public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] scsi: sd: fix missing put_disk() when device_add(&disk_dev) fails
@ 2026-03-30  1:49 Yang Xiuwei
  2026-03-30  2:12 ` Ming Lei
  0 siblings, 1 reply; 3+ messages in thread
From: Yang Xiuwei @ 2026-03-30  1:49 UTC (permalink / raw)
  To: James Bottomley, Martin K . Petersen
  Cc: linux-scsi, Ming Lei, Bart Van Assche, John Garry, stable,
	Yang Xiuwei

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;
 	}
 
-- 
2.25.1


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

end of thread, other threads:[~2026-03-30  3:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-03-30  3:06   ` Yang Xiuwei

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