diff mbox

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

Message ID CAJbz7-1FTiDiA3Mjs4hxaZXBCc-qcTYdmWZ6DqnVVYrqohEyrA@mail.gmail.com
State Changes Requested
Headers show

Commit Message

Honza Petrouš May 30, 2017, 9:51 a.m. UTC
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@gmail.com>
---
 drivers/mtd/chips/cfi_cmdset_0002.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

             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 */
diff mbox

Patch

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) {