From: Damien Le Moal <dlemoal@kernel.org>
To: Yang Xiuwei <yangxiuwei@kylinos.cn>,
martin.petersen@oracle.com,
James.Bottomley@HansenPartnership.com
Cc: hare@suse.de, tom.leiming@gmail.com, p.raghav@samsung.com,
sw.prabhu6@gmail.com, linux-scsi@vger.kernel.org
Subject: Re: [PATCH v1 2/4] scsi: sd: unify sd_probe() error cleanup through out_put
Date: Sat, 27 Jun 2026 06:54:44 +0900 [thread overview]
Message-ID: <00c16485-fc4b-43bd-a420-89b3b5eebaeb@kernel.org> (raw)
In-Reply-To: <20260623100159.4018066-3-yangxiuwei@kylinos.cn>
On 6/23/26 19:01, Yang Xiuwei wrote:
> After put_device() or device_unregister() has released sdkp through
> scsi_disk_release(), set sdkp to NULL and fall through to out_put so
> put_disk() and kfree() are handled in one place.
>
> Suggested-by: Ming Lei <tom.leiming@gmail.com>
> Signed-off-by: Yang Xiuwei <yangxiuwei@kylinos.cn>
> ---
> drivers/scsi/sd.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index d18693d390b2..b096ea237f14 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -4060,8 +4060,8 @@ 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;
> + sdkp = NULL;
> + goto out_put;
> }
>
> dev_set_drvdata(dev, sdkp);
> @@ -4090,8 +4090,8 @@ static int sd_probe(struct scsi_device *sdp)
> if (sd_large_pool_create()) {
> error = -ENOMEM;
> device_unregister(&sdkp->disk_dev);
> - put_disk(gd);
> - goto out;
> + sdkp = NULL;
> + goto out_put;
device_unregister() is called here and in the next error path too. So what about
a "goto out_unregister;" to avoid repeating this pattern ?
> }
> }
>
> @@ -4109,11 +4109,11 @@ static int sd_probe(struct scsi_device *sdp)
>
> error = device_add_disk(dev, gd, NULL);
> if (error) {
> - device_unregister(&sdkp->disk_dev);
> - put_disk(gd);
> if (sdp->sector_size > PAGE_SIZE)
> sd_large_pool_destroy();
> - goto out;
> + device_unregister(&sdkp->disk_dev);
> + sdkp = NULL;
> + goto out_put;
> }
>
> if (sdkp->security) {
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2026-06-26 21:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-23 10:01 [PATCH v1 0/4] scsi: sd: fix probe error cleanup, special_vec leak and sd_done() sense gate Yang Xiuwei
2026-06-23 10:01 ` [PATCH v1 1/4] scsi: sd: fix error handling in sd_probe() after large pool creation failure Yang Xiuwei
2026-06-26 21:52 ` Damien Le Moal
2026-06-23 10:01 ` [PATCH v1 2/4] scsi: sd: unify sd_probe() error cleanup through out_put Yang Xiuwei
2026-06-26 21:54 ` Damien Le Moal [this message]
2026-06-29 1:16 ` Yang Xiuwei
2026-06-29 5:03 ` Damien Le Moal
2026-06-23 10:01 ` [PATCH v1 3/4] scsi: sd: fix special_vec mempool leak when scsi_alloc_sgtables() fails Yang Xiuwei
2026-06-23 10:20 ` sashiko-bot
2026-06-26 21:57 ` Damien Le Moal
2026-06-23 10:01 ` [PATCH v1 4/4] scsi: sd: fix sd_done() sense handling condition Yang Xiuwei
2026-06-23 10:18 ` sashiko-bot
2026-06-26 22:07 ` Damien Le Moal
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=00c16485-fc4b-43bd-a420-89b3b5eebaeb@kernel.org \
--to=dlemoal@kernel.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=hare@suse.de \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=p.raghav@samsung.com \
--cc=sw.prabhu6@gmail.com \
--cc=tom.leiming@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox