From: Bart Van Assche <bvanassche@acm.org>
To: Jakob Koschel <jakobkoschel@gmail.com>, Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
Mike Rapoport <rppt@kernel.org>,
Brian Johannesmeyer <bjohannesmeyer@gmail.com>,
Cristiano Giuffrida <c.giuffrida@vu.nl>,
"Bos, H.J." <h.j.bos@vu.nl>
Subject: Re: [PATCH] block: use dedicated list iterator variable
Date: Sun, 27 Mar 2022 19:02:46 -0700 [thread overview]
Message-ID: <49f08642-8878-8574-ce86-d1baf41f1189@acm.org> (raw)
In-Reply-To: <20220327214704.2188742-1-jakobkoschel@gmail.com>
On 3/27/22 14:47, Jakob Koschel wrote:
> 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/
> Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
> ---
> block/blk-mq.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index 8e659dc5fcf3..455fdd488f3c 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -4466,12 +4466,14 @@ static bool blk_mq_elv_switch_none(struct list_head *head,
> static void blk_mq_elv_switch_back(struct list_head *head,
> struct request_queue *q)
> {
> - struct blk_mq_qe_pair *qe;
> + struct blk_mq_qe_pair *qe = NULL;
> + struct blk_mq_qe_pair *iter;
> struct elevator_type *t = NULL;
>
> - list_for_each_entry(qe, head, node)
> - if (qe->q == q) {
> - t = qe->type;
> + list_for_each_entry(iter, head, node)
> + if (iter->q == q) {
> + t = iter->type;
> + qe = iter;
> break;
> }
The current code looks much more readable to me than with the above
patch applied. How about replacing the above patch with the patch below?
Thanks,
Bart.
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 9c784262fd6b..c9435be54667 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -4451,21 +4451,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;
+
+ return NULL;
+}
+
+static void blk_mq_elv_switch_back(struct list_head *head,
+ struct request_queue *q)
+{
+ struct blk_mq_qe_pair *qe = blk_lookup_qe_pair(head, q);
+ struct elevator_type *t;
- if (!t)
+ if (!qe)
return;
+ t = qe->type;
list_del(&qe->node);
kfree(qe);
prev parent reply other threads:[~2022-03-28 2:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-27 21:47 [PATCH] block: use dedicated list iterator variable Jakob Koschel
2022-03-28 2:02 ` Bart Van Assche [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49f08642-8878-8574-ce86-d1baf41f1189@acm.org \
--to=bvanassche@acm.org \
--cc=axboe@kernel.dk \
--cc=bjohannesmeyer@gmail.com \
--cc=c.giuffrida@vu.nl \
--cc=h.j.bos@vu.nl \
--cc=jakobkoschel@gmail.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox