mtd: ubi: Release device reference on busy detach
Subsystems (2)
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.
--- drivers/mtd/ubi/build.c | 1 + 1 file changed, 1 insertion(+)
drivers/mtd/ubi/build.c +1 -0
@@ -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
Zhihao Cheng
reviewerQuoted 5 lines · Yuho Choi
ubi_detach_mtd_dev()obtains a device reference throughubi_get_device()before checking whether the UBI device is busy. The busy return path dropsubi->ref_countbut 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")Signed-off-by Yuho Choi <[email protected]>--- 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@@ -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 ; }
Richard Weinberger
AppliedQuoted 8 lines · Yuho Choi
ubi_detach_mtd_dev()obtains a device reference throughubi_get_device()before checking whether the UBI device is busy. The busy return path dropsubi->ref_countbut 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