Skip to content

Commit 444cb7d

Browse files
covanamKAGA-KOKO
authored andcommitted
hrtimers: Introduce hrtimer_setup_on_stack()
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 <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/all/4b05e2ab3a82c517adf67fabc0f0cd8fe118b97c.1730386209.git.namcao@linutronix.de
1 parent 908a1d7 commit 444cb7d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/linux/hrtimer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ extern void hrtimer_setup(struct hrtimer *timer, enum hrtimer_restart (*function
232232
clockid_t clock_id, enum hrtimer_mode mode);
233233
extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock,
234234
enum hrtimer_mode mode);
235+
extern void hrtimer_setup_on_stack(struct hrtimer *timer,
236+
enum hrtimer_restart (*function)(struct hrtimer *),
237+
clockid_t clock_id, enum hrtimer_mode mode);
235238
extern void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl,
236239
clockid_t clock_id,
237240
enum hrtimer_mode mode);

kernel/time/hrtimer.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,25 @@ void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t clock_id,
16461646
}
16471647
EXPORT_SYMBOL_GPL(hrtimer_init_on_stack);
16481648

1649+
/**
1650+
* hrtimer_setup_on_stack - initialize a timer on stack memory
1651+
* @timer: The timer to be initialized
1652+
* @function: the callback function
1653+
* @clock_id: The clock to be used
1654+
* @mode: The timer mode
1655+
*
1656+
* Similar to hrtimer_setup(), except that this one must be used if struct hrtimer is in stack
1657+
* memory.
1658+
*/
1659+
void hrtimer_setup_on_stack(struct hrtimer *timer,
1660+
enum hrtimer_restart (*function)(struct hrtimer *),
1661+
clockid_t clock_id, enum hrtimer_mode mode)
1662+
{
1663+
debug_init_on_stack(timer, clock_id, mode);
1664+
__hrtimer_setup(timer, function, clock_id, mode);
1665+
}
1666+
EXPORT_SYMBOL_GPL(hrtimer_setup_on_stack);
1667+
16491668
/*
16501669
* A timer is active, when it is enqueued into the rbtree or the
16511670
* callback function is running or it's in the state of being migrated

0 commit comments

Comments
 (0)