All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] block: use dedicated list iterator variable
@ 2022-03-31  9:12 Jakob Koschel
  2022-03-31 11:59 ` Jens Axboe
  2022-03-31 12:06 ` Jens Axboe
  0 siblings, 2 replies; 5+ messages in thread
From: Jakob Koschel @ 2022-03-31  9:12 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, linux-kernel, Bart Van Assche, 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/ [1]
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
---

v1->v2:
- introduce blk_lookup_qe_pair() for more readable code (Bart Van Assche)

 block/blk-mq.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index e6f24fa4a4c2..f7f950cce452 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -4462,21 +4462,27 @@ 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 = blk_lookup_qe_pair(head, q);
+	struct elevator_type *t;

+	if (!qe)
+		return;
+	t = qe->type;
 	list_del(&qe->node);
 	kfree(qe);


base-commit: d888c83fcec75194a8a48ccd283953bdba7b2550
--
2.25.1


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

* Re: [PATCH v2] block: use dedicated list iterator variable
  2022-03-31  9:12 [PATCH v2] block: use dedicated list iterator variable Jakob Koschel
@ 2022-03-31 11:59 ` Jens Axboe
  2022-03-31 12:00   ` Jakob Koschel
  2022-03-31 12:06 ` Jens Axboe
  1 sibling, 1 reply; 5+ messages in thread
From: Jens Axboe @ 2022-03-31 11:59 UTC (permalink / raw)
  To: Jakob Koschel
  Cc: linux-block, linux-kernel, Bart Van Assche, Mike Rapoport,
	Brian Johannesmeyer, Cristiano Giuffrida, Bos, H.J.

On 3/31/22 3:12 AM, 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].

Not a huge fan of doing a helper for this single use, but I guess it
does make the main function easier to code. So I guess that's fine. But
can you move the call down where the result is checked?

qe = blk_lookup_qe_pair(head, q);
if (!qe)
	return;

I prefer no distance between call and check, makes it easier to read. I
can make the edit locally and note it in the commit message so you don't
have to re-send it. Let me know, or just resend a v3.

-- 
Jens Axboe


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

* Re: [PATCH v2] block: use dedicated list iterator variable
  2022-03-31 11:59 ` Jens Axboe
@ 2022-03-31 12:00   ` Jakob Koschel
  2022-03-31 12:06     ` Jens Axboe
  0 siblings, 1 reply; 5+ messages in thread
From: Jakob Koschel @ 2022-03-31 12:00 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, linux-kernel, Bart Van Assche, Mike Rapoport,
	Brian Johannesmeyer, Cristiano Giuffrida, Bos, H.J.



> On 31. Mar 2022, at 13:59, Jens Axboe <axboe@kernel.dk> wrote:
> 
> On 3/31/22 3:12 AM, 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].
> 
> Not a huge fan of doing a helper for this single use, but I guess it
> does make the main function easier to code. So I guess that's fine. But
> can you move the call down where the result is checked?
> 
> qe = blk_lookup_qe_pair(head, q);
> if (!qe)
> 	return;
> 
> I prefer no distance between call and check, makes it easier to read. I
> can make the edit locally and note it in the commit message so you don't
> have to re-send it. Let me know, or just resend a v3.

I'm fine with you doing the change locally, thanks!

> 
> -- 
> Jens Axboe
> 

	Jakob

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

* Re: [PATCH v2] block: use dedicated list iterator variable
  2022-03-31  9:12 [PATCH v2] block: use dedicated list iterator variable Jakob Koschel
  2022-03-31 11:59 ` Jens Axboe
@ 2022-03-31 12:06 ` Jens Axboe
  1 sibling, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2022-03-31 12:06 UTC (permalink / raw)
  To: Jakob Koschel
  Cc: Bos, H.J.,
	linux-kernel, Brian Johannesmeyer, Mike Rapoport, linux-block,
	Bart Van Assche, Cristiano Giuffrida

On Thu, 31 Mar 2022 11:12:18 +0200, 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].
> 
> [...]

Applied, thanks!

[1/1] block: use dedicated list iterator variable
      commit: 4a3b666e0ea977dd40adb56c37a91370f76fa19e

Best regards,
-- 
Jens Axboe



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

* Re: [PATCH v2] block: use dedicated list iterator variable
  2022-03-31 12:00   ` Jakob Koschel
@ 2022-03-31 12:06     ` Jens Axboe
  0 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2022-03-31 12:06 UTC (permalink / raw)
  To: Jakob Koschel
  Cc: linux-block, linux-kernel, Bart Van Assche, Mike Rapoport,
	Brian Johannesmeyer, Cristiano Giuffrida, Bos, H.J.

On 3/31/22 6:00 AM, Jakob Koschel wrote:
> 
> 
>> On 31. Mar 2022, at 13:59, Jens Axboe <axboe@kernel.dk> wrote:
>>
>> On 3/31/22 3:12 AM, 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].
>>
>> Not a huge fan of doing a helper for this single use, but I guess it
>> does make the main function easier to code. So I guess that's fine. But
>> can you move the call down where the result is checked?
>>
>> qe = blk_lookup_qe_pair(head, q);
>> if (!qe)
>> 	return;
>>
>> I prefer no distance between call and check, makes it easier to read. I
>> can make the edit locally and note it in the commit message so you don't
>> have to re-send it. Let me know, or just resend a v3.
> 
> I'm fine with you doing the change locally, thanks!

OK, I did that, it's in. Thanks!

-- 
Jens Axboe


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

end of thread, other threads:[~2022-03-31 12:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-31  9:12 [PATCH v2] block: use dedicated list iterator variable Jakob Koschel
2022-03-31 11:59 ` Jens Axboe
2022-03-31 12:00   ` Jakob Koschel
2022-03-31 12:06     ` Jens Axboe
2022-03-31 12:06 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.