Re: [PATCH bpf-next v3 1/3] PM: wakeup: Handle empty list in wakeup_sources_walk
From: Rafael J. Wysocki
Date: Tue Jan 27 2026 - 11:17:56 EST
On Sat, Jan 24, 2026 at 2:22 AM Samuel Wu <wusamuel@xxxxxxxxxx> wrote:
>
> In the case of an empty wakeup_sources list, wakeup_sources_walk_start()
> will return an invalid but non-NULL address. This also affects wrappers
> of the aforementioned function, like for_each_wakeup_source().
>
> This patch updates wakeup_sources_walk_start() to return NULL in case of
> an empty list.
>
> Signed-off-by: Samuel Wu <wusamuel@xxxxxxxxxx>
> ---
> drivers/base/power/wakeup.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
> index 1e1a0e7eeac5..e69033d16fba 100644
> --- a/drivers/base/power/wakeup.c
> +++ b/drivers/base/power/wakeup.c
> @@ -275,9 +275,7 @@ EXPORT_SYMBOL_GPL(wakeup_sources_read_unlock);
> */
> struct wakeup_source *wakeup_sources_walk_start(void)
> {
> - struct list_head *ws_head = &wakeup_sources;
> -
> - return list_entry_rcu(ws_head->next, struct wakeup_source, entry);
> + return list_first_or_null_rcu(&wakeup_sources, struct wakeup_source, entry);
> }
> EXPORT_SYMBOL_GPL(wakeup_sources_walk_start);
>
> --
This looks like a fix for the for_each_wakeup_source() users.
I can apply it without the next two patches.