diff mbox

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

Message ID CAJbz7-3BzFyJ6+EZo-Rs9mbRGgBHHFYvGB=_uzO-76wmJ4aBiw@mail.gmail.com
State Changes Requested
Headers show

Commit Message

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

         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++;
diff mbox

Patch

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;
+            }
         }