linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Waiman Long <llong@redhat.com>
To: Nathan Chancellor <nathan@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>
Cc: Boqun Feng <boqun.feng@gmail.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	linux-kernel@vger.kernel.org, llvm@lists.linux.dev,
	"kernelci.org bot" <bot@kernelci.org>,
	Stephen Rothwell <sfr@canb.auug.org.au>
Subject: Re: [PATCH] locking/ww-mutex: Fix uninitialized use of ret in test_aa()
Date: Wed, 22 Sep 2021 11:52:58 -0400	[thread overview]
Message-ID: <27e08098-83b6-2238-59c1-3b38cd042a31@redhat.com> (raw)
In-Reply-To: <20210922145822.3935141-1-nathan@kernel.org>

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>


  reply	other threads:[~2021-09-22 15:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2021-10-01 15:05 ` [tip: locking/core] " tip-bot2 for Nathan Chancellor

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=27e08098-83b6-2238-59c1-3b38cd042a31@redhat.com \
    --to=llong@redhat.com \
    --cc=boqun.feng@gmail.com \
    --cc=bot@kernelci.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mingo@redhat.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=sfr@canb.auug.org.au \
    --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).