linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] locking/ww-mutex: Fix uninitialized use of ret in test_aa()
@ 2021-09-22 14:58 Nathan Chancellor
  2021-09-22 15:52 ` Waiman Long
  2021-10-01 15:05 ` [tip: locking/core] " tip-bot2 for Nathan Chancellor
  0 siblings, 2 replies; 3+ messages in thread
From: Nathan Chancellor @ 2021-09-22 14:58 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Will Deacon
  Cc: Waiman Long, Boqun Feng, Nick Desaulniers, Maarten Lankhorst,
	linux-kernel, llvm, Nathan Chancellor, kernelci.org bot,
	Stephen Rothwell

Clang warns:

kernel/locking/test-ww_mutex.c:138:7: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                if (!ww_mutex_trylock(&mutex, &ctx)) {
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/locking/test-ww_mutex.c:172:9: note: uninitialized use occurs here
        return ret;
               ^~~
kernel/locking/test-ww_mutex.c:138:3: note: remove the 'if' if its condition is always false
                if (!ww_mutex_trylock(&mutex, &ctx)) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/locking/test-ww_mutex.c:125:9: note: initialize the variable 'ret' to silence this warning
        int ret;
               ^
                = 0
1 error generated.

Assign !ww_mutex_trylock(...) to ret so that it is always initialized.

Fixes: 12235da8c80a ("kernel/locking: Add context to ww_mutex_trylock()")
Link: https://github.com/ClangBuiltLinux/linux/issues/1463
Reported-by: "kernelci.org bot" <bot@kernelci.org>
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 kernel/locking/test-ww_mutex.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c
index d63ac411f367..353004155d65 100644
--- a/kernel/locking/test-ww_mutex.c
+++ b/kernel/locking/test-ww_mutex.c
@@ -135,7 +135,8 @@ static int test_aa(bool trylock)
 			goto out;
 		}
 	} else {
-		if (!ww_mutex_trylock(&mutex, &ctx)) {
+		ret = !ww_mutex_trylock(&mutex, &ctx);
+		if (ret) {
 			pr_err("%s: initial trylock failed!\n", __func__);
 			goto out;
 		}

base-commit: 12235da8c80a1f9909008e4ca6036d5772b81192
-- 
2.33.0.514.g99c99ed825


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] locking/ww-mutex: Fix uninitialized use of ret in test_aa()
  2021-09-22 14:58 [PATCH] locking/ww-mutex: Fix uninitialized use of ret in test_aa() Nathan Chancellor
@ 2021-09-22 15:52 ` Waiman Long
  2021-10-01 15:05 ` [tip: locking/core] " tip-bot2 for Nathan Chancellor
  1 sibling, 0 replies; 3+ messages in thread
From: Waiman Long @ 2021-09-22 15:52 UTC (permalink / raw)
  To: Nathan Chancellor, Peter Zijlstra, Ingo Molnar, Will Deacon
  Cc: Boqun Feng, Nick Desaulniers, Maarten Lankhorst, linux-kernel,
	llvm, kernelci.org bot, Stephen Rothwell

On 9/22/21 10:58 AM, Nathan Chancellor wrote:
> Clang warns:
>
> kernel/locking/test-ww_mutex.c:138:7: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
>                  if (!ww_mutex_trylock(&mutex, &ctx)) {
>                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> kernel/locking/test-ww_mutex.c:172:9: note: uninitialized use occurs here
>          return ret;
>                 ^~~
> kernel/locking/test-ww_mutex.c:138:3: note: remove the 'if' if its condition is always false
>                  if (!ww_mutex_trylock(&mutex, &ctx)) {
>                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> kernel/locking/test-ww_mutex.c:125:9: note: initialize the variable 'ret' to silence this warning
>          int ret;
>                 ^
>                  = 0
> 1 error generated.
>
> Assign !ww_mutex_trylock(...) to ret so that it is always initialized.
>
> Fixes: 12235da8c80a ("kernel/locking: Add context to ww_mutex_trylock()")
> Link: https://github.com/ClangBuiltLinux/linux/issues/1463
> Reported-by: "kernelci.org bot" <bot@kernelci.org>
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
>   kernel/locking/test-ww_mutex.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c
> index d63ac411f367..353004155d65 100644
> --- a/kernel/locking/test-ww_mutex.c
> +++ b/kernel/locking/test-ww_mutex.c
> @@ -135,7 +135,8 @@ static int test_aa(bool trylock)
>   			goto out;
>   		}
>   	} else {
> -		if (!ww_mutex_trylock(&mutex, &ctx)) {
> +		ret = !ww_mutex_trylock(&mutex, &ctx);
> +		if (ret) {
>   			pr_err("%s: initial trylock failed!\n", __func__);
>   			goto out;
>   		}
>
> base-commit: 12235da8c80a1f9909008e4ca6036d5772b81192

I was a bit confused by this patch at the beginning and then realized 
that it was supposed to be applied on top of the tip true, not the 
current mainline kernel.

Anyway, it looks good to me

Acked-by: Waiman Long <longman@redhat.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: locking/core] locking/ww-mutex: Fix uninitialized use of ret in test_aa()
  2021-09-22 14:58 [PATCH] locking/ww-mutex: Fix uninitialized use of ret in test_aa() Nathan Chancellor
  2021-09-22 15:52 ` Waiman Long
@ 2021-10-01 15:05 ` tip-bot2 for Nathan Chancellor
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Nathan Chancellor @ 2021-10-01 15:05 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: kernelci.org bot, Stephen Rothwell, Nathan Chancellor,
	Peter Zijlstra (Intel),
	Waiman Long, x86, linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     1415b49bcd321bca7347f43f8b269c91ec46d1dc
Gitweb:        https://git.kernel.org/tip/1415b49bcd321bca7347f43f8b269c91ec46d1dc
Author:        Nathan Chancellor <nathan@kernel.org>
AuthorDate:    Wed, 22 Sep 2021 07:58:22 -07:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 01 Oct 2021 13:57:49 +02:00

locking/ww-mutex: Fix uninitialized use of ret in test_aa()

Clang warns:

kernel/locking/test-ww_mutex.c:138:7: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                if (!ww_mutex_trylock(&mutex, &ctx)) {
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/locking/test-ww_mutex.c:172:9: note: uninitialized use occurs here
        return ret;
               ^~~
kernel/locking/test-ww_mutex.c:138:3: note: remove the 'if' if its condition is always false
                if (!ww_mutex_trylock(&mutex, &ctx)) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/locking/test-ww_mutex.c:125:9: note: initialize the variable 'ret' to silence this warning
        int ret;
               ^
                = 0
1 error generated.

Assign !ww_mutex_trylock(...) to ret so that it is always initialized.

Fixes: 12235da8c80a ("kernel/locking: Add context to ww_mutex_trylock()")
Reported-by: "kernelci.org bot" <bot@kernelci.org>
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Waiman Long <longman@redhat.com>
Link: https://lore.kernel.org/r/20210922145822.3935141-1-nathan@kernel.org
---
 kernel/locking/test-ww_mutex.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c
index d63ac41..3530041 100644
--- a/kernel/locking/test-ww_mutex.c
+++ b/kernel/locking/test-ww_mutex.c
@@ -135,7 +135,8 @@ static int test_aa(bool trylock)
 			goto out;
 		}
 	} else {
-		if (!ww_mutex_trylock(&mutex, &ctx)) {
+		ret = !ww_mutex_trylock(&mutex, &ctx);
+		if (ret) {
 			pr_err("%s: initial trylock failed!\n", __func__);
 			goto out;
 		}

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-01 15:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-22 14:58 [PATCH] locking/ww-mutex: Fix uninitialized use of ret in test_aa() Nathan Chancellor
2021-09-22 15:52 ` Waiman Long
2021-10-01 15:05 ` [tip: locking/core] " tip-bot2 for Nathan Chancellor

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).