diff mbox series

[2/2] efi: replace usage of found with dedicated list iterator variable

Message ID 20220331221030.889718-2-jakobkoschel@gmail.com
State New
Headers show
Series [1/2] efi: remove use of list iterator variable after loop | expand

Commit Message

Jakob Koschel March 31, 2022, 10:10 p.m. UTC
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/firmware/efi/vars.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Comments

Ard Biesheuvel April 13, 2022, 5:09 p.m. UTC | #1
On Fri, 1 Apr 2022 at 00:11, 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>

Acked-by: Ard Biesheuvel <ardb@kernel.org>

I'll queue this up once we converge on a solution for the other patch.

> ---
>  drivers/firmware/efi/vars.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c
> index 3994aad38661..e4e1cc593441 100644
> --- a/drivers/firmware/efi/vars.c
> +++ b/drivers/firmware/efi/vars.c
> @@ -809,22 +809,21 @@ EXPORT_SYMBOL_GPL(efivar_entry_set_safe);
>  struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
>                                        struct list_head *head, bool remove)
>  {
> -       struct efivar_entry *entry, *n;
> +       struct efivar_entry *entry = NULL, *iter, *n;
>         int strsize1, strsize2;
> -       bool found = false;
>
> -       list_for_each_entry_safe(entry, n, head, list) {
> +       list_for_each_entry_safe(iter, n, head, list) {
>                 strsize1 = ucs2_strsize(name, 1024);
> -               strsize2 = ucs2_strsize(entry->var.VariableName, 1024);
> +               strsize2 = ucs2_strsize(iter->var.VariableName, 1024);
>                 if (strsize1 == strsize2 &&
> -                   !memcmp(name, &(entry->var.VariableName), strsize1) &&
> -                   !efi_guidcmp(guid, entry->var.VendorGuid)) {
> -                       found = true;
> +                   !memcmp(name, &(iter->var.VariableName), strsize1) &&
> +                   !efi_guidcmp(guid, iter->var.VendorGuid)) {
> +                       entry = iter;
>                         break;
>                 }
>         }
>
> -       if (!found)
> +       if (!entry)
>                 return NULL;
>
>         if (remove) {
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c
index 3994aad38661..e4e1cc593441 100644
--- a/drivers/firmware/efi/vars.c
+++ b/drivers/firmware/efi/vars.c
@@ -809,22 +809,21 @@  EXPORT_SYMBOL_GPL(efivar_entry_set_safe);
 struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
 				       struct list_head *head, bool remove)
 {
-	struct efivar_entry *entry, *n;
+	struct efivar_entry *entry = NULL, *iter, *n;
 	int strsize1, strsize2;
-	bool found = false;
 
-	list_for_each_entry_safe(entry, n, head, list) {
+	list_for_each_entry_safe(iter, n, head, list) {
 		strsize1 = ucs2_strsize(name, 1024);
-		strsize2 = ucs2_strsize(entry->var.VariableName, 1024);
+		strsize2 = ucs2_strsize(iter->var.VariableName, 1024);
 		if (strsize1 == strsize2 &&
-		    !memcmp(name, &(entry->var.VariableName), strsize1) &&
-		    !efi_guidcmp(guid, entry->var.VendorGuid)) {
-			found = true;
+		    !memcmp(name, &(iter->var.VariableName), strsize1) &&
+		    !efi_guidcmp(guid, iter->var.VendorGuid)) {
+			entry = iter;
 			break;
 		}
 	}
 
-	if (!found)
+	if (!entry)
 		return NULL;
 
 	if (remove) {