[PATCH v2 1/3] mtd:nor:ppb_unlock: fix locking of the utmost required sector

Honza Petrouš jpetrous at gmail.com
Tue May 30 02:51:14 PDT 2017


When used Persistent Protection Bits (PPB) unlocking of cfi_cmdset_0002.c
the last sector remains unlocked regardless of its previous state
because of late increment of 'sectors' variable. Flip the code fixes it.

Signed-off-by: Honza Petrous <jpetrous at gmail.com>
---
 drivers/mtd/chips/cfi_cmdset_0002.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c
b/drivers/mtd/chips/cfi_cmdset_0002.c
index 56aa6b7..62a1004 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -2680,14 +2680,6 @@ static int __maybe_unused cfi_ppb_unlock(struct
mtd_info *mtd, loff_t ofs,
         if (offset == regions[i].offset + size * regions[i].numblocks)
             i++;

-        if (adr >> cfi->chipshift) {
-            adr = 0;
-            chipnum++;
-
-            if (chipnum >= cfi->numchips)
-                break;
-        }
-
         sectors++;
         if (sectors >= MAX_SECTORS) {
             printk(KERN_ERR "Only %d sectors for PPB locking supported!\n",
@@ -2695,6 +2687,14 @@ static int __maybe_unused cfi_ppb_unlock(struct
mtd_info *mtd, loff_t ofs,
             kfree(sect);
             return -EINVAL;
         }
+
+        if (adr >> cfi->chipshift) {
+            adr = 0;
+            chipnum++;
+
+            if (chipnum >= cfi->numchips)
+                break;
+        }
     }

     /* Now unlock the whole chip */
-- 
2.9.3



More information about the linux-mtd mailing list