Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 191014
b: refs/heads/master
c: a5d8e46
h: refs/heads/master
v: v3
  • Loading branch information
Mathieu Desnoyers authored and Paul E. McKenney committed May 10, 2010
1 parent 2160afb commit 96e516b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d822ed1094032ab524344a9a474c93128d9c2159
refs/heads/master: a5d8e467f83f6672104f276223a88e3b50cbd375
11 changes: 11 additions & 0 deletions trunk/include/linux/debugobjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ struct debug_obj_descr;
* struct debug_obj - representaion of an tracked object
* @node: hlist node to link the object into the tracker list
* @state: tracked object state
* @astate: current active state
* @object: pointer to the real object
* @descr: pointer to an object type specific debug description structure
*/
struct debug_obj {
struct hlist_node node;
enum debug_obj_state state;
unsigned int astate;
void *object;
struct debug_obj_descr *descr;
};
Expand Down Expand Up @@ -60,6 +62,15 @@ extern void debug_object_deactivate(void *addr, struct debug_obj_descr *descr);
extern void debug_object_destroy (void *addr, struct debug_obj_descr *descr);
extern void debug_object_free (void *addr, struct debug_obj_descr *descr);

/*
* Active state:
* - Set at 0 upon initialization.
* - Must return to 0 before deactivation.
*/
extern void
debug_object_active_state(void *addr, struct debug_obj_descr *descr,
unsigned int expect, unsigned int next);

extern void debug_objects_early_init(void);
extern void debug_objects_mem_init(void);
#else
Expand Down
59 changes: 56 additions & 3 deletions trunk/lib/debugobjects.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr)
obj->object = addr;
obj->descr = descr;
obj->state = ODEBUG_STATE_NONE;
obj->astate = 0;
hlist_del(&obj->node);

hlist_add_head(&obj->node, &b->list);
Expand Down Expand Up @@ -252,8 +253,10 @@ static void debug_print_object(struct debug_obj *obj, char *msg)

if (limit < 5 && obj->descr != descr_test) {
limit++;
WARN(1, KERN_ERR "ODEBUG: %s %s object type: %s\n", msg,
obj_states[obj->state], obj->descr->name);
WARN(1, KERN_ERR "ODEBUG: %s %s (active state %u) "
"object type: %s\n",
msg, obj_states[obj->state], obj->astate,
obj->descr->name);
}
debug_objects_warnings++;
}
Expand Down Expand Up @@ -447,7 +450,10 @@ void debug_object_deactivate(void *addr, struct debug_obj_descr *descr)
case ODEBUG_STATE_INIT:
case ODEBUG_STATE_INACTIVE:
case ODEBUG_STATE_ACTIVE:
obj->state = ODEBUG_STATE_INACTIVE;
if (!obj->astate)
obj->state = ODEBUG_STATE_INACTIVE;
else
debug_print_object(obj, "deactivate");
break;

case ODEBUG_STATE_DESTROYED:
Expand Down Expand Up @@ -553,6 +559,53 @@ void debug_object_free(void *addr, struct debug_obj_descr *descr)
raw_spin_unlock_irqrestore(&db->lock, flags);
}

/**
* debug_object_active_state - debug checks object usage state machine
* @addr: address of the object
* @descr: pointer to an object specific debug description structure
* @expect: expected state
* @next: state to move to if expected state is found
*/
void
debug_object_active_state(void *addr, struct debug_obj_descr *descr,
unsigned int expect, unsigned int next)
{
struct debug_bucket *db;
struct debug_obj *obj;
unsigned long flags;

if (!debug_objects_enabled)
return;

db = get_bucket((unsigned long) addr);

raw_spin_lock_irqsave(&db->lock, flags);

obj = lookup_object(addr, db);
if (obj) {
switch (obj->state) {
case ODEBUG_STATE_ACTIVE:
if (obj->astate == expect)
obj->astate = next;
else
debug_print_object(obj, "active_state");
break;

default:
debug_print_object(obj, "active_state");
break;
}
} else {
struct debug_obj o = { .object = addr,
.state = ODEBUG_STATE_NOTAVAILABLE,
.descr = descr };

debug_print_object(&o, "active_state");
}

raw_spin_unlock_irqrestore(&db->lock, flags);
}

#ifdef CONFIG_DEBUG_OBJECTS_FREE
static void __debug_check_no_obj_freed(const void *address, unsigned long size)
{
Expand Down

0 comments on commit 96e516b

Please sign in to comment.