Linux-bcachefs Archive mirror
 help / color / mirror / Atom feed
From: Hongbo Li <lihongbo22@huawei.com>
To: Kent Overstreet <kent.overstreet@linux.dev>
Cc: <bfoster@redhat.com>, <linux-bcachefs@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] bcachefs: eliminate the uninitialized compilation warning in __do_six_trylock
Date: Fri, 26 Apr 2024 14:09:53 +0800	[thread overview]
Message-ID: <4c7f35f0-29c2-4368-8061-d022b7528469@huawei.com> (raw)
In-Reply-To: <mk6bvhdvbeo5ey7oxlclkgya4ywk3izi4p2anl5n7a7zngneoj@qddrf2si5nfd>



On 2024/4/26 12:04, Kent Overstreet wrote:
> On Fri, Apr 26, 2024 at 11:21:36AM +0800, Hongbo Li wrote:
>> When compiling the bcachefs-tools, the following compilation warning
>> is reported:
>>      libbcachefs/six.c: In function ‘__do_six_trylock’:
>>      libbcachefs/six.c:90:12: warning: ‘old’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>>         90 |  if (!(old & SIX_LOCK_HELD_intent)) {
>>          |       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
>>
>> This is also a false altert. Only when @type=SIX_LOCK_write and @try=false
>> are passed in __do_six_trylock, the second condition branch would enter
>> which does not initialize the @old variable. But six_set_owner will not
>> use @old if @type is not SIX_LOCK_intent. There should be nothing wrong
>> in logical too.
>>
>> Although the report itself is a false alert, we can elimate the unitialize
>> compilation warning by assigning @old in front.
>>
>> Fixes: 84a37cbf62e0 ("six locks: Wakeup now takes lock on behalf of waiter")
>> Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
> 
> let's just delete the assertion - I don't like moving around reading the
> lock state for this.
ok, thank you, and I will keep "old = atomic_read(&lock->state);" in the 
following else branch for next version.
> 
>> ---
>> v2:
>>    - Fix the error about reading lock->state introduced in v1.
>>
>> v1: https://lore.kernel.org/all/20240419074851.1583392-3-lihongbo22@huawei.com/T/#u
>> ---
>> ---
>>   fs/bcachefs/six.c | 5 ++---
>>   1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/fs/bcachefs/six.c b/fs/bcachefs/six.c
>> index 3a494c5d1247..8bfd22a6f771 100644
>> --- a/fs/bcachefs/six.c
>> +++ b/fs/bcachefs/six.c
>> @@ -118,11 +118,11 @@ static int __do_six_trylock(struct six_lock *lock, enum six_lock_type type,
>>   			    struct task_struct *task, bool try)
>>   {
>>   	int ret;
>> -	u32 old;
>> +	u32 old = atomic_read(&lock->state);
>>   
>>   	EBUG_ON(type == SIX_LOCK_write && lock->owner != task);
>>   	EBUG_ON(type == SIX_LOCK_write &&
>> -		(try != !(atomic_read(&lock->state) & SIX_LOCK_HELD_write)));
>> +		(try != !(old & SIX_LOCK_HELD_write)));
>>   
>>   	/*
>>   	 * Percpu reader mode:
>> @@ -182,7 +182,6 @@ static int __do_six_trylock(struct six_lock *lock, enum six_lock_type type,
>>   				ret = -1 - SIX_LOCK_read;
>>   		}
>>   	} else {
>> -		old = atomic_read(&lock->state);
>>   		do {
>>   			ret = !(old & l[type].lock_fail);
>>   			if (!ret || (type == SIX_LOCK_write && !try)) {
>> -- 
>> 2.34.1
>>
> 

      reply	other threads:[~2024-04-26  6:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-26  3:21 [PATCH v2 0/2] eliminate the uninitialized compilation warning Hongbo Li
2024-04-26  3:21 ` [PATCH v2 1/2] bcachefs: eliminate the uninitialized compilation warning in bch2_reconstruct_snapshots Hongbo Li
2024-04-26  4:04   ` Kent Overstreet
2024-04-26  3:21 ` [PATCH v2 2/2] bcachefs: eliminate the uninitialized compilation warning in __do_six_trylock Hongbo Li
2024-04-26  4:04   ` Kent Overstreet
2024-04-26  6:09     ` Hongbo Li [this message]

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=4c7f35f0-29c2-4368-8061-d022b7528469@huawei.com \
    --to=lihongbo22@huawei.com \
    --cc=bfoster@redhat.com \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcachefs@vger.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 read-only IMAP folder(s) and NNTP newsgroup(s).