Skip to content

Commit adccf02

Browse files
lgs2513kawasaki
authored andcommitted
floppy: fix reference leak on platform_device_register() failure
When platform_device_register() fails in do_floppy_init(), the embedded struct device in floppy_device[drive] has already been initialized by device_initialize(), but the failure path jumps to out_remove_drives without dropping the device reference for the current drive. Previously registered floppy devices are cleaned up in out_remove_drives, but the device for the drive that fails registration is not, leading to a reference leak. The issue was identified by a static analysis tool I developed and confirmed by manual review. Fix this by calling put_device() for the current floppy device before jumping to the common cleanup path. Fixes: 94fd0db ("[PATCH] Floppy: Add cmos attribute to floppy driver") Cc: stable@vger.kernel.org Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
1 parent 6b4d829 commit adccf02

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

drivers/block/floppy.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4724,8 +4724,10 @@ static int __init do_floppy_init(void)
47244724
floppy_device[drive].dev.groups = floppy_dev_groups;
47254725

47264726
err = platform_device_register(&floppy_device[drive]);
4727-
if (err)
4727+
if (err) {
4728+
put_device(&floppy_device[drive].dev);
47284729
goto out_remove_drives;
4730+
}
47294731

47304732
registered[drive] = true;
47314733

0 commit comments

Comments
 (0)