]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
mtd: mtdpart: fix partitions searching
authorMikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Mon, 19 Jan 2026 22:33:05 +0000 (01:33 +0300)
committerTom Rini <trini@konsulko.com>
Wed, 4 Feb 2026 16:30:55 +0000 (10:30 -0600)
mtdpart internally enumerate partitions starting from zero, but partition
driver API enumerate partitions starting from 1, so wrong partition will
be queried. This is wrong.

Unnecessary debug message also was removed.

Fixes: c29a6daec184 ("disk: support MTD partitions")
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
drivers/mtd/mtdpart.c

index 842d3e7274e2386d1193ddf19f412b7d61793a79..f3b7f1ee13c780589a5b32be3d8b3f1d26294e2a 100644 (file)
@@ -1061,13 +1061,13 @@ EXPORT_SYMBOL_GPL(mtd_get_device_size);
 static struct mtd_info *mtd_get_partition_by_index(struct mtd_info *mtd, int index)
 {
        struct mtd_info *part;
-       int i = 0;
+       int i = 1;
 
+       /* partition indexes starts from 1 */
        list_for_each_entry(part, &mtd->partitions, node)
                if (i++ == index)
                        return part;
 
-       debug("Partition with idx=%d not found on MTD device %s\n", index, mtd->name);
        return NULL;
 }
 
@@ -1084,7 +1084,8 @@ static int __maybe_unused part_get_info_mtd(struct blk_desc *dev_desc, int part_
 
        part = mtd_get_partition_by_index(master, part_idx);
        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, master->name);
                return -EINVAL;
        }