Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: sd: do not call device_add() on scsi_disk with uninitialized gendisk ->queue
@ 2021-09-02 16:24 Ewan D. Milne
  2021-09-02 17:00 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Ewan D. Milne @ 2021-09-02 16:24 UTC (permalink / raw)
  To: linux-scsi

Calling device_add() makes the scsi_disk visible in sysfs, the accessor
routines reference sdkp->disk->queue which was not yet set properly.
Fix this by initializing gendisk fields earlier in the function.

Signed-off-by: Ewan D. Milne <emilne@redhat.com>
---
 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 6d2d636..97ab18b 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3428,6 +3428,13 @@ static int sd_probe(struct device *dev)
 		goto out_free_index;
 	}
 
+	gd->major = sd_major((index & 0xf0) >> 4);
+	gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00);
+
+	gd->fops = &sd_fops;
+	gd->private_data = &sdkp->driver;
+	gd->queue = sdp->request_queue;
+
 	sdkp->device = sdp;
 	sdkp->driver = &sd_template;
 	sdkp->disk = gd;
@@ -3456,13 +3463,6 @@ static int sd_probe(struct device *dev)
 	get_device(dev);
 	dev_set_drvdata(dev, sdkp);
 
-	gd->major = sd_major((index & 0xf0) >> 4);
-	gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00);
-
-	gd->fops = &sd_fops;
-	gd->private_data = &sdkp->driver;
-	gd->queue = sdkp->device->request_queue;
-
 	/* defaults, until the device tells us otherwise */
 	sdp->sector_size = 512;
 	sdkp->capacity = 0;
-- 
2.1.0


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

end of thread, other threads:[~2021-09-03  4:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-02 16:24 [PATCH] scsi: sd: do not call device_add() on scsi_disk with uninitialized gendisk ->queue Ewan D. Milne
2021-09-02 17:00 ` Christoph Hellwig
2021-09-02 19:35   ` Ewan Milne
2021-09-03  4:41     ` Christoph Hellwig

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