2019-06-28 09:16:26

by Yuyang Du

[permalink] [raw]
Subject: [PATCH v3 02/30] locking/lockdep: Change return type of add_chain_cache()

The function add_chain_cache() adds a new chain - the current lock chain
- into the lock_chains cache if it does not exist in there.

Previously if failed to add an integer 0 is returned and if successful 1
is returned. Change the return type to the pointer of the chain if the
new chain is added or NULL if otherwise.

No functional change.

Signed-off-by: Yuyang Du <[email protected]>
---
kernel/locking/lockdep.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index e30e9e4..3546894 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -2714,12 +2714,12 @@ static struct lock_chain *alloc_lock_chain(void)
* Adds a dependency chain into chain hashtable. And must be called with
* graph_lock held.
*
- * Return 0 if fail, and graph_lock is released.
- * Return 1 if succeed, with graph_lock held.
+ * Return NULL if failed, and graph_lock is released.
+ * Return the new chain if successful, with graph_lock held.
*/
-static inline int add_chain_cache(struct task_struct *curr,
- struct held_lock *hlock,
- u64 chain_key)
+static inline struct lock_chain *add_chain_cache(struct task_struct *curr,
+ struct held_lock *hlock,
+ u64 chain_key)
{
struct lock_class *class = hlock_class(hlock);
struct hlist_head *hash_head = chainhashentry(chain_key);
@@ -2732,16 +2732,16 @@ static inline int add_chain_cache(struct task_struct *curr,
* lockdep won't complain about its own locking errors.
*/
if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
- return 0;
+ return NULL;

chain = alloc_lock_chain();
if (!chain) {
if (!debug_locks_off_graph_unlock())
- return 0;
+ return NULL;

print_lockdep_off("BUG: MAX_LOCKDEP_CHAINS too low!");
dump_stack();
- return 0;
+ return NULL;
}
chain->chain_key = chain_key;
chain->irq_context = hlock->irq_context;
@@ -2762,18 +2762,18 @@ static inline int add_chain_cache(struct task_struct *curr,
nr_chain_hlocks += chain->depth;
} else {
if (!debug_locks_off_graph_unlock())
- return 0;
+ return NULL;

print_lockdep_off("BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low!");
dump_stack();
- return 0;
+ return NULL;
}

hlist_add_head_rcu(&chain->entry, hash_head);
debug_atomic_inc(chain_lookup_misses);
inc_chains();

- return 1;
+ return chain;
}

/*
--
1.8.3.1