First, don't init a callback list if there are no plug callbacks. Also, replace internals of the function with do-while. Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx> --- block/blk-mq.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 6bdbaa838030..6627ea76f7c6 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2251,22 +2251,24 @@ static void flush_plug_callbacks(struct blk_plug *plug, bool from_schedule) { LIST_HEAD(callbacks); - while (!list_empty(&plug->cb_list)) { + do { list_splice_init(&plug->cb_list, &callbacks); - while (!list_empty(&callbacks)) { + do { struct blk_plug_cb *cb = list_first_entry(&callbacks, struct blk_plug_cb, list); + list_del(&cb->list); cb->callback(cb, from_schedule); - } - } + } while (!list_empty(&callbacks)); + } while (!list_empty(&plug->cb_list)); } void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule) { - flush_plug_callbacks(plug, from_schedule); + if (!list_empty(&plug->cb_list)) + flush_plug_callbacks(plug, from_schedule); if (!rq_list_empty(plug->mq_list)) blk_mq_flush_plug_list(plug, from_schedule); -- 2.33.1