Skip to contentSkip to conversation

PM: Delete timer before removing wakeup source from list

PATCH Superseded Kaushlendra Kumar 3 participants 5 messages Sep 24, 2025 – Oct 21, 2025

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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
index d1283ff1080b..ae6ec9f04b61 100644
@@ -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
#1 lore raw
Quoted 5 lines · Kaushlendra Kumar

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.

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.

---
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
index d1283ff1080b..ae6ec9f04b61 100644
@@ -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
#2 lore raw
Quoted 44 lines · Dhruva Gole
Quoted 5 lines · Kaushlendra Kumar

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.

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.

---
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
index d1283ff1080b..ae6ec9f04b61 100644
@@ -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?

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

#3 lore raw
In reply to Kaushlendra Kumar
Quoted 23 lines · Kaushlendra Kumar

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 +0 -0
index d1283ff1080b..ae6ec9f04b61 100644

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 -3
        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.
--

2.34.1

#4 lore raw
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