Message ID | 20210902162425.17208-1-emilne@redhat.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | scsi: sd: do not call device_add() on scsi_disk with uninitialized gendisk ->queue | expand |
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.
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. >
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.
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;
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(-)