Skip to content

Commit

Permalink
block: use dedicated list iterator variable
Browse files Browse the repository at this point in the history
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 <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[axboe: move lookup to where return value is checked]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Jakob-Koschel authored and axboe committed Mar 31, 2022
1 parent d186832 commit 4a3b666
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -4448,21 +4448,28 @@ static bool blk_mq_elv_switch_none(struct list_head *head,
return true;
}

static void blk_mq_elv_switch_back(struct list_head *head,
struct request_queue *q)
static struct blk_mq_qe_pair *blk_lookup_qe_pair(struct list_head *head,
struct request_queue *q)
{
struct blk_mq_qe_pair *qe;
struct elevator_type *t = NULL;

list_for_each_entry(qe, head, node)
if (qe->q == q) {
t = qe->type;
break;
}
if (qe->q == q)
return qe;

if (!t)
return;
return NULL;
}

static void blk_mq_elv_switch_back(struct list_head *head,
struct request_queue *q)
{
struct blk_mq_qe_pair *qe;
struct elevator_type *t;

qe = blk_lookup_qe_pair(head, q);
if (!qe)
return;
t = qe->type;
list_del(&qe->node);
kfree(qe);

Expand Down

0 comments on commit 4a3b666

Please sign in to comment.