]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hrtimer: Add a helper to retrieve a hrtimer from its timerqueue node
authorThomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Wed, 11 Mar 2026 10:15:21 +0000 (11:15 +0100)
committerThomas Gleixner <tglx@kernel.org>
Thu, 12 Mar 2026 11:15:56 +0000 (12:15 +0100)
The container_of() call is open-coded multiple times.

Add a helper macro.

Use container_of_const() to preserve constness.

Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260311-hrtimer-cleanups-v1-12-095357392669@linutronix.de
kernel/time/hrtimer.c

index a71e2caa14027c9d252da1a7d6d86d8b9c65211e..2db171bae05ced2417595354afb9a7bc62a03781 100644 (file)
@@ -534,6 +534,8 @@ static inline void debug_activate(struct hrtimer *timer, enum hrtimer_mode mode,
                for (bool done = false; !done; active &= ~(1U << idx))                  \
                        for (base = &cpu_base->clock_base[idx]; !done; done = true)
 
+#define hrtimer_from_timerqueue_node(_n) container_of_const(_n, struct hrtimer, node)
+
 #if defined(CONFIG_NO_HZ_COMMON)
 /*
  * Same as hrtimer_bases_next_event() below, but skips the excluded timer and
@@ -578,7 +580,7 @@ static __always_inline struct hrtimer *clock_base_next_timer(struct hrtimer_cloc
 {
        struct timerqueue_linked_node *next = timerqueue_linked_first(&base->active);
 
-       return container_of(next, struct hrtimer, node);
+       return hrtimer_from_timerqueue_node(next);
 }
 
 /* Find the base with the earliest expiry */
@@ -1960,7 +1962,7 @@ static __always_inline struct hrtimer *clock_base_next_timer_safe(struct hrtimer
 {
        struct timerqueue_linked_node *next = timerqueue_linked_first(&base->active);
 
-       return next ? container_of(next, struct hrtimer, node) : NULL;
+       return next ? hrtimer_from_timerqueue_node(next) : NULL;
 }
 
 static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now,
@@ -2439,7 +2441,7 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
        struct hrtimer *timer;
 
        while ((node = timerqueue_linked_first(&old_base->active))) {
-               timer = container_of(node, struct hrtimer, node);
+               timer = hrtimer_from_timerqueue_node(node);
                BUG_ON(hrtimer_callback_running(timer));
                debug_hrtimer_deactivate(timer);