diff options
author | Jakob Koschel <[email protected]> | 2023-03-13 14:59:19 +0100 |
---|---|---|
committer | Wim Van Sebroeck <[email protected]> | 2023-04-22 12:54:00 +0200 |
commit | 33e4945352a2484c92fc1d5a16471b1939d67abb (patch) | |
tree | 13d5e58d384308116218010992a9037dc0302d45 | |
parent | fc0c5db58f4c78b948acfbf9558eeaf6b343bf9a (diff) |
watchdog: avoid usage of iterator after loop
If potentially no valid element is found, 'p' would contain an invalid
pointer past the iterator loop. To ensure 'p' is valid under any
circumstances, the kfree() should be within the loop body.
Additionally, Linus proposed to avoid any use of the list iterator
variable after the loop, in the attempt to move the list iterator
variable declaration into the macro to avoid any potential misuse after
the loop [1].
Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1]
Signed-off-by: Jakob Koschel <[email protected]>
Reviewed-by: Guenter Roeck <[email protected]>
Link: https://lore.kernel.org/r/20230301-watchdog-avoid-iter-after-loop-v2-1-8411e3bbe0de@gmail.com
Signed-off-by: Guenter Roeck <[email protected]>
Signed-off-by: Wim Van Sebroeck <[email protected]>
-rw-r--r-- | drivers/watchdog/watchdog_pretimeout.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/drivers/watchdog/watchdog_pretimeout.c b/drivers/watchdog/watchdog_pretimeout.c index 376a495ab80c..e5295c990fa1 100644 --- a/drivers/watchdog/watchdog_pretimeout.c +++ b/drivers/watchdog/watchdog_pretimeout.c @@ -207,10 +207,9 @@ void watchdog_unregister_pretimeout(struct watchdog_device *wdd) list_for_each_entry_safe(p, t, &pretimeout_list, entry) { if (p->wdd == wdd) { list_del(&p->entry); + kfree(p); break; } } spin_unlock_irq(&pretimeout_lock); - - kfree(p); } |