]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hrtimers: Introduce hrtimer_setup_on_stack()
authorNam Cao <namcao@linutronix.de>
Thu, 31 Oct 2024 15:14:21 +0000 (16:14 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Thu, 7 Nov 2024 01:47:05 +0000 (02:47 +0100)
To initialize hrtimer on stack, hrtimer_init_on_stack() needs to be called
and also hrtimer::function must be set. This is error-prone and awkward to
use.

Introduce hrtimer_setup_on_stack() which does both of these things, so that
users of hrtimer can be simplified.

The new setup function also has a sanity check for the provided function
pointer. If NULL, a warning is emitted and a dummy callback installed.

hrtimer_init_on_stack() will be removed as soon as all of its users have
been converted to the new function.

Signed-off-by: Nam Cao <namcao@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/4b05e2ab3a82c517adf67fabc0f0cd8fe118b97c.1730386209.git.namcao@linutronix.de
include/linux/hrtimer.h
kernel/time/hrtimer.c

index bcc0715c59a84165402480d02454716f5ea68f42..2da513f8d66acc628ac420c93dae2cbed5680a27 100644 (file)
@@ -232,6 +232,9 @@ extern void hrtimer_setup(struct hrtimer *timer, enum hrtimer_restart (*function
                          clockid_t clock_id, enum hrtimer_mode mode);
 extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock,
                                  enum hrtimer_mode mode);
+extern void hrtimer_setup_on_stack(struct hrtimer *timer,
+                                  enum hrtimer_restart (*function)(struct hrtimer *),
+                                  clockid_t clock_id, enum hrtimer_mode mode);
 extern void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl,
                                          clockid_t clock_id,
                                          enum hrtimer_mode mode);
index a5ef67edcda92f5a810ba20020d032f985cda88f..daee4e27f839509236c35b867ddd979733d1170d 100644 (file)
@@ -1646,6 +1646,25 @@ void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t clock_id,
 }
 EXPORT_SYMBOL_GPL(hrtimer_init_on_stack);
 
+/**
+ * hrtimer_setup_on_stack - initialize a timer on stack memory
+ * @timer:     The timer to be initialized
+ * @function:  the callback function
+ * @clock_id:  The clock to be used
+ * @mode:       The timer mode
+ *
+ * Similar to hrtimer_setup(), except that this one must be used if struct hrtimer is in stack
+ * memory.
+ */
+void hrtimer_setup_on_stack(struct hrtimer *timer,
+                           enum hrtimer_restart (*function)(struct hrtimer *),
+                           clockid_t clock_id, enum hrtimer_mode mode)
+{
+       debug_init_on_stack(timer, clock_id, mode);
+       __hrtimer_setup(timer, function, clock_id, mode);
+}
+EXPORT_SYMBOL_GPL(hrtimer_setup_on_stack);
+
 /*
  * A timer is active, when it is enqueued into the rbtree or the
  * callback function is running or it's in the state of being migrated