Skip to content

Commit

Permalink
timer: Use debugobjects to catch deletion of uninitialized timers
Browse files Browse the repository at this point in the history
del_timer_sync() calls debug_object_assert_init() to assert that
a timer has been initialized before calling lock_timer_base().
lock_timer_base() would spin forever on a NULL(uninit-ed) base.
The check is added to del_timer() to prevent silent failure, even
though it would not get stuck in an infinite loop.

[ sboyd@codeaurora.org: Remove WARN, intialize timer function]

Signed-off-by: Christine Chan <cschan@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Cc: John Stultz <john.stultz@linaro.org>
Link: http://lkml.kernel.org/r/1320724108-20788-4-git-send-email-sboyd@codeaurora.org
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Christine Chan authored and Thomas Gleixner committed Nov 23, 2011
1 parent fb16b8c commit dc4218b
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions kernel/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,40 @@ static int timer_fixup_free(void *addr, enum debug_obj_state state)
}
}

/*
* fixup_assert_init is called when:
* - an untracked/uninit-ed object is found
*/
static int timer_fixup_assert_init(void *addr, enum debug_obj_state state)
{
struct timer_list *timer = addr;

switch (state) {
case ODEBUG_STATE_NOTAVAILABLE:
if (timer->entry.prev == TIMER_ENTRY_STATIC) {
/*
* This is not really a fixup. The timer was
* statically initialized. We just make sure that it
* is tracked in the object tracker.
*/
debug_object_init(timer, &timer_debug_descr);
return 0;
} else {
setup_timer(timer, stub_timer, 0);
return 1;
}
default:
return 0;
}
}

static struct debug_obj_descr timer_debug_descr = {
.name = "timer_list",
.debug_hint = timer_debug_hint,
.fixup_init = timer_fixup_init,
.fixup_activate = timer_fixup_activate,
.fixup_free = timer_fixup_free,
.name = "timer_list",
.debug_hint = timer_debug_hint,
.fixup_init = timer_fixup_init,
.fixup_activate = timer_fixup_activate,
.fixup_free = timer_fixup_free,
.fixup_assert_init = timer_fixup_assert_init,
};

static inline void debug_timer_init(struct timer_list *timer)
Expand All @@ -515,6 +543,11 @@ static inline void debug_timer_free(struct timer_list *timer)
debug_object_free(timer, &timer_debug_descr);
}

static inline void debug_timer_assert_init(struct timer_list *timer)
{
debug_object_assert_init(timer, &timer_debug_descr);
}

static void __init_timer(struct timer_list *timer,
const char *name,
struct lock_class_key *key);
Expand All @@ -538,6 +571,7 @@ EXPORT_SYMBOL_GPL(destroy_timer_on_stack);
static inline void debug_timer_init(struct timer_list *timer) { }
static inline void debug_timer_activate(struct timer_list *timer) { }
static inline void debug_timer_deactivate(struct timer_list *timer) { }
static inline void debug_timer_assert_init(struct timer_list *timer) { }
#endif

static inline void debug_init(struct timer_list *timer)
Expand All @@ -559,6 +593,11 @@ static inline void debug_deactivate(struct timer_list *timer)
trace_timer_cancel(timer);
}

static inline void debug_assert_init(struct timer_list *timer)
{
debug_timer_assert_init(timer);
}

static void __init_timer(struct timer_list *timer,
const char *name,
struct lock_class_key *key)
Expand Down Expand Up @@ -909,6 +948,8 @@ int del_timer(struct timer_list *timer)
unsigned long flags;
int ret = 0;

debug_assert_init(timer);

timer_stats_timer_clear_start_info(timer);
if (timer_pending(timer)) {
base = lock_timer_base(timer, &flags);
Expand Down Expand Up @@ -939,6 +980,8 @@ int try_to_del_timer_sync(struct timer_list *timer)
unsigned long flags;
int ret = -1;

debug_assert_init(timer);

base = lock_timer_base(timer, &flags);

if (base->running_timer == timer)
Expand Down

0 comments on commit dc4218b

Please sign in to comment.