[PATCH] lock/lockdep: Add missing graph_unlock in validate_chain

From: Xuewen Yan
Date: Thu Jan 04 2024 - 00:41:34 EST


The lookup_chain_cache_add will get graph_lock, but the
validate_chain do not unlock before return 0.

So add graph_unlock before return 0.

Signed-off-by: Xuewen Yan <xuewen.yan@xxxxxxxxxx>
Signed-off-by: Zhiguo Niu <zhiguo.niu@xxxxxxxxxx>
---
kernel/locking/lockdep.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 151bd3de5936..24995e1ebc62 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -3855,8 +3855,11 @@ static int validate_chain(struct task_struct *curr,
*/
int ret = check_deadlock(curr, hlock);

- if (!ret)
+ if (!ret) {
+ graph_unlock();
return 0;
+ }
+
/*
* Add dependency only if this lock is not the head
* of the chain, and if the new lock introduces no more
@@ -3865,9 +3868,9 @@ static int validate_chain(struct task_struct *curr,
* serializes nesting locks), see the comments for
* check_deadlock().
*/
- if (!chain_head && ret != 2) {
- if (!check_prevs_add(curr, hlock))
- return 0;
+ if (!chain_head && ret != 2 && !check_prevs_add(curr, hlock)) {
+ graph_unlock();
+ return 0;
}

graph_unlock();
--
2.25.1