* [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
* Re: [PATCH] scsi: sd: do not call device_add() on scsi_disk with uninitialized gendisk ->queue
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
0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2021-09-02 17:00 UTC (permalink / raw)
To: Ewan D. Milne; +Cc: linux-scsi
On Thu, Sep 02, 2021 at 12:24:25PM -0400, Ewan D. Milne wrote:
> 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.
What kernel is this against? This won't apply against linux-next
as disk->queue is now always set up by __blk_alloc_disk.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: sd: do not call device_add() on scsi_disk with uninitialized gendisk ->queue
2021-09-02 17:00 ` Christoph Hellwig
@ 2021-09-02 19:35 ` Ewan Milne
2021-09-03 4:41 ` Christoph Hellwig
0 siblings, 1 reply; 4+ messages in thread
From: Ewan Milne @ 2021-09-02 19:35 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: linux-scsi
It was against git://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git
branch "fixes".
Looks like your changes resolve ->queue not being set prior to add_device(),
please disregard my patch. It's not that critical to fix in earlier versions.
Sorry for the noise.
-Ewan
On Thu, Sep 2, 2021 at 1:01 PM Christoph Hellwig <hch@infradead.org> wrote:
>
> On Thu, Sep 02, 2021 at 12:24:25PM -0400, Ewan D. Milne wrote:
> > 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.
>
> What kernel is this against? This won't apply against linux-next
> as disk->queue is now always set up by __blk_alloc_disk.
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: sd: do not call device_add() on scsi_disk with uninitialized gendisk ->queue
2021-09-02 19:35 ` Ewan Milne
@ 2021-09-03 4:41 ` Christoph Hellwig
0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2021-09-03 4:41 UTC (permalink / raw)
To: Ewan Milne; +Cc: Christoph Hellwig, linux-scsi
On Thu, Sep 02, 2021 at 03:35:23PM -0400, Ewan Milne wrote:
> It was against git://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git
> branch "fixes".
>
> Looks like your changes resolve ->queue not being set prior to add_device(),
> please disregard my patch. It's not that critical to fix in earlier versions.
> Sorry for the noise.
This might still be useful for -stable. It just needs to be clearly
tagged as such.
^ permalink raw reply [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 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.