Skip to content

Commit e784f2e

Browse files
lgs2513axboe
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: [email protected] Signed-off-by: Guangshuo Li <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent a7c9fa7 commit e784f2e

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

drivers/block/floppy.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4722,15 +4722,19 @@ static int __init do_floppy_init(void)
47224722
floppy_device[drive].dev.groups = floppy_dev_groups;
47234723

47244724
err = platform_device_register(&floppy_device[drive]);
4725-
if (err)
4725+
if (err) {
4726+
platform_device_put(&floppy_device[drive]);
47264727
goto out_remove_drives;
4727-
4728+
}
47284729
registered[drive] = true;
47294730

47304731
err = device_add_disk(&floppy_device[drive].dev,
47314732
disks[drive][0], NULL);
4732-
if (err)
4733+
if (err) {
4734+
platform_device_unregister(&floppy_device[drive]);
4735+
registered[drive] = false;
47334736
goto out_remove_drives;
4737+
}
47344738
}
47354739

47364740
return 0;

0 commit comments

Comments
 (0)