Skip to contentSkip to conversation

mtd: spi-nor: fix wrong "fully unlocked" test

PATCH Applied Brian Norris 1 participant 2 messages Jun 24, 2016 – Jul 10, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: spi-nor: fix wrong "fully unlocked" test

In stm_unlock(), the test to determine whether we've fully unlocked the flash checks for the lock length to be equal to the flash size. That is a typo/think-o -- the condition actually means the flash is completely *locked.* We should be using the inverse condition -- that the lock length is 0 (i.e., no protection).

The result of this bug is that we never actually turn off the Status Register Write Disable bit, even if the flash is completely unlocked. Now we can.

Fixes 47b8edbf0d43 ("mtd: spi-nor: disallow further writes to SR if WP# is low")
Cc Ezequiel Garcia <[email protected]>
---
 drivers/mtd/spi-nor/spi-nor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi-nor/spi-nor.c +1 -1
index a63922ed6385..14cf6ac8c0a5 100644
@@ -661,7 +661,7 @@ static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 	status_new = (status_old & ~mask & ~SR_TB) | val;
 
 	/* Don't protect status register if we're fully unlocked */
-	if (lock_len == mtd->size)
+	if (lock_len == 0)
 		status_new &= ~SR_SRWD;
 
 	if (!use_top)
Signature · 1 line
2.8.0.rc3.226.g39d4020
author Applied
#1 lore raw
Quoted 6 lines · Brian Norris

In stm_unlock(), the test to determine whether we've fully unlocked the flash checks for the lock length to be equal to the flash size. That is a typo/think-o -- the condition actually means the flash is completely *locked.* We should be using the inverse condition -- that the lock length is 0 (i.e., no protection).

Quoted 8 lines

The result of this bug is that we never actually turn off the Status Register Write Disable bit, even if the flash is completely unlocked. Now we can.

Fixes 47b8edbf0d43 ("mtd: spi-nor: disallow further writes to SR if WP# is low")
Cc Ezequiel Garcia <[email protected]>

Applied to l2-mtd.git