mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] devres: add managed timer shutdown helper
@ 2026-11-04 23:03 Kirtikumar Anandrao Ramchandani
  2026-11-04 23:23 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Kirtikumar Anandrao Ramchandani @ 2026-11-04 23:03 UTC (permalink / raw)
  To: Hans de Goede, Guenter Roeck; +Cc: Matti Vaittinen, linux-hwmon, linux-kernel

Provide a devres action for initialized timers. The action calls
timer_shutdown_sync(), draining the callback and rejecting later rearming
before device-managed storage is released.

Use devm_add_action_or_reset() so a failed action registration shuts the
timer down immediately.

Signed-off-by: Kirtikumar Anandrao Ramchandani <kirtiar15502@gmail.com>
---
 include/linux/devm-helpers.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/include/linux/devm-helpers.h b/include/linux/devm-helpers.h
index 708ca9131..ffe8b68b7 100644
--- a/include/linux/devm-helpers.h
+++ b/include/linux/devm-helpers.h
@@ -24,8 +24,33 @@
  */

 #include <linux/device.h>
+#include <linux/timer.h>
 #include <linux/workqueue.h>

+static inline void devm_timer_shutdown(void *res)
+{
+	timer_shutdown_sync(res);
+}
+
+/**
+ * devm_timer_autoshutdown - Shut down an initialized timer on resource release
+ * @dev: Device whose lifetime the timer is bound to
+ * @timer: Initialized timer to shut down
+ *
+ * Register a timer_shutdown_sync() action. Register this action before
+ * arming the timer, and after resources that its callback may access.
+ * The timer is shut down immediately if action registration fails.
+ *
+ * The callback's resources must remain live until shutdown completes. Any
+ * independent user of the timer must stop before the timer's storage is
+ * released. Devres actions run in reverse registration order.
+ */
+static inline int devm_timer_autoshutdown(struct device *dev,
+					  struct timer_list *timer)
+{
+	return devm_add_action_or_reset(dev, devm_timer_shutdown, timer);
+}
+
 static inline void devm_delayed_work_drop(void *res)
 {
 	cancel_delayed_work_sync(res);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/2] devres: add managed timer shutdown helper
  2026-11-04 23:03 [PATCH 1/2] devres: add managed timer shutdown helper Kirtikumar Anandrao Ramchandani
@ 2026-11-04 23:23 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2026-11-04 23:23 UTC (permalink / raw)
  To: Kirtikumar Anandrao Ramchandani, Hans de Goede
  Cc: Matti Vaittinen, linux-hwmon, linux-kernel

On 11/4/26 15:03, Kirtikumar Anandrao Ramchandani wrote:
> Provide a devres action for initialized timers. The action calls
> timer_shutdown_sync(), draining the callback and rejecting later rearming
> before device-managed storage is released.
> 
> Use devm_add_action_or_reset() so a failed action registration shuts the
> timer down immediately.
> 
> Signed-off-by: Kirtikumar Anandrao Ramchandani <kirtiar15502@gmail.com>

I see no benefit in this patch. The calling code now calls
devm_timer_autoshutdown() instead of devm_add_action_or_reset().
That does not really make a difference. Sure, we could add similar
code for every instance of devm_add_action_or_reset() in the kernel,
but what would be the point ?

Guenter

> ---
>   include/linux/devm-helpers.h | 25 +++++++++++++++++++++++++
>   1 file changed, 25 insertions(+)
> 
> diff --git a/include/linux/devm-helpers.h b/include/linux/devm-helpers.h
> index 708ca9131..ffe8b68b7 100644
> --- a/include/linux/devm-helpers.h
> +++ b/include/linux/devm-helpers.h
> @@ -24,8 +24,33 @@
>    */
> 
>   #include <linux/device.h>
> +#include <linux/timer.h>
>   #include <linux/workqueue.h>
> 
> +static inline void devm_timer_shutdown(void *res)
> +{
> +	timer_shutdown_sync(res);
> +}
> +
> +/**
> + * devm_timer_autoshutdown - Shut down an initialized timer on resource release
> + * @dev: Device whose lifetime the timer is bound to
> + * @timer: Initialized timer to shut down
> + *
> + * Register a timer_shutdown_sync() action. Register this action before
> + * arming the timer, and after resources that its callback may access.
> + * The timer is shut down immediately if action registration fails.
> + *
> + * The callback's resources must remain live until shutdown completes. Any
> + * independent user of the timer must stop before the timer's storage is
> + * released. Devres actions run in reverse registration order.
> + */
> +static inline int devm_timer_autoshutdown(struct device *dev,
> +					  struct timer_list *timer)
> +{
> +	return devm_add_action_or_reset(dev, devm_timer_shutdown, timer);
> +}
> +
>   static inline void devm_delayed_work_drop(void *res)
>   {
>   	cancel_delayed_work_sync(res);


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-04 23:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04 23:03 [PATCH 1/2] devres: add managed timer shutdown helper Kirtikumar Anandrao Ramchandani
2026-11-04 23:23 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®