Skip to content

Commit 33e4945

Browse files
Jakob-KoschelWim Van Sebroeck
authored andcommitted
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>
1 parent fc0c5db commit 33e4945

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

drivers/watchdog/watchdog_pretimeout.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,9 @@ void watchdog_unregister_pretimeout(struct watchdog_device *wdd)
207207
list_for_each_entry_safe(p, t, &pretimeout_list, entry) {
208208
if (p->wdd == wdd) {
209209
list_del(&p->entry);
210+
kfree(p);
210211
break;
211212
}
212213
}
213214
spin_unlock_irq(&pretimeout_lock);
214-
215-
kfree(p);
216215
}

0 commit comments

Comments
 (0)