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 <[email protected]>
---
 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);
 
-- 
2.52.0.457.g6b5491de43-goog


Reply via email to