From 1e41c5056619ec50b8146534881d6e0d6a7ca5ba Mon Sep 17 00:00:00 2001 From: Joseph Qi Date: Thu, 23 May 2019 19:49:12 +0800 Subject: [PATCH 0604/2944] blk-mq: fix NULL pointer deference in case no poll implementation In case some drivers such virtio-blk, poll function is not implementatin yet. Before commit 529262d5 ("block: remove ->poll_fn"), q->poll_fn is NULL and then blk_poll() won't do poll actually. So add a check for this to avoid NULL pointer dereference when calling q->mq_ops->poll. Signed-off-by: Joseph Qi Reviewed-by: Xiaoguang Wang --- block/blk-mq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index db251c6..a2e20b3 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3283,7 +3283,7 @@ int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin) struct blk_mq_hw_ctx *hctx; long state; - if (!blk_qc_t_valid(cookie) || + if (!blk_qc_t_valid(cookie) || !q->mq_ops->poll || !test_bit(QUEUE_FLAG_POLL, &q->queue_flags)) return 0; -- 1.8.3.1