Skip to contentSkip to conversation

mtd: ubi: Release device reference on busy detach

PATCH Applied Yuho Choi 3 participants 3 messages Aug 7 – Aug 11

Subsystems (2)
lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 mtd: ubi: Release device reference on busy detach

ubi_detach_mtd_dev() obtains a device reference through ubi_get_device() before checking whether the UBI device is busy. The busy return path drops ubi->ref_count but leaves the device reference held, so the device object cannot be released after a later detach.

Drop the device reference before returning -EBUSY.

Fixes 7e84c961b2eb ("mtd: ubi: introduce pre-removal notification for UBI volumes")
---
 drivers/mtd/ubi/build.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/ubi/build.c +1 -0
index 674ad87809df..ee6ce4471b25 100644
@@ -1105,6 +1105,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
 	ubi->ref_count -= 1;
 	if (ubi->ref_count) {
 		if (!anyway) {
+			put_device(&ubi->dev);
 			spin_unlock(&ubi_devices_lock);
 			return -EBUSY;
 		}
Signature · 1 line
2.43.0
reviewer
#1 lore raw
Quoted 5 lines · Yuho Choi

ubi_detach_mtd_dev() obtains a device reference through ubi_get_device() before checking whether the UBI device is busy. The busy return path drops ubi->ref_count but leaves the device reference held, so the device object cannot be released after a later detach.

Quoted 7 lines

Drop the device reference before returning -EBUSY.

Fixes 7e84c961b2eb ("mtd: ubi: introduce pre-removal notification for UBI volumes")
---
  drivers/mtd/ubi/build.c | 1 +
  1 file changed, 1 insertion(+)

I think you have sent this patch before?
https://lore.kernel.org/linux-mtd/[email protected]/

Quoted 14 lines
drivers/mtd/ubi/build.c +1 -0
index 674ad87809df..ee6ce4471b25 100644
@@ -1105,6 +1105,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
  	ubi->ref_count -= 1;
  	if (ubi->ref_count) {
  		if (!anyway) {
+			put_device(&ubi->dev);
  			spin_unlock(&ubi_devices_lock);
  			return -EBUSY;
  		}
#2 lore raw
In reply to Yuho Choi
Quoted 8 lines · Yuho Choi

ubi_detach_mtd_dev() obtains a device reference through ubi_get_device() before checking whether the UBI device is busy. The busy return path drops ubi->ref_count but leaves the device reference held, so the device object cannot be released after a later detach.

Drop the device reference before returning -EBUSY.

[...]

Applied, thanks!

[1/1] mtd: ubi: Release device reference on busy detach

      commit: 31dd710cd84d5dd63c49f640d3a9f36c9699ca95