PM: Delete timer before removing wakeup source from list
Subsystems (4)
PATCH v2 1/1 PM: Delete timer before removing wakeup source from list
Move timer_delete_sync() before list_del_rcu() in wakeup_source_remove() to improve the cleanup ordering and code clarity. This change ensures that the timer is stopped before removing the wakeup source from the events list, providing a more logical cleanup sequence.
While the current ordering is functionally correct, stopping the timer first makes the cleanup flow more intuitive and follows the general pattern of disabling active components before removing data structures.
---
Changes in v2:
- Reframed as cleanup/improvement rather than fix
drivers/base/power/wakeup.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/base/power/wakeup.c +1 -2
@@ -189,12 +189,11 @@ static void wakeup_source_remove(struct wakeup_source *ws)if (WARN_ON (!ws))return ; +timer_delete_sync (&ws->timer);raw_spin_lock_irqsave (&events_lock, flags);list_del_rcu (&ws->entry);raw_spin_unlock_irqrestore (&events_lock, flags);synchronize_srcu (&wakeup_srcu); - -timer_delete_sync (&ws->timer);/* * Clear timer.function to make wakeup_source_not_registered() treat * this wakeup source as not registered.
Signature · 1 line
2.34.1
Quoted 5 lines · Kaushlendra Kumar
Move
timer_delete_sync()beforelist_del_rcu()inwakeup_source_remove()to improve the cleanup ordering and code clarity. This change ensures that the timer is stopped before removing the wakeup source from the events list, providing a more logical cleanup sequence.
Quoted 8 lines
While the current ordering is functionally correct, stopping the timer first makes the cleanup flow more intuitive and follows the general pattern of disabling active components before removing data structures.
Signed-off-by Kaushlendra Kumar <[email protected]>---
Changes in v2:
- Reframed as cleanup/improvement rather than fix
Nit: See the git log and fix $subject to be PM: wakeup ...
Quoted 12 lines
drivers/base/power/wakeup.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/base/power/wakeup.c +0
-0@@ -189,12 +189,11 @@ static void wakeup_source_remove(struct wakeup_source *ws)if (WARN_ON (!ws))return ;
drivers/base/power/wakeup.c static void wakeup_source_remove(struct wakeup_source *ws) · line 199
Quoted 10 lines
drivers/base/power/wakeup.c +1
-2+timer_delete_sync (&ws->timer);raw_spin_lock_irqsave (&events_lock, flags);list_del_rcu (&ws->entry);raw_spin_unlock_irqrestore (&events_lock, flags);synchronize_srcu (&wakeup_srcu); - -timer_delete_sync (&ws->timer);/* * Clear timer.function to make wakeup_source_not_registered() treat * this wakeup source as not registered.
Also, since we're doing cleanup, can you check if using timer_shutdown_sync makes more sense and then we can remove ws->timer.function = NULL; line after this because that's what the kernel doc for timer_shutdown_sync says it does?
Signature · 3 lines
Best regards, Dhruva Gole Texas Instruments Incorporated
Quoted 44 lines · Dhruva Gole
Quoted 5 lines · Kaushlendra Kumar
Move
timer_delete_sync()beforelist_del_rcu()inwakeup_source_remove()to improve the cleanup ordering and code clarity. This change ensures that the timer is stopped before removing the wakeup source from the events list, providing a more logical cleanup sequence.Quoted 8 lines
While the current ordering is functionally correct, stopping the timer first makes the cleanup flow more intuitive and follows the general pattern of disabling active components before removing data structures.
Signed-off-by Kaushlendra Kumar <[email protected]>---
Changes in v2:
- Reframed as cleanup/improvement rather than fixNit: See the git log and fix $subject to be PM: wakeup ...
Quoted 12 lines
drivers/base/power/wakeup.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/base/power/wakeup.c +0
-0@@ -189,12 +189,11 @@ static void wakeup_source_remove(struct wakeup_source *ws)if (WARN_ON (!ws))return ;drivers/base/power/wakeup.c static void wakeup_source_remove(struct wakeup_source *ws) · line 199
Quoted 10 lines
drivers/base/power/wakeup.c +1
-2+timer_delete_sync (&ws->timer);raw_spin_lock_irqsave (&events_lock, flags);list_del_rcu (&ws->entry);raw_spin_unlock_irqrestore (&events_lock, flags);synchronize_srcu (&wakeup_srcu); - -timer_delete_sync (&ws->timer);/* * Clear timer.function to make wakeup_source_not_registered() treat * this wakeup source as not registered. Also, since we're doing cleanup, can you check if using
timer_shutdown_syncmakes more sense and then we can removews->timer.function= NULL; line after this because that's what the
kernel doc fortimer_shutdown_syncsays it does?
Quoted 4 lines
--
Best regards,
Dhruva Gole
Texas Instruments Incorporated
Hi Dhruva,
Thank you for the feedback!
Let me look into this timer_shutdown_sync() approach and will come up with a separate patch if needed.
Thank you for the thorough review and the improvement suggestions!
Best regards,
Kaushlendra
Rafael J. Wysocki
maintainerQuoted 23 lines · Kaushlendra Kumar
Move
timer_delete_sync()beforelist_del_rcu()inwakeup_source_remove()to improve the cleanup ordering and code clarity. This change ensures that the timer is stopped before removing the wakeup source from the events list, providing a more logical cleanup sequence.While the current ordering is functionally correct, stopping the timer first makes the cleanup flow more intuitive and follows the general pattern of disabling active components before removing data structures.
Signed-off-by Kaushlendra Kumar <[email protected]>---
Changes in v2:
- Reframed as cleanup/improvement rather than fixdrivers/base/power/wakeup.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/base/power/wakeup.c +0
-0
drivers/base/power/wakeup.c static void wakeup_source_remove(struct wakeup_source *ws) · line 192
Quoted 4 lines
drivers/base/power/wakeup.c +1
-0@@ -189,12 +189,11 @@ static void wakeup_source_remove(struct wakeup_source *ws)if (WARN_ON (!ws))return ; +timer_delete_sync (&ws->timer);
Doesn't this need to be timer_shutdown_sync()?
The current code guarantees that the timer will not be re-armed after deletion, but the new code doesn't guarantee that AFAICS.
Quoted 12 lines
drivers/base/power/wakeup.c +0
-3raw_spin_lock_irqsave (&events_lock, flags);list_del_rcu (&ws->entry);raw_spin_unlock_irqrestore (&events_lock, flags);synchronize_srcu (&wakeup_srcu); - -timer_delete_sync (&ws->timer);/* * Clear timer.function to make wakeup_source_not_registered() treat * this wakeup source as not registered. -- 2.34.1
Quoted 3 lines
Doesn't this need to be
timer_shutdown_sync()?The current code guarantees that the timer will not be re-armed after deletion, but the new code doesn't guarantee that AFAICS.
timer_shutdown_sync() would be the more appropriate here. Will create a v3 patch for the same.
Thanks for the feedback!
BR,
Kaushlendra