[PATCH v2 2/3] mtd:nor:ppb_unlock: don't use empty part of array

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


There is no need to increment 'sectors' during walk over all sectors
in the case of the sectors inside the unlocking area. It can only lead to
out of sectors error for big chips.

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 62a1004..29a0b7f 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -2671,6 +2671,14 @@ static int __maybe_unused cfi_ppb_unlock(struct
mtd_info *mtd, loff_t ofs,
             sect[sectors].locked = do_ppb_xxlock(
                 map, &cfi->chips[chipnum], adr, 0,
                 DO_XXLOCK_ONEBLOCK_GETLOCK);
+
+            sectors++;
+            if (sectors >= MAX_SECTORS) {
+                printk(KERN_ERR "Only %d sectors for PPB locking supported!\n",
+                       MAX_SECTORS);
+                kfree(sect);
+                return -EINVAL;
+            }
         }

         adr += size;
@@ -2680,14 +2688,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++;

-        sectors++;
-        if (sectors >= MAX_SECTORS) {
-            printk(KERN_ERR "Only %d sectors for PPB locking supported!\n",
-                   MAX_SECTORS);
-            kfree(sect);
-            return -EINVAL;
-        }
-
         if (adr >> cfi->chipshift) {
             adr = 0;
             chipnum++;
-- 
2.9.3



More information about the linux-mtd mailing list