Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2904d9fa authored by Bart Van Assche's avatar Bart Van Assche Committed by Ingo Molnar
Browse files

locking/lockdep: Introduce lock_class_cache_is_registered()



This patch does not change any functionality but makes the
lockdep_reset_lock() function easier to read.

Signed-off-by: default avatarBart Van Assche <bvanassche@acm.org>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Waiman Long <longman@redhat.com>
Cc: johannes.berg@intel.com
Cc: tj@kernel.org
Link: https://lkml.kernel.org/r/20181207011148.251812-11-bvanassche@acm.org


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent d35568bd
Loading
Loading
Loading
Loading
+30 −20
Original line number Diff line number Diff line
@@ -4201,13 +4201,33 @@ void lockdep_free_key_range(void *start, unsigned long size)
	 */
}

void lockdep_reset_lock(struct lockdep_map *lock)
/*
 * Check whether any element of the @lock->class_cache[] array refers to a
 * registered lock class. The caller must hold either the graph lock or the
 * RCU read lock.
 */
static bool lock_class_cache_is_registered(struct lockdep_map *lock)
{
	struct lock_class *class;
	struct hlist_head *head;
	unsigned long flags;
	int i, j;
	int locked;

	for (i = 0; i < CLASSHASH_SIZE; i++) {
		head = classhash_table + i;
		hlist_for_each_entry_rcu(class, head, hash_entry) {
			for (j = 0; j < NR_LOCKDEP_CACHING_CLASSES; j++)
				if (lock->class_cache[j] == class)
					return true;
		}
	}
	return false;
}

void lockdep_reset_lock(struct lockdep_map *lock)
{
	struct lock_class *class;
	unsigned long flags;
	int j, locked;

	raw_local_irq_save(flags);

@@ -4227,15 +4247,7 @@ void lockdep_reset_lock(struct lockdep_map *lock)
	 * be gone.
	 */
	locked = graph_lock();
	for (i = 0; i < CLASSHASH_SIZE; i++) {
		head = classhash_table + i;
		hlist_for_each_entry_rcu(class, head, hash_entry) {
			int match = 0;

			for (j = 0; j < NR_LOCKDEP_CACHING_CLASSES; j++)
				match |= class == lock->class_cache[j];

			if (unlikely(match)) {
	if (unlikely(lock_class_cache_is_registered(lock))) {
		if (debug_locks_off_graph_unlock()) {
			/*
			 * We all just reset everything, how did it match?
@@ -4244,8 +4256,6 @@ void lockdep_reset_lock(struct lockdep_map *lock)
		}
		goto out_restore;
	}
		}
	}
	if (locked)
		graph_unlock();