locking/ww-mutex: Fix uninitialized use of ret in test_aa()
authorNathan Chancellor <nathan@kernel.org>
Wed, 22 Sep 2021 14:58:22 +0000 (07:58 -0700)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 1 Oct 2021 11:57:49 +0000 (13:57 +0200)
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

index d63ac411f367228a7f66dafe5ca4ddc6833377cb..353004155d659fa271d0921bb454a2eb27ad1b8a 100644 (file)
@@ -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;
                }