Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <jkl820.git@gmail.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20230301-watchdog-avoid-iter-after-loop-v2-1-8411e3bbe0de@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>

authored by

Jakob Koschel and committed by
Wim Van Sebroeck
33e49453 fc0c5db5

+1 -2
+1 -2
drivers/watchdog/watchdog_pretimeout.c
··· 207 207 list_for_each_entry_safe(p, t, &pretimeout_list, entry) { 208 208 if (p->wdd == wdd) { 209 209 list_del(&p->entry); 210 + kfree(p); 210 211 break; 211 212 } 212 213 } 213 214 spin_unlock_irq(&pretimeout_lock); 214 - 215 - kfree(p); 216 215 }