habanalabs: replace usage of found with dedicated list iterator variable
PATCH 1/1 habanalabs: replace usage of found with dedicated list iterator variable
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.
--- drivers/misc/habanalabs/common/command_submission.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +5 -6
@@ -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
Signature · 1 line
2.25.1
Quoted 51 lines · 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/ open hereSigned-off-by Jakob Koschel <[email protected]>--- drivers/misc/habanalabs/common/command_submission.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/misc/habanalabs/common/command_submission.c +5
-6@@ -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); }
Quoted 4 lines
base-commit:
f443e374ae131c168a065ea1748feac6b2e76613--
2.25.1
This patch is
Applied to -next.
Thanks,
Oded