linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thunderbolt: replace usage of found with dedicated list iterator variable
@ 2022-03-24  7:27 Jakob Koschel
  2022-03-24 12:19 ` Mika Westerberg
  2022-04-04  9:36 ` Mika Westerberg
  0 siblings, 2 replies; 3+ messages in thread
From: Jakob Koschel @ 2022-03-24  7:27 UTC (permalink / raw)
  To: Andreas Noever
  Cc: Michael Jamet, Mika Westerberg, Yehezkel Bernat, linux-usb,
	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].

This removes the need to use a found variable and simply checking if
the variable was set, can determine if the break/goto was hit.

Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
---
 drivers/thunderbolt/ctl.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/thunderbolt/ctl.c b/drivers/thunderbolt/ctl.c
index 4986edfbdf67..e92c658dba1c 100644
--- a/drivers/thunderbolt/ctl.c
+++ b/drivers/thunderbolt/ctl.c
@@ -158,21 +158,20 @@ static bool tb_cfg_request_is_active(struct tb_cfg_request *req)
 static struct tb_cfg_request *
 tb_cfg_request_find(struct tb_ctl *ctl, struct ctl_pkg *pkg)
 {
-	struct tb_cfg_request *req;
-	bool found = false;
+	struct tb_cfg_request *req = NULL, *iter;
 
 	mutex_lock(&pkg->ctl->request_queue_lock);
-	list_for_each_entry(req, &pkg->ctl->request_queue, list) {
-		tb_cfg_request_get(req);
-		if (req->match(req, pkg)) {
-			found = true;
+	list_for_each_entry(iter, &pkg->ctl->request_queue, list) {
+		tb_cfg_request_get(iter);
+		if (iter->match(iter, pkg)) {
+			req = iter;
 			break;
 		}
-		tb_cfg_request_put(req);
+		tb_cfg_request_put(iter);
 	}
 	mutex_unlock(&pkg->ctl->request_queue_lock);
 
-	return found ? req : NULL;
+	return req;
 }
 
 /* utility functions */

base-commit: f443e374ae131c168a065ea1748feac6b2e76613
-- 
2.25.1


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

* Re: [PATCH] thunderbolt: replace usage of found with dedicated list iterator variable
  2022-03-24  7:27 [PATCH] thunderbolt: replace usage of found with dedicated list iterator variable Jakob Koschel
@ 2022-03-24 12:19 ` Mika Westerberg
  2022-04-04  9:36 ` Mika Westerberg
  1 sibling, 0 replies; 3+ messages in thread
From: Mika Westerberg @ 2022-03-24 12:19 UTC (permalink / raw)
  To: Jakob Koschel
  Cc: Andreas Noever, Michael Jamet, Yehezkel Bernat, linux-usb,
	linux-kernel, Mike Rapoport, Brian Johannesmeyer,
	Cristiano Giuffrida, Bos, H.J.

Hi Jakob,

On Thu, Mar 24, 2022 at 08:27:00AM +0100, 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].
> 
> This removes the need to use a found variable and simply checking if
> the variable was set, can determine if the break/goto was hit.
> 
> Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/
> Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>

Looks good to me. I will pick this up to Thunderbolt tree after the
merge window closes.

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

* Re: [PATCH] thunderbolt: replace usage of found with dedicated list iterator variable
  2022-03-24  7:27 [PATCH] thunderbolt: replace usage of found with dedicated list iterator variable Jakob Koschel
  2022-03-24 12:19 ` Mika Westerberg
@ 2022-04-04  9:36 ` Mika Westerberg
  1 sibling, 0 replies; 3+ messages in thread
From: Mika Westerberg @ 2022-04-04  9:36 UTC (permalink / raw)
  To: Jakob Koschel
  Cc: Andreas Noever, Michael Jamet, Yehezkel Bernat, linux-usb,
	linux-kernel, Mike Rapoport, Brian Johannesmeyer,
	Cristiano Giuffrida, Bos, H.J.

On Thu, Mar 24, 2022 at 08:27:00AM +0100, 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].
> 
> This removes the need to use a found variable and simply checking if
> the variable was set, can determine if the break/goto was hit.
> 
> Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/
> Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>

Applied to thunderbolt.git/next, thanks!

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

end of thread, other threads:[~2022-04-04  9:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24  7:27 [PATCH] thunderbolt: replace usage of found with dedicated list iterator variable Jakob Koschel
2022-03-24 12:19 ` Mika Westerberg
2022-04-04  9:36 ` Mika Westerberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).