From: Ming Lei <ming.lei@redhat.com>
To: Yang Xiuwei <yangxiuwei@kylinos.cn>
Cc: James Bottomley <James.Bottomley@hansenpartnership.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, Bart Van Assche <bvanassche@acm.org>,
John Garry <john.g.garry@oracle.com>,
stable@vger.kernel.org
Subject: Re: [PATCH v3] scsi: sd: fix missing put_disk() when device_add(&disk_dev) fails
Date: Mon, 30 Mar 2026 10:12:51 +0800 [thread overview]
Message-ID: <acncI-IZhtdDsmJg@fedora> (raw)
In-Reply-To: <20260330014952.152776-1-yangxiuwei@kylinos.cn>
On Mon, Mar 30, 2026 at 09:49:52AM +0800, Yang Xiuwei wrote:
> If device_add(&sdkp->disk_dev) fails, put_device() runs
> scsi_disk_release(), which frees the scsi_disk but leaves the gendisk
> referenced. The device_add_disk() error path in sd_probe() calls
> put_disk(gd); call put_disk(gd) here to mirror that cleanup.
>
> Fixes: 265dfe8ebbab ("scsi: sd: Free scsi_disk device via put_device()")
> Cc: stable@vger.kernel.org
> Reviewed-by: John Garry <john.g.garry@oracle.com>
> Signed-off-by: Yang Xiuwei <yangxiuwei@kylinos.cn>
> ---
> v2: Add Fixes: and Cc: stable; add a short note on how the issue was found.
> v3: Commit message and subject refined per review; add Reviewed-by from John Garry.
>
> drivers/scsi/sd.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 628a1d0a74ba..aba22060fcd5 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -4018,6 +4018,7 @@ static int sd_probe(struct scsi_device *sdp)
> error = device_add(&sdkp->disk_dev);
> if (error) {
> put_device(&sdkp->disk_dev);
> + put_disk(gd);
> goto out;
> }
Another fix is to clear `sdkp` and `goto out_put`:
- clearing `sdkp` because the device is released already, and this way is `memory safe`
- `goto out_put` can release disk centrally
Thanks,
Ming
next prev parent reply other threads:[~2026-03-30 2:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 1:49 [PATCH v3] scsi: sd: fix missing put_disk() when device_add(&disk_dev) fails Yang Xiuwei
2026-03-30 2:12 ` Ming Lei [this message]
2026-03-30 3:06 ` Yang Xiuwei
2026-04-09 2:11 ` Martin K. Petersen
2026-04-14 2:19 ` Martin K. Petersen
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=acncI-IZhtdDsmJg@fedora \
--to=ming.lei@redhat.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=bvanassche@acm.org \
--cc=john.g.garry@oracle.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=stable@vger.kernel.org \
--cc=yangxiuwei@kylinos.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.