Re: [PATCH] floppy: fix reference leak on platform_device_register() failure

From: Denis Efremov (Oracle)

Date: Wed Apr 15 2026 - 10:20:16 EST




On 15/04/2026 17:54, Guangshuo Li wrote:
> Hi Denis,
>
> Thank you for the review.
>
> On Wed, 15 Apr 2026 at 21:00, Denis Efremov (Oracle) <efremov@xxxxxxxxx> wrote:
>>
>> 1. Let's use platform_device_put()
>>
>>> goto out_remove_drives;
>>> + }
>>>
>>> registered[drive] = true;
>>>
>
> My understanding is:
>
> For the platform_device_register() failure case, we should use
> platform_device_put() instead of put_device(), so the failure path
> would look like:
>
> err = platform_device_register(&floppy_device[drive]);
> if (err) {
> platform_device_put(&floppy_device[drive]);
> goto out_remove_drives;
> }
> registered[drive] = true;

Yes, correct.

>
>> err = device_add_disk(&floppy_device[drive].dev,
>> disks[drive][0], NULL);
>> if (err)
>> goto out_remove_drives;
>>
>> 2. We also need to fix this case.
>>
>> platform_device_unregister()
>> registered[drive] = false;
>> goto ...
>>
>> Thanks,
>> Denis
> We also need to handle the device_add_disk() failure case for the
> current drive, since out_remove_drives only cleans up previously
> registered drives. So this path should explicitly unregister the
> current platform device before jumping to the common cleanup path, for
> example:
>
> err = device_add_disk(&floppy_device[drive].dev, disks[drive][0], NULL);
> if (err) {
> platform_device_unregister(&floppy_device[drive]);
> registered[drive] = false;
> goto out_remove_drives;
> }
>
>
> Is my understanding correct? If so, I will prepare and send a v2
> following this pattern.

Yes, correct. Please, send v2.

>
> Thanks,
> Guangshuo