Skip to contentSkip to conversation

mtd: ubi: Fix rollback for explicit UBI device numbers

PATCH In review Yuho Choi 2 participants 2 messages Jun 8

Subsystems (2)
lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 mtd: ubi: Fix rollback for explicit UBI device numbers

ubi_init_attach() rolls back module initialization failures by scanning ubi_devices[0..i-1], where i is the mtd= parameter index. That assumes the parameter index matches the UBI device number.

That assumption is not true when mtd= specifies an explicit ubi_num. A successfully attached device can be stored at a higher ubi_devices[] slot, and a later failure can miss it during rollback.

Scan the full ubi_devices[] array and detach by the actual array index, matching the way UBI devices are stored.

Fixes 83ff59a06663 ("UBI: support ubi_num on mtd.ubi command line")
---
 drivers/mtd/ubi/build.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/ubi/build.c +2 -2
index 674ad87809df..90c5c83d90e3 100644
@@ -1317,10 +1317,10 @@ static int __init ubi_init_attach(void)
 	return 0;
 
 out_detach:
-	for (k = 0; k < i; k++)
+	for (k = 0; k < UBI_MAX_DEVICES; k++)
 		if (ubi_devices[k]) {
 			mutex_lock(&ubi_devices_mutex);
-			ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1);
+			ubi_detach_mtd_dev(k, 1);
 			mutex_unlock(&ubi_devices_mutex);
 		}
 	return err;
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Yuho Choi

ubi_init_attach() rolls back module initialization failures by scanning ubi_devices[0..i-1], where i is the mtd= parameter index. That assumes the parameter index matches the UBI device number.

That assumption is not true when mtd= specifies an explicit ubi_num. A successfully attached device can be stored at a higher ubi_devices[] slot, and a later failure can miss it during rollback.

Quoted 9 lines

Scan the full ubi_devices[] array and detach by the actual array index, matching the way UBI devices are stored.

Fixes 83ff59a06663 ("UBI: support ubi_num on mtd.ubi command line")
---
  drivers/mtd/ubi/build.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 18 lines
drivers/mtd/ubi/build.c +2 -2
index 674ad87809df..90c5c83d90e3 100644
@@ -1317,10 +1317,10 @@ static int __init ubi_init_attach(void)
  	return 0;
 
  out_detach:
-	for (k = 0; k < i; k++)
+	for (k = 0; k < UBI_MAX_DEVICES; k++)
  		if (ubi_devices[k]) {
  			mutex_lock(&ubi_devices_mutex);
-			ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1);
+			ubi_detach_mtd_dev(k, 1);
  			mutex_unlock(&ubi_devices_mutex);
  		}
  	return err;