linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] habanalabs: replace usage of found with dedicated list iterator variable
@ 2022-03-24  7:10 Jakob Koschel
  2022-03-24 14:40 ` Oded Gabbay
  0 siblings, 1 reply; 2+ messages in thread
From: Jakob Koschel @ 2022-03-24  7:10 UTC (permalink / raw)
  To: Oded Gabbay
  Cc: Arnd Bergmann, Greg Kroah-Hartman, Ofir Bitton, Dani Liberman,
	Ohad Sharabi, farah kassabri, 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/misc/habanalabs/common/command_submission.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/misc/habanalabs/common/command_submission.c b/drivers/misc/habanalabs/common/command_submission.c
index 0a4ef13d9ac4..4927749e439c 100644
--- a/drivers/misc/habanalabs/common/command_submission.c
+++ b/drivers/misc/habanalabs/common/command_submission.c
@@ -405,8 +405,7 @@ static void staged_cs_put(struct hl_device *hdev, struct hl_cs *cs)
 
 static void cs_handle_tdr(struct hl_device *hdev, struct hl_cs *cs)
 {
-	bool next_entry_found = false;
-	struct hl_cs *next, *first_cs;
+	struct hl_cs *next = NULL, *iter, *first_cs;
 
 	if (!cs_needs_timeout(cs))
 		return;
@@ -441,13 +440,13 @@ static void cs_handle_tdr(struct hl_device *hdev, struct hl_cs *cs)
 	spin_lock(&hdev->cs_mirror_lock);
 
 	/* queue TDR for next CS */
-	list_for_each_entry(next, &hdev->cs_mirror_list, mirror_node)
-		if (cs_needs_timeout(next)) {
-			next_entry_found = true;
+	list_for_each_entry(iter, &hdev->cs_mirror_list, mirror_node)
+		if (cs_needs_timeout(iter)) {
+			next = iter;
 			break;
 		}
 
-	if (next_entry_found && !next->tdr_active) {
+	if (next && !next->tdr_active) {
 		next->tdr_active = true;
 		schedule_delayed_work(&next->work_tdr, next->timeout_jiffies);
 	}

base-commit: f443e374ae131c168a065ea1748feac6b2e76613
-- 
2.25.1


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

* Re: [PATCH] habanalabs: replace usage of found with dedicated list iterator variable
  2022-03-24  7:10 [PATCH] habanalabs: replace usage of found with dedicated list iterator variable Jakob Koschel
@ 2022-03-24 14:40 ` Oded Gabbay
  0 siblings, 0 replies; 2+ messages in thread
From: Oded Gabbay @ 2022-03-24 14:40 UTC (permalink / raw)
  To: Jakob Koschel
  Cc: Arnd Bergmann, Greg Kroah-Hartman, Ofir Bitton, Dani Liberman,
	Ohad Sharabi, farah kassabri, Linux-Kernel@Vger. Kernel. Org,
	Mike Rapoport, Brian Johannesmeyer, Cristiano Giuffrida, Bos,
	H.J.

On Thu, Mar 24, 2022 at 9:11 AM Jakob Koschel <jakobkoschel@gmail.com> 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>
> ---
>  drivers/misc/habanalabs/common/command_submission.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/misc/habanalabs/common/command_submission.c b/drivers/misc/habanalabs/common/command_submission.c
> index 0a4ef13d9ac4..4927749e439c 100644
> --- a/drivers/misc/habanalabs/common/command_submission.c
> +++ b/drivers/misc/habanalabs/common/command_submission.c
> @@ -405,8 +405,7 @@ static void staged_cs_put(struct hl_device *hdev, struct hl_cs *cs)
>
>  static void cs_handle_tdr(struct hl_device *hdev, struct hl_cs *cs)
>  {
> -       bool next_entry_found = false;
> -       struct hl_cs *next, *first_cs;
> +       struct hl_cs *next = NULL, *iter, *first_cs;
>
>         if (!cs_needs_timeout(cs))
>                 return;
> @@ -441,13 +440,13 @@ static void cs_handle_tdr(struct hl_device *hdev, struct hl_cs *cs)
>         spin_lock(&hdev->cs_mirror_lock);
>
>         /* queue TDR for next CS */
> -       list_for_each_entry(next, &hdev->cs_mirror_list, mirror_node)
> -               if (cs_needs_timeout(next)) {
> -                       next_entry_found = true;
> +       list_for_each_entry(iter, &hdev->cs_mirror_list, mirror_node)
> +               if (cs_needs_timeout(iter)) {
> +                       next = iter;
>                         break;
>                 }
>
> -       if (next_entry_found && !next->tdr_active) {
> +       if (next && !next->tdr_active) {
>                 next->tdr_active = true;
>                 schedule_delayed_work(&next->work_tdr, next->timeout_jiffies);
>         }
>
> base-commit: f443e374ae131c168a065ea1748feac6b2e76613
> --
> 2.25.1
>
This patch is
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>

Applied to -next.

Thanks,
Oded

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

end of thread, other threads:[~2022-03-24 14:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24  7:10 [PATCH] habanalabs: replace usage of found with dedicated list iterator variable Jakob Koschel
2022-03-24 14:40 ` Oded Gabbay

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).