Linux block layer
 help / color / mirror / Atom feed
* [PATCH] block: use dedicated list iterator variable
@ 2022-03-27 21:47 Jakob Koschel
  2022-03-28  2:02 ` Bart Van Assche
  0 siblings, 1 reply; 2+ messages in thread
From: Jakob Koschel @ 2022-03-27 21:47 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, linux-kernel, Mike Rapoport, Brian Johannesmeyer,
	Cristiano Giuffrida, Bos, H.J., Jakob Koschel

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;
 		}
 

base-commit: b47d5a4f6b8d42f8a8fbe891b36215e4fddc53be
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-28  2:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-27 21:47 [PATCH] block: use dedicated list iterator variable Jakob Koschel
2022-03-28  2:02 ` Bart Van Assche

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox