Skip to contentSkip to conversation

timers: Check timer_pending() before reading bucket index

PATCH In review Liang Hao 2 participants 3 messages Aug 28 – Sep 6 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore

Liang Hao

author
#0 lore raw

PATCH 1/1 timers: Check timer_pending() before reading bucket index

Only read the cached wheel index when the timer is still queued. No functional change.

---
 kernel/time/timer.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/time/timer.c +3 -1
index ae9abf14688e..9f3b199d3075 100644
@@ -897,11 +897,13 @@ static inline void detach_timer(struct timer_list *timer, bool clear_pending)
 static int detach_if_pending(struct timer_list *timer, struct timer_base *base,
 			     bool clear_pending)
 {
-	unsigned idx = timer_get_idx(timer);
+	unsigned int idx;
 
 	if (!timer_pending(timer))
 		return 0;
 
+	idx = timer_get_idx(timer);
+
 	if (hlist_is_singular_node(&timer->entry, base->vectors + idx)) {
 		__clear_bit(idx, base->pending_map);
 		base->next_expiry_recalc = true;
Signature · 1 line
2.50.1 (Apple Git-155)
maintainer
#1 lore raw
Quoted 2 lines · Liang Hao

Only read the cached wheel index when the timer is still queued. No functional change.

Which problem is actually solved by this?

author
#2 lore raw
Quoted 1 line · Thomas Gleixner

Which problem is actually solved by this?

None that shows up as a bug. The index is never used when the timer is not queued; I only reordered the checks. I'll drop it.

Thanks,
Liang Hao