[PATCH v2 3/3] mtd: mtdpart: fix partitions searching

Mikhail Kshevetskiy mikhail.kshevetskiy at iopsys.eu
Mon Jan 19 01:36:06 CET 2026


mtdpart internally enumerate partitions starting from zero, but partition
driver API enumerate partitions starting from 1. Just now mtdpart does
not take this difference into account. This is wrong.

Unnecessary debug message also was removed.

Fixes: c29a6daec184 ("disk: support MTD partitions")
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy at iopsys.eu>
---
 drivers/mtd/mtdpart.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 842d3e7274e..0bd4b3db022 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -1067,7 +1067,6 @@ static struct mtd_info *mtd_get_partition_by_index(struct mtd_info *mtd, int ind
 		if (i++ == index)
 			return part;
 
-	debug("Partition with idx=%d not found on MTD device %s\n", index, mtd->name);
 	return NULL;
 }
 
@@ -1082,9 +1081,11 @@ static int __maybe_unused part_get_info_mtd(struct blk_desc *dev_desc, int part_
 		return -EINVAL;
 	}
 
-	part = mtd_get_partition_by_index(master, part_idx);
+	/* internal indexing starts from zero, but part_idx starts from 1 */
+	part = mtd_get_partition_by_index(master, part_idx - 1);
 	if (!part) {
-		debug("Failed to find partition with idx=%d\n", part_idx);
+		debug("Failed to find partition with idx=%d on MTD device %s\n",
+		      part_idx - 1, master->name);
 		return -EINVAL;
 	}
 
-- 
2.51.0



More information about the U-Boot mailing list