public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: "Denis Efremov (Oracle)" <efremov@linux.com>
To: Guangshuo Li <lgs201920130244@gmail.com>,
	Jens Axboe <axboe@kernel.dk>, Greg Kroah-Hartman <gregkh@suse.de>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: Re: [PATCH] floppy: fix reference leak on platform_device_register() failure
Date: Wed, 15 Apr 2026 17:00:39 +0400	[thread overview]
Message-ID: <8afc6b6b-399e-4f77-82e8-3c0e717f765e@linux.com> (raw)
In-Reply-To: <20260413153114.3040093-1-lgs201920130244@gmail.com>

Hello,

Thank you for the patch,

On 13/04/2026 19:31, Guangshuo Li wrote:
> 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: 94fd0db7bfb4a ("[PATCH] Floppy: Add cmos attribute to floppy driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
>  drivers/block/floppy.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
> index c28786e0fe1c..d9afe495d5c2 100644
> --- a/drivers/block/floppy.c
> +++ b/drivers/block/floppy.c
> @@ -4724,8 +4724,10 @@ static int __init do_floppy_init(void)
>  		floppy_device[drive].dev.groups = floppy_dev_groups;
>  
>  		err = platform_device_register(&floppy_device[drive]);
> -		if (err)
> +		if (err) {
> +			put_device(&floppy_device[drive].dev);

1. Let's use platform_device_put()

>  			goto out_remove_drives;
> +		}
>  
>  		registered[drive] = true;
>  

                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

  reply	other threads:[~2026-04-15 13:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-13 15:31 [PATCH] floppy: fix reference leak on platform_device_register() failure Guangshuo Li
2026-04-15 13:00 ` Denis Efremov (Oracle) [this message]
2026-04-15 13:54   ` Guangshuo Li
2026-04-15 14:15     ` Denis Efremov (Oracle)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8afc6b6b-399e-4f77-82e8-3c0e717f765e@linux.com \
    --to=efremov@linux.com \
    --cc=axboe@kernel.dk \
    --cc=gregkh@suse.de \
    --cc=lgs201920130244@gmail.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox