Skip to contentSkip to conversation

block: check poll() callback when setting QUEUE_FLAG_POLL

PATCH New Jeffle Xu 1 participant 1 message Sep 24, 2020 Block layer

lore
Share & tools
lore

Jeffle Xu

author
#0 lore raw

PATCH 1/1 block: check poll() callback when setting QUEUE_FLAG_POLL

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.

---
 block/blk-mq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-mq.c +1 -1
index b3d2785eefe9..12f6b3406211 100644
@@ -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);
 
Signature · 1 line
2.27.0