Skip to contentSkip to conversation

ubi: fix bug creating partitions for non-existent volumes

PATCH In review Oskar Nilsson 2 participants 3 messages Mar 26, 2025 – Apr 8, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ubi: fix bug creating partitions for non-existent volumes

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@1806000 blk         0  [   ]  ubi_blk        |   |   `-- [email protected] partition   0  [   ]  blk_partition  |   |       |-- [email protected]:1
...
partition 127  [   ]  blk_partition  |   |       `-- [email protected]: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@1806000 blk         0  [   ]  ubi_blk        |   |   `-- [email protected]

partition   0  [   ]  blk_partition  |   |       |-- [email protected]:1
partition   1  [   ]  blk_partition  |   |       |-- [email protected]:2
partition   2  [   ]  blk_partition  |   |       |-- [email protected]:3
partition   3  [   ]  blk_partition  |   |       `-- [email protected]:4
simple_bus  1  [ + ]  simple_bus     |   |-- bus@2000000
Cc Kyungmin Park <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Alexey Romanov <[email protected]>

Changed in v2:
- Change return from -1 to -ENOENT

---
 drivers/mtd/ubi/part.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/ubi/part.c +1 -1
index 13d1f165c30..a049bb295ce 100644
@@ -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 -ENOENT;
 
 	snprintf(info->name, PART_NAME_LEN, vol->name);
 
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw

Hello Oskar,

Quoted 41 lines · Oskar Nilsson

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@1806000 blk         0  [   ]  ubi_blk        |   |   `-- [email protected] partition   0  [   ]  blk_partition  |   |       |-- [email protected]:1
...
partition 127  [   ]  blk_partition  |   |       `-- [email protected]: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@1806000 blk         0  [   ]  ubi_blk        |   |   `-- [email protected]

partition   0  [   ]  blk_partition  |   |       |-- [email protected]:1
partition   1  [   ]  blk_partition  |   |       |-- [email protected]:2
partition   2  [   ]  blk_partition  |   |       |-- [email protected]:3
partition   3  [   ]  blk_partition  |   |       `-- [email protected]:4
simple_bus  1  [ + ]  simple_bus     |   |-- bus@2000000
Cc Kyungmin Park <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Alexey Romanov <[email protected]>
Quoted 6 lines

Changed in v2:
- Change return from -1 to -ENOENT

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

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]
#2 lore raw
In reply to Oskar Nilsson

Hello Oskar,

Quoted 41 lines · Oskar Nilsson

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@1806000 blk         0  [   ]  ubi_blk        |   |   `-- [email protected] partition   0  [   ]  blk_partition  |   |       |-- [email protected]:1
...
partition 127  [   ]  blk_partition  |   |       `-- [email protected]: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@1806000 blk         0  [   ]  ubi_blk        |   |   `-- [email protected]

partition   0  [   ]  blk_partition  |   |       |-- [email protected]:1
partition   1  [   ]  blk_partition  |   |       |-- [email protected]:2
partition   2  [   ]  blk_partition  |   |       |-- [email protected]:3
partition   3  [   ]  blk_partition  |   |       `-- [email protected]:4
simple_bus  1  [ + ]  simple_bus     |   |-- bus@2000000
Cc Kyungmin Park <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Alexey Romanov <[email protected]>
Quoted 6 lines

Changed in v2:
- Change return from -1 to -ENOENT

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

Applied to u-boot-ubi master

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]