mtd: nand: fix nand_lock/unlock() function

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Wed Oct 15 23:59:02 PDT 2014


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=57d3a9a89a0645f3597561e214f8d6852a2c56b4
Commit:     57d3a9a89a0645f3597561e214f8d6852a2c56b4
Parent:     6f3c0f163103fb225c77b73ca17fc4ecea308103
Author:     White Ding <bpqw at micron.com>
AuthorDate: Thu Jul 24 00:10:45 2014 +0800
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Tue Aug 19 11:53:07 2014 -0700

    mtd: nand: fix nand_lock/unlock() function
    
    Do nand reset before write protect check.
    
    If we want to check the WP# low or high through STATUS READ and check bit 7,
    we must reset the device, other operation (eg.erase/program a locked block) can
    also clear the bit 7 of status register.
    
    As we know the status register can be refreshed, if we do some operation to trigger it,
    for example if we do erase/program operation to one block that is locked, then READ STATUS,
    the bit 7 of READ STATUS will be 0 indicate the device in write protect, then if we do
    erase/program operation to another block that is unlocked, the bit 7 of READ STATUS will
    be 1 indicate the device is not write protect.
    Suppose we checked the bit 7 of READ STATUS is 0 then judge the WP# is low (write protect),
    but in this case the WP# maybe high if we do erase/program operation to a locked block,
    so we must reset the device if we want to check the WP# low or high through STATUS READ and
    check bit 7.
    
    Signed-off-by: White Ding <bpqw at micron.com>
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 drivers/mtd/nand/nand_base.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index d8cdf06..1a27c2d 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -982,6 +982,15 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 
 	chip->select_chip(mtd, chipnr);
 
+	/*
+	 * Reset the chip.
+	 * If we want to check the WP through READ STATUS and check the bit 7
+	 * we must reset the chip
+	 * some operation can also clear the bit 7 of status register
+	 * eg. erase/program a locked block
+	 */
+	chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
+
 	/* Check, if it is write protected */
 	if (nand_check_wp(mtd)) {
 		pr_debug("%s: device is write protected!\n",
@@ -1032,6 +1041,15 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 
 	chip->select_chip(mtd, chipnr);
 
+	/*
+	 * Reset the chip.
+	 * If we want to check the WP through READ STATUS and check the bit 7
+	 * we must reset the chip
+	 * some operation can also clear the bit 7 of status register
+	 * eg. erase/program a locked block
+	 */
+	chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
+
 	/* Check, if it is write protected */
 	if (nand_check_wp(mtd)) {
 		pr_debug("%s: device is write protected!\n",



More information about the linux-mtd-cvs mailing list