diff mbox series

block: check poll() callback when setting QUEUE_FLAG_POLL

Message ID 20200924041530.114227-1-jefflexu@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series block: check poll() callback when setting QUEUE_FLAG_POLL | expand

Commit Message

Jingbo Xu Sept. 24, 2020, 4:15 a.m. UTC
If queue mapping is set for polling while mq_ops->poll() not
defined, blk_poll() will crash directly.

I can understand this constraint is achieved by ensuring that
mq_ops->poll() will always be defined whenever queue mapping
is set for polling during code review phase.

However adding the extra checking can enhance the code robustness,
and the checking is cheap after all since it's done only once when
initializing the queue.

Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
---
 block/blk-mq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/block/blk-mq.c b/block/blk-mq.c
index b3d2785eefe9..12f6b3406211 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -3204,7 +3204,7 @@  struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
 	q->tag_set = set;
 
 	q->queue_flags |= QUEUE_FLAG_MQ_DEFAULT;
-	if (set->nr_maps > HCTX_TYPE_POLL &&
+	if (q->mq_ops->poll && set->nr_maps > HCTX_TYPE_POLL &&
 	    set->map[HCTX_TYPE_POLL].nr_queues)
 		blk_queue_flag_set(QUEUE_FLAG_POLL, q);