linux/drivers/mtd
Miquel Raynal a6fd2145c7 mtd: spi-nor: swp: Improve locking user experience
[ Upstream commit e1d456b26b ]

In the case of the first block being locked (or the few first blocks),
if the user want to fully unlock the device it has two possibilities:
- either it asks to unlock the entire device, and this works;
- or it asks to unlock just the block(s) that are currently locked,
  which fails.

It fails because the conditions "can_be_top" and "can_be_bottom" are
true. Indeed, in this case, we unlock everything, so the TB bit does not
matter. However in the current implementation, use_top would be true (as
this is the favourite option) and lock_len, which in practice should be
reduced down to 0, is set to "nor->params->size - (ofs + len)" which is
a positive number. This is wrong.

An easy way is to simply add an extra condition. In the unlock() path,
if we can achieve the same result from both sides, it means we unlock
everything and lock_len must simply be 0. A comment is added to clarify
that logic.

Fixes: 3dd8012a8e ("mtd: spi-nor: add TB (Top/Bottom) protect support")
Cc: stable@kernel.org
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Michael Walle <mwalle@kernel.org>
Signed-off-by: Pratyush Yadav <pratyush@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-08-23 14:17:21 +02:00
..
chips mtd: cfi_cmdset_0001: Byte swap OTP info 2023-11-28 16:56:31 +00:00
devices mtd: mchp23k256: use SPI match data for chip caps 2026-07-24 15:51:55 +02:00
hyperbus mtd: hyperbus: hbmc-am654: fix an OF node reference leak 2025-03-13 12:50:09 +01:00
lpddr mtd: lpddr_cmds: fix signed shifts in lpddr_cmds 2026-01-19 13:09:36 +01:00
maps mtd: maps: vmu-flash: fix fault in unaligned fixup 2026-08-23 14:17:21 +02:00
nand mtd: nand: mtk-ecc: stop on ECC idle timeouts 2026-08-19 17:13:52 +02:00
parsers mtd: parsers: ofpart: call of_node_get() for dedicated subpartitions 2026-06-01 17:35:35 +02:00
spi-nor mtd: spi-nor: swp: Improve locking user experience 2026-08-23 14:17:21 +02:00
tests mtd: make mtd_test.c a separate module 2024-08-19 05:45:05 +02:00
ubi ubi: fastmap: Fix duplicate slab cache names while attaching 2024-12-14 19:51:20 +01:00
ftl.c mtd: fix possible integer overflow in erase_xfer() 2025-08-28 16:24:09 +02:00
inftlcore.c mtd: inftlcore: Add error check for inftl_read_oob() 2025-05-02 07:44:04 +02:00
inftlmount.c mtd: inftl: remove unnecessary oom message 2021-06-11 20:44:21 +02:00
Kconfig mtdblock: Add comment about UBI block devices 2021-08-06 22:05:13 +02:00
Makefile mtd: Support kmsg dumper based on pstore/blk 2020-05-31 19:49:01 -07:00
mtd_blkdevs.c mtd: Fix gluebi NULL pointer dereference caused by ftl notifier 2024-01-25 14:52:34 -08:00
mtdblock.c mtdblock: tolerate corrected bit-flips 2023-04-20 12:13:52 +02:00
mtdblock_ro.c mtdblock: Warn if added for a NAND device 2021-08-17 18:41:59 +02:00
mtdchar.c mtd: add OTP (one-time-programmable) erase ioctl 2021-03-28 19:24:54 +02:00
mtdconcat.c mtd: mtdconcat: Check _read, _write callbacks existence before assignment 2021-08-17 18:43:33 +02:00
mtdcore.c mtd: core: Report error if first mtd_otp_size() call fails in mtd_otp_nvmem_add() 2024-06-16 13:39:27 +02:00
mtdcore.h mtd: Provide fs_context-aware mount_mtd() replacement 2019-09-05 14:34:23 -04:00
mtdoops.c mtd: mtdoops: remove unnecessary oom message 2021-06-11 20:43:46 +02:00
mtdpart.c mtd: Fixed breaking list in __mtd_del_partition. 2022-01-27 11:02:48 +01:00
mtdpstore.c mtd: Replace kcalloc() with devm_kcalloc() 2025-05-02 07:44:02 +02:00
mtdsuper.c block: remove i_bdev 2020-12-01 14:53:39 -07:00
mtdswap.c mtd: mtdswap: remove debugfs stats file on teardown 2026-08-19 17:13:52 +02:00
nftlcore.c mtd: nftlcore: remove set but rewrite variables 2021-05-10 12:11:46 +02:00
nftlmount.c mtd: nftl: remove unnecessary oom message 2021-06-11 20:43:26 +02:00
rfd_ftl.c mtd/rfd_ftl: don't cast away the type when calling add_mtd_blktrans_dev 2021-08-23 10:01:06 +02:00
sm_ftl.c mtd: sm_ftl: Fix deadlock caused by cancel_work_sync in sm_release 2022-08-17 14:23:40 +02:00
sm_ftl.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
ssfdc.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00