block: bypass blk_set_runtime_active for uninitialized q->dev
authorStanley Chu <stanley.chu@mediatek.com>
Thu, 12 Sep 2019 08:35:27 +0000 (16:35 +0800)
committerJens Axboe <axboe@kernel.dk>
Thu, 12 Sep 2019 13:11:56 +0000 (07:11 -0600)
Some devices may skip blk_pm_runtime_init() and have null pointer
in its request_queue->dev. For example, SCSI devices of UFS Well-Known
LUNs.

Currently the null pointer is checked by the user of
blk_set_runtime_active(), i.e., scsi_dev_type_resume(). It is better to
check it by blk_set_runtime_active() itself instead of by its users.

Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-pm.c

index 0a028c1898977c5208223928c3f2d490c4213999..1adc1cd748b4038d8bb441d76fa9ca277d333c0c 100644 (file)
@@ -207,10 +207,12 @@ EXPORT_SYMBOL(blk_post_runtime_resume);
  */
 void blk_set_runtime_active(struct request_queue *q)
 {
-       spin_lock_irq(&q->queue_lock);
-       q->rpm_status = RPM_ACTIVE;
-       pm_runtime_mark_last_busy(q->dev);
-       pm_request_autosuspend(q->dev);
-       spin_unlock_irq(&q->queue_lock);
+       if (q->dev) {
+               spin_lock_irq(&q->queue_lock);
+               q->rpm_status = RPM_ACTIVE;
+               pm_runtime_mark_last_busy(q->dev);
+               pm_request_autosuspend(q->dev);
+               spin_unlock_irq(&q->queue_lock);
+       }
 }
 EXPORT_SYMBOL(blk_set_runtime_active);