locking/ww-mutex: Fix uninitialized use of ret in test_aa()
PATCH 1/1 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;
^
= 01 error generated.
Assign !ww_mutex_trylock(...) to ret so that it is always initialized.
--- kernel/locking/test-ww_mutex.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/locking/test-ww_mutex.c +2 -1
@@ -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
Signature · 1 line
2.33.0.514.g99c99ed825
Quoted 43 lines · Nathan Chancellor
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; ^ = 01 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" <[email protected]>Reported-by Stephen Rothwell <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- kernel/locking/test-ww_mutex.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/locking/test-ww_mutex.c +2
-1@@ -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; }
Quoted 1 line
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
The following commit has been merged into the locking/core branch of tip:
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 <[email protected]> AuthorDate: Wed, 22 Sep 2021 07:58:22 -07:00 Committer: Peter Zijlstra <[email protected]> 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;
^
= 01 error generated.
Assign !ww_mutex_trylock(...) to ret so that it is always initialized.
--- kernel/locking/test-ww_mutex.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/locking/test-ww_mutex.c +2 -1
@@ -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; }