[PATCH] ubi: fix bug creating partitions for non-existent volumes

Oskar Nilsson onilsson at rums.se
Tue Mar 25 18:47:06 CET 2025


The part_get_info_ubi() function was incorrectly returning 0 (success)
when a UBI volume was not found for a given partition index. This caused
the part_create_block_devices() function in blk-uclass.c to continue
creating devices for non-existent partitions up to MAX_SEARCH_PARTITIONS

Fix the issue by returning -1 when a volume is not found, signaling to
the part_create_block_devices() function that no more valid volumes
exist.

Before patch, 128 blk_partition are created:
Class   Index  Probed  Driver        Name
-------------------------------------------------
root        0  [ + ]  root_driver    root_driver
thermal     0  [   ]  imx_thermal    |-- imx_thermal
simple_bus  0  [ + ]  simple_bus     |-- soc
mtd         0  [ + ]  mxs-nand-dt    |   |-- nand-controller at 1806000
blk         0  [   ]  ubi_blk        |   |   `-- nand-controller at 1806000.blk
partition   0  [   ]  blk_partition  |   |       |-- nand-controller at 1806000.blk:1
...
partition 127  [   ]  blk_partition  |   |       `-- nand-controller at 1806000.blk:128


After patch, the expected blk_partition are created:
Class   Index  Probed  Driver        Name
-------------------------------------------------
root        0  [ + ]  root_driver    root_driver
thermal     0  [   ]  imx_thermal    |-- imx_thermal
simple_bus  0  [ + ]  simple_bus     |-- soc
mtd         0  [ + ]  mxs-nand-dt    |   |-- nand-controller at 1806000
blk         0  [   ]  ubi_blk        |   |   `-- nand-controller at 1806000.blk
partition   0  [   ]  blk_partition  |   |       |-- nand-controller at 1806000.blk:1
partition   1  [   ]  blk_partition  |   |       |-- nand-controller at 1806000.blk:2
partition   2  [   ]  blk_partition  |   |       |-- nand-controller at 1806000.blk:3
partition   3  [   ]  blk_partition  |   |       `-- nand-controller at 1806000.blk:4
simple_bus  1  [ + ]  simple_bus     |   |-- bus at 2000000

Signed-off-by: Oskar Nilsson <onilsson at rums.se>
Cc: Kyungmin Park <kmpark at infradead.org>
Cc: Heiko Schocher <hs at denx.de>
Cc: Alexey Romanov <avromanov at salutedevices.com>

---
 drivers/mtd/ubi/part.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/part.c b/drivers/mtd/ubi/part.c
index 13d1f165c30..a049bb295ce 100644
--- a/drivers/mtd/ubi/part.c
+++ b/drivers/mtd/ubi/part.c
@@ -47,7 +47,7 @@ static int __maybe_unused part_get_info_ubi(
 	 */
 	vol = ubi_get_volume_by_index(part_idx - 1);
 	if (!vol)
-		return 0;
+		return -1;
 
 	snprintf(info->name, PART_NAME_LEN, vol->name);
 
-- 
2.43.0



More information about the U-Boot mailing list