From: Xiongwei Song <sxwjean@me.com>
To: peterz@infradead.org, mingo@redhat.com, will@kernel.org,
longman@redhat.com, boqun.feng@gmail.com
Cc: linux-kernel@vger.kernel.org, Xiongwei Song <sxwjean@gmail.com>
Subject: [PATCH v2] locking/lockdep: Reorganize the return values of check_wait_context()
Date: Mon, 12 Jul 2021 22:59:13 +0800 [thread overview]
Message-ID: <20210712145913.189202-1-sxwjean@me.com> (raw)
From: Xiongwei Song <sxwjean@gmail.com>
Some check_*() functions for lock rules check return 1 if there is no bug,
otherwise return 0 like check_prev_add(), check_irq_usage(), etc. Here we
can reorganize the return values of check_wait_context() to make the
return logic same as other check_*() functions.
The return values of print_lock_invalid_wait_context() are unnecessary,
remove them.
Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
---
v2:
- Improve commit log.
- Keep return value sync for check_wait_context in !CONFIG_PROVE_LOCKING.
- Add statement for return vaules.
v1:
- https://lkml.org/lkml/2021/7/11/174
---
kernel/locking/lockdep.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index bf1c00c881e4..69e524def98b 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -4635,16 +4635,16 @@ static inline short task_wait_context(struct task_struct *curr)
return LD_WAIT_MAX;
}
-static int
+static void
print_lock_invalid_wait_context(struct task_struct *curr,
struct held_lock *hlock)
{
short curr_inner;
if (!debug_locks_off())
- return 0;
+ return;
if (debug_locks_silent)
- return 0;
+ return;
pr_warn("\n");
pr_warn("=============================\n");
@@ -4664,8 +4664,6 @@ print_lock_invalid_wait_context(struct task_struct *curr,
pr_warn("stack backtrace:\n");
dump_stack();
-
- return 0;
}
/*
@@ -4682,6 +4680,8 @@ print_lock_invalid_wait_context(struct task_struct *curr,
*
* Therefore we must look for the strictest environment in the lock stack and
* compare that to the lock we're trying to acquire.
+ *
+ * Return 1 if no nesting confilct, otherwise return 0.
*/
static int check_wait_context(struct task_struct *curr, struct held_lock *next)
{
@@ -4691,7 +4691,7 @@ static int check_wait_context(struct task_struct *curr, struct held_lock *next)
int depth;
if (!next_inner || next->trylock)
- return 0;
+ return 1;
if (!next_outer)
next_outer = next_inner;
@@ -4723,10 +4723,12 @@ static int check_wait_context(struct task_struct *curr, struct held_lock *next)
}
}
- if (next_outer > curr_inner)
- return print_lock_invalid_wait_context(curr, next);
+ if (next_outer > curr_inner) {
+ print_lock_invalid_wait_context(curr, next);
+ return 0;
+ }
- return 0;
+ return 1;
}
#else /* CONFIG_PROVE_LOCKING */
@@ -4751,7 +4753,7 @@ static inline int separate_irq_context(struct task_struct *curr,
static inline int check_wait_context(struct task_struct *curr,
struct held_lock *next)
{
- return 0;
+ return 1;
}
#endif /* CONFIG_PROVE_LOCKING */
@@ -4962,7 +4964,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
#endif
hlock->pin_count = pin_count;
- if (check_wait_context(curr, hlock))
+ if (!check_wait_context(curr, hlock))
return 0;
/* Initialize the lock usage bit */
--
2.30.2
reply other threads:[~2021-07-12 14:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210712145913.189202-1-sxwjean@me.com \
--to=sxwjean@me.com \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=sxwjean@gmail.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).