mtd: mtdparts: calculate mtd partition offset before calculating size
authorWeijie Gao <weijie.gao@mediatek.com>
Fri, 25 Apr 2025 03:43:03 +0000 (11:43 +0800)
committerTom Rini <trini@konsulko.com>
Mon, 28 Apr 2025 19:26:15 +0000 (13:26 -0600)
The mtd partition offset must be calculated first as it will be
referenced when calculating the mtd partition size.

Change-Id: Iccfd101b0a9597ac240c25670da638a82af28980
Fixes: 1ca97ee9039 (mtd: mtdpart: Support MTD_SIZE_REMAINING with unallocated memory area)
Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Reported-by: Francesco Dolcini <francesco@dolcini.it>
drivers/mtd/mtdpart.c

index 3f8edeb..99bea6f 100644 (file)
@@ -236,6 +236,10 @@ int mtd_parse_partitions(struct mtd_info *parent, const char **_mtdparts,
                if (ret)
                        return ret;
 
+               if (parts[idx].offset == MTD_OFFSET_NOT_SPECIFIED)
+                       parts[idx].offset = cur_off;
+               cur_off += parts[idx].size;
+
                if (parts[idx].size == MTD_SIZE_REMAINING)
                        parts[idx].size = parent->size - parts[idx].offset;
 
@@ -246,10 +250,6 @@ int mtd_parse_partitions(struct mtd_info *parent, const char **_mtdparts,
                        return -EINVAL;
                }
 
-               if (parts[idx].offset == MTD_OFFSET_NOT_SPECIFIED)
-                       parts[idx].offset = cur_off;
-               cur_off += parts[idx].size;
-
                parts[idx].ecclayout = parent->ecclayout;
        }