mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] floppy: unregister platform device on add_disk failure
@ 2026-07-08 10:57 Guangshuo Li
  2026-07-24 13:29 ` Denis Efremov (Oracle)
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-07-08 10:57 UTC (permalink / raw)
  To: Denis Efremov, Jens Axboe, linux-block, linux-kernel; +Cc: Guangshuo Li

The change referenced by the Fixes tag reverted a previous fix because
that fix added incorrect cleanup for the platform_device_register()
failure path.

However, reverting the whole change also removed the cleanup for a later
failure path. If platform_device_register() succeeds but device_add_disk()
fails, the current floppy platform device has already been registered and
registered[drive] has been set.

The common out_remove_drives path uses while (drive--), so it starts from
the previous drive and does not unregister the current one. As a result,
the platform device registered for the failing drive is leaked.

Unregister the current platform device directly on the device_add_disk()
failure path, where platform_device_register() is known to have
succeeded. Leave the platform_device_register() failure path unchanged.

Fixes: 895a9b37917d ("Revert "floppy: fix reference leak on platform_device_register() failure"")
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/block/floppy.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index f04397b8e381..7a34af534460 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -4729,8 +4729,11 @@ static int __init do_floppy_init(void)
 
 		err = device_add_disk(&floppy_device[drive].dev,
 				      disks[drive][0], NULL);
-		if (err)
+		if (err) {
+			platform_device_unregister(&floppy_device[drive]);
+			registered[drive] = false;
 			goto out_remove_drives;
+		}
 	}
 
 	return 0;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] floppy: unregister platform device on add_disk failure
  2026-07-08 10:57 [PATCH] floppy: unregister platform device on add_disk failure Guangshuo Li
@ 2026-07-24 13:29 ` Denis Efremov (Oracle)
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Efremov (Oracle) @ 2026-07-24 13:29 UTC (permalink / raw)
  To: Guangshuo Li, Jens Axboe, linux-block, linux-kernel

Hello,

Thank you for the patch.

On 08/07/2026 14:57, Guangshuo Li wrote:
> The change referenced by the Fixes tag reverted a previous fix because
> that fix added incorrect cleanup for the platform_device_register()
> failure path.
> 
> However, reverting the whole change also removed the cleanup for a later
> failure path. If platform_device_register() succeeds but device_add_disk()
> fails, the current floppy platform device has already been registered and
> registered[drive] has been set.
> 
> The common out_remove_drives path uses while (drive--), so it starts from
> the previous drive and does not unregister the current one. As a result,
> the platform device registered for the failing drive is leaked.
> 
> Unregister the current platform device directly on the device_add_disk()
> failure path, where platform_device_register() is known to have
> succeeded. Leave the platform_device_register() failure path unchanged.
> 
> Fixes: 895a9b37917d ("Revert "floppy: fix reference leak on platform_device_register() failure"")
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>

Reviewed-by: Denis Efremov (Oracle) <efremov@linux.com>

I would also add
Fixes: 47d34aa2d211 ("floppy: add error handling support for add_disk()")
Cc: stable@vger.kernel.org

> ---
>  drivers/block/floppy.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
> index f04397b8e381..7a34af534460 100644
> --- a/drivers/block/floppy.c
> +++ b/drivers/block/floppy.c
> @@ -4729,8 +4729,11 @@ static int __init do_floppy_init(void)
>  
>  		err = device_add_disk(&floppy_device[drive].dev,
>  				      disks[drive][0], NULL);
> -		if (err)
> +		if (err) {
> +			platform_device_unregister(&floppy_device[drive]);
> +			registered[drive] = false;
>  			goto out_remove_drives;
> +		}
>  	}
>  
>  	return 0;

Thanks,
Denis

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-24 13:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-08 10:57 [PATCH] floppy: unregister platform device on add_disk failure Guangshuo Li
2026-07-24 13:29 ` Denis Efremov (Oracle)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®