# HG changeset patch # User Josef 'Jeff' Sipek # Date 1564078771 14400 # Node ID 01848cbed620ef77a27e78defbfd383ac8f364ef # Parent 8f41dc0ec42e6f3996d32286599b60764824ba65 synch: move mutex lock checking into a helper function Signed-off-by: Josef 'Jeff' Sipek diff -r 8f41dc0ec42e -r 01848cbed620 synch.c --- a/synch.c Sun Aug 11 11:49:56 2019 -0400 +++ b/synch.c Thu Jul 25 14:19:31 2019 -0400 @@ -488,6 +488,41 @@ __bad_type(info, op, where, expected_type); } +static void check_unheld_for_lock(struct lock_info *info, + const struct lock_context *where) +{ +#ifdef JEFFPC_LOCK_TRACKING + struct held_lock *held; + size_t i; + + if (!atomic_read(&lockdep_on)) + return; + + /* check for deadlocks & recursive locking */ + for_each_held_lock(i, held) { + if ((held->info != info) && (held->info->lc != info->lc)) + continue; + + error_lock(held, info, where); + return; + } + + /* check for circular dependencies */ + if (check_circular_deps(info, where)) + return; + + held = held_stack_alloc(); + if (!held) { + error_alloc(info, where, "lock nesting limit reached"); + return; + } + + held->info = info; + held->where = *where; + held->type = info->type; +#endif +} + static void verify_lock_init(const struct lock_context *where, struct lock *l, struct lock_class *lc) { @@ -536,40 +571,7 @@ print_invalid_call("MXLOCK", where); check_magic(&l->info, "acquire", where, SYNCH_TYPE_MUTEX); - -#ifdef JEFFPC_LOCK_TRACKING - struct held_lock *held; - size_t i; - - if (!atomic_read(&lockdep_on)) - return; - - /* check for deadlocks & recursive locking */ - for_each_held_lock(i, held) { - if ((held->info != &l->info) && (held->info->lc != l->info.lc)) - continue; - - if (held->info == &l->info) - sanity_check_held_synch_type(held, SYNCH_TYPE_MUTEX); - - error_lock(held, &l->info, where); - return; - } - - /* check for circular dependencies */ - if (check_circular_deps(&l->info, where)) - return; - - held = held_stack_alloc(); - if (!held) { - error_alloc(&l->info, where, "lock nesting limit reached"); - return; - } - - held->info = &l->info; - held->where = *where; - held->type = SYNCH_TYPE_MUTEX; -#endif + check_unheld_for_lock(&l->info, where); } static void verify_lock_unlock(const struct lock_context *where, struct lock *l)