Commit 0b9f5dee authored by Joakim Tjernlund's avatar Joakim Tjernlund Committed by Stefan Bader

mtd: cfi_cmdset_0002: fix SEGV unlocking multiple chips

BugLink: https://bugs.launchpad.net/bugs/1784382

commit 5fdfc3db upstream.

cfi_ppb_unlock() tries to relock all sectors that were locked before
unlocking the whole chip.
This locking used the chip start address + the FULL offset from the
first flash chip, thereby forming an illegal address. Fix that by using
the chip offset(adr).

Fixes: 1648eaaa ("mtd: cfi_cmdset_0002: Support Persistent Protection Bits (PPB) locking")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarJoakim Tjernlund <joakim.tjernlund@infinera.com>
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent f6e7d43d
...@@ -2533,7 +2533,7 @@ static int cfi_atmel_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) ...@@ -2533,7 +2533,7 @@ static int cfi_atmel_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
struct ppb_lock { struct ppb_lock {
struct flchip *chip; struct flchip *chip;
loff_t offset; unsigned long adr;
int locked; int locked;
}; };
...@@ -2669,7 +2669,7 @@ static int __maybe_unused cfi_ppb_unlock(struct mtd_info *mtd, loff_t ofs, ...@@ -2669,7 +2669,7 @@ static int __maybe_unused cfi_ppb_unlock(struct mtd_info *mtd, loff_t ofs,
*/ */
if ((adr < ofs) || (adr >= (ofs + len))) { if ((adr < ofs) || (adr >= (ofs + len))) {
sect[sectors].chip = &cfi->chips[chipnum]; sect[sectors].chip = &cfi->chips[chipnum];
sect[sectors].offset = offset; sect[sectors].adr = adr;
sect[sectors].locked = do_ppb_xxlock( sect[sectors].locked = do_ppb_xxlock(
map, &cfi->chips[chipnum], adr, 0, map, &cfi->chips[chipnum], adr, 0,
DO_XXLOCK_ONEBLOCK_GETLOCK); DO_XXLOCK_ONEBLOCK_GETLOCK);
...@@ -2713,7 +2713,7 @@ static int __maybe_unused cfi_ppb_unlock(struct mtd_info *mtd, loff_t ofs, ...@@ -2713,7 +2713,7 @@ static int __maybe_unused cfi_ppb_unlock(struct mtd_info *mtd, loff_t ofs,
*/ */
for (i = 0; i < sectors; i++) { for (i = 0; i < sectors; i++) {
if (sect[i].locked) if (sect[i].locked)
do_ppb_xxlock(map, sect[i].chip, sect[i].offset, 0, do_ppb_xxlock(map, sect[i].chip, sect[i].adr, 0,
DO_XXLOCK_ONEBLOCK_LOCK); DO_XXLOCK_ONEBLOCK_LOCK);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment