On Thu, 2017-02-16 at 16:12 +0100, Hannes Reinecke wrote:
> +struct scsi_device *scsi_device_from_queue(struct request_queue *q)
> +{
> +     struct scsi_device *sdev = NULL;
> +     unsigned long flags;
> +
> +     spin_lock_irqsave(q->queue_lock, flags);
> +     if (q->mq_ops) {
> +             if (q->mq_ops == &scsi_mq_ops)
> +                     sdev = q->queuedata;
> +     } else if (q->request_fn == scsi_request_fn)
> +             sdev = q->queuedata;
> +     if (!sdev || !get_device(&sdev->sdev_gendev))
> +             sdev = NULL;
> +     spin_unlock_irqrestore(q->queue_lock, flags);
> +
> +     return sdev;
> +}

Hello Hannes,

Do we need to take the queue lock? Neither q->mq_ops nor q->request_fn are
modified after a block device has been created. q->queuedata is not modified
by any SCSI driver after it has been set. And since the caller of
scsi_device_from_queue() has to guarantee that the queue does not disappear
while this function is in progress, the queue lock does not have to be held
around the get_device() call either. Otherwise this patch looks fine to me.

Bart.

Reply via email to