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

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Mon Aug 1 18:59:03 PDT 2016


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=06586204714b7befec99e554c71687b0b40f351c
Commit:     06586204714b7befec99e554c71687b0b40f351c
Parent:     21a190b970878be8298c3f696aede1de36986817
Author:     Brian Norris <computersforpeace at gmail.com>
AuthorDate: Fri Jun 24 10:38:14 2016 -0700
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Sat Jul 9 19:29:38 2016 -0700

    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")
    Reported-by: Giorgio <giorgio.nicole at arcor.de>
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
    Cc: Ezequiel Garcia <ezequiel at vanguardiasur.com.ar>
---
 drivers/mtd/spi-nor/spi-nor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index a63922e..14cf6ac 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -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)



More information about the linux-mtd-cvs mailing list