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) 
<[email protected]>
---
 kernel/time/hrtimer.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index d350bceb3c95..94955f967207 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -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,
@@ -2438,7 +2440,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);
 

-- 
2.53.0


Reply via email to