[PATCH] mtd: mtdparts: calculate mtd partition offset before calculating size

Weijie Gao weijie.gao at mediatek.com
Fri Apr 25 05:43:03 CEST 2025


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 at mediatek.com>
---
 drivers/mtd/mtdpart.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 3f8edeb5093..99bea6f1c85 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -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;
 	}
 
-- 
2.34.1



More information about the U-Boot mailing list