Skip to content

Commit b84d435

Browse files
Christine ChanKAGA-KOKO
authored andcommitted
debugobjects: Extend to assert that an object is initialized
Calling del_timer_sync() on an uninitialized timer leads to a never ending loop in lock_timer_base() that spins checking for a non-NULL timer base. Add an assertion to debugobjects to catch usage of uninitialized objects so that we can initialize timers in the del_timer_sync() path before it calls lock_timer_base(). [ sboyd@codeaurora.org: Clarify commit message ] 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-3-git-send-email-sboyd@codeaurora.org Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent feac18d commit b84d435

3 files changed

Lines changed: 94 additions & 0 deletions

File tree

‎Documentation/DocBook/debugobjects.tmpl‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<listitem><para>debug_object_deactivate</para></listitem>
9797
<listitem><para>debug_object_destroy</para></listitem>
9898
<listitem><para>debug_object_free</para></listitem>
99+
<listitem><para>debug_object_assert_init</para></listitem>
99100
</itemizedlist>
100101
Each of these functions takes the address of the real object and
101102
a pointer to the object type specific debug description
@@ -273,6 +274,26 @@
273274
debug checks.
274275
</para>
275276
</sect1>
277+
278+
<sect1 id="debug_object_assert_init">
279+
<title>debug_object_assert_init</title>
280+
<para>
281+
This function is called to assert that an object has been
282+
initialized.
283+
</para>
284+
<para>
285+
When the real object is not tracked by debugobjects, it calls
286+
fixup_assert_init of the object type description structure
287+
provided by the caller, with the hardcoded object state
288+
ODEBUG_NOT_AVAILABLE. The fixup function can correct the problem
289+
by calling debug_object_init and other specific initializing
290+
functions.
291+
</para>
292+
<para>
293+
When the real object is already tracked by debugobjects it is
294+
ignored.
295+
</para>
296+
</sect1>
276297
</chapter>
277298
<chapter id="fixupfunctions">
278299
<title>Fixup functions</title>
@@ -381,6 +402,35 @@
381402
statistics.
382403
</para>
383404
</sect1>
405+
<sect1 id="fixup_assert_init">
406+
<title>fixup_assert_init</title>
407+
<para>
408+
This function is called from the debug code whenever a problem
409+
in debug_object_assert_init is detected.
410+
</para>
411+
<para>
412+
Called from debug_object_assert_init() with a hardcoded state
413+
ODEBUG_STATE_NOTAVAILABLE when the object is not found in the
414+
debug bucket.
415+
</para>
416+
<para>
417+
The function returns 1 when the fixup was successful,
418+
otherwise 0. The return value is used to update the
419+
statistics.
420+
</para>
421+
<para>
422+
Note, this function should make sure debug_object_init() is
423+
called before returning.
424+
</para>
425+
<para>
426+
The handling of statically initialized objects is a special
427+
case. The fixup function should check if this is a legitimate
428+
case of a statically initialized object or not. In this case only
429+
debug_object_init() should be called to make the object known to
430+
the tracker. Then the function should return 0 because this is not
431+
a real fixup.
432+
</para>
433+
</sect1>
384434
</chapter>
385435
<chapter id="bugs">
386436
<title>Known Bugs And Assumptions</title>

‎include/linux/debugobjects.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct debug_obj {
4646
* fails
4747
* @fixup_free: fixup function, which is called when the free check
4848
* fails
49+
* @fixup_assert_init: fixup function, which is called when the assert_init
50+
* check fails
4951
*/
5052
struct debug_obj_descr {
5153
const char *name;
@@ -54,6 +56,7 @@ struct debug_obj_descr {
5456
int (*fixup_activate) (void *addr, enum debug_obj_state state);
5557
int (*fixup_destroy) (void *addr, enum debug_obj_state state);
5658
int (*fixup_free) (void *addr, enum debug_obj_state state);
59+
int (*fixup_assert_init)(void *addr, enum debug_obj_state state);
5760
};
5861

5962
#ifdef CONFIG_DEBUG_OBJECTS
@@ -64,6 +67,7 @@ extern void debug_object_activate (void *addr, struct debug_obj_descr *descr);
6467
extern void debug_object_deactivate(void *addr, struct debug_obj_descr *descr);
6568
extern void debug_object_destroy (void *addr, struct debug_obj_descr *descr);
6669
extern void debug_object_free (void *addr, struct debug_obj_descr *descr);
70+
extern void debug_object_assert_init(void *addr, struct debug_obj_descr *descr);
6771

6872
/*
6973
* Active state:
@@ -89,6 +93,8 @@ static inline void
8993
debug_object_destroy (void *addr, struct debug_obj_descr *descr) { }
9094
static inline void
9195
debug_object_free (void *addr, struct debug_obj_descr *descr) { }
96+
static inline void
97+
debug_object_assert_init(void *addr, struct debug_obj_descr *descr) { }
9298

9399
static inline void debug_objects_early_init(void) { }
94100
static inline void debug_objects_mem_init(void) { }

‎lib/debugobjects.c‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,44 @@ void debug_object_free(void *addr, struct debug_obj_descr *descr)
570570
raw_spin_unlock_irqrestore(&db->lock, flags);
571571
}
572572

573+
/**
574+
* debug_object_assert_init - debug checks when object should be init-ed
575+
* @addr: address of the object
576+
* @descr: pointer to an object specific debug description structure
577+
*/
578+
void debug_object_assert_init(void *addr, struct debug_obj_descr *descr)
579+
{
580+
struct debug_bucket *db;
581+
struct debug_obj *obj;
582+
unsigned long flags;
583+
584+
if (!debug_objects_enabled)
585+
return;
586+
587+
db = get_bucket((unsigned long) addr);
588+
589+
raw_spin_lock_irqsave(&db->lock, flags);
590+
591+
obj = lookup_object(addr, db);
592+
if (!obj) {
593+
struct debug_obj o = { .object = addr,
594+
.state = ODEBUG_STATE_NOTAVAILABLE,
595+
.descr = descr };
596+
597+
raw_spin_unlock_irqrestore(&db->lock, flags);
598+
/*
599+
* Maybe the object is static. Let the type specific
600+
* code decide what to do.
601+
*/
602+
if (debug_object_fixup(descr->fixup_assert_init, addr,
603+
ODEBUG_STATE_NOTAVAILABLE))
604+
debug_print_object(&o, "assert_init");
605+
return;
606+
}
607+
608+
raw_spin_unlock_irqrestore(&db->lock, flags);
609+
}
610+
573611
/**
574612
* debug_object_active_state - debug checks object usage state machine
575613
* @addr: address of the object

0 commit comments

Comments
 (0)