Skip to content

Commit 4a3b666

Browse files
Jakob-Koschelaxboe
authored andcommitted
block: use dedicated list iterator variable
To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable instead of a found boolean [1]. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com> Link: https://lore.kernel.org/r/20220331091218.641532-1-jakobkoschel@gmail.com [axboe: move lookup to where return value is checked] Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent d186832 commit 4a3b666

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

block/blk-mq.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4448,21 +4448,28 @@ static bool blk_mq_elv_switch_none(struct list_head *head,
44484448
return true;
44494449
}
44504450

4451-
static void blk_mq_elv_switch_back(struct list_head *head,
4452-
struct request_queue *q)
4451+
static struct blk_mq_qe_pair *blk_lookup_qe_pair(struct list_head *head,
4452+
struct request_queue *q)
44534453
{
44544454
struct blk_mq_qe_pair *qe;
4455-
struct elevator_type *t = NULL;
44564455

44574456
list_for_each_entry(qe, head, node)
4458-
if (qe->q == q) {
4459-
t = qe->type;
4460-
break;
4461-
}
4457+
if (qe->q == q)
4458+
return qe;
44624459

4463-
if (!t)
4464-
return;
4460+
return NULL;
4461+
}
44654462

4463+
static void blk_mq_elv_switch_back(struct list_head *head,
4464+
struct request_queue *q)
4465+
{
4466+
struct blk_mq_qe_pair *qe;
4467+
struct elevator_type *t;
4468+
4469+
qe = blk_lookup_qe_pair(head, q);
4470+
if (!qe)
4471+
return;
4472+
t = qe->type;
44664473
list_del(&qe->node);
44674474
kfree(qe);
44684475

0 commit comments

Comments
 (0)