From: Jakob Koschel <jakobkoschel@gmail.com>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org,
Mike Rapoport <rppt@kernel.org>,
"Brian Johannesmeyer" <bjohannesmeyer@gmail.com>,
Cristiano Giuffrida <c.giuffrida@vu.nl>,
"Bos, H.J." <h.j.bos@vu.nl>,
Jakob Koschel <jakobkoschel@gmail.com>
Subject: [PATCH 1/2] efi: remove use of list iterator variable after loop
Date: Fri, 1 Apr 2022 00:10:29 +0200 [thread overview]
Message-ID: <20220331221030.889718-1-jakobkoschel@gmail.com> (raw)
In preparation to limiting the scope of a list iterator to the list
traversal loop, use a dedicated pointer to iterate through the list [1].
In the current state the list_for_each_entry() is guaranteed to
hit a break or goto in order to work properly. If the list iterator
executes completely or the list is empty the iterator variable contains
a type confused bogus value infered from the head of the list.
With this patch the variable used past the list iterator is only set
if the list exists early and is NULL otherwise. It should therefore
be safe to just set *prev = NULL (as it was before).
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 | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c
index cae590bd08f2..3994aad38661 100644
--- a/drivers/firmware/efi/vars.c
+++ b/drivers/firmware/efi/vars.c
@@ -1081,14 +1081,16 @@ int __efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
struct list_head *head, void *data,
struct efivar_entry **prev)
{
- struct efivar_entry *entry, *n;
+ struct efivar_entry *entry = NULL, *iter, *n;
int err = 0;
if (!prev || !*prev) {
- list_for_each_entry_safe(entry, n, head, list) {
- err = func(entry, data);
- if (err)
+ list_for_each_entry_safe(iter, n, head, list) {
+ err = func(iter, data);
+ if (err) {
+ entry = iter;
break;
+ }
}
if (prev)
base-commit: d888c83fcec75194a8a48ccd283953bdba7b2550
--
2.25.1
next reply other threads:[~2022-03-31 22:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-31 22:10 Jakob Koschel [this message]
2022-03-31 22:10 ` [PATCH 2/2] efi: replace usage of found with dedicated list iterator variable Jakob Koschel
2022-04-13 17:09 ` Ard Biesheuvel
2022-04-13 17:05 ` [PATCH 1/2] efi: remove use of list iterator variable after loop Ard Biesheuvel
2022-04-13 18:08 ` Jakob Koschel
2022-04-13 22:09 ` Ard Biesheuvel
2022-06-28 8:02 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220331221030.889718-1-jakobkoschel@gmail.com \
--to=jakobkoschel@gmail.com \
--cc=ardb@kernel.org \
--cc=bjohannesmeyer@gmail.com \
--cc=c.giuffrida@vu.nl \
--cc=h.j.bos@vu.nl \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®