mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <wqu@suse.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>,
	clm@fb.com, josef@toxicpanda.com, dsterba@suse.com,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Abaci Robot <abaci@linux.alibaba.com>
Subject: Re: [PATCH] btrfs: Use min() instead of doing it manually
Date: Mon, 3 Jan 2022 19:12:55 +0100	[thread overview]
Message-ID: <20220103181255.GL28560@twin.jikos.cz> (raw)
In-Reply-To: <7a37b841-3b82-ce8d-0459-ebaea539fc89@suse.com>

On Mon, Dec 27, 2021 at 07:49:01PM +0800, Qu Wenruo wrote:
> 
> 
> On 2021/12/27 19:34, Jiapeng Chong wrote:
> > Eliminate following coccicheck warning:
> > 
> > ./fs/btrfs/volumes.c:7768:13-14: WARNING opportunity for min().
> > 
> > Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> > Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> > ---
> >   fs/btrfs/volumes.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> > index 730355b55b42..dca3f0cedff9 100644
> > --- a/fs/btrfs/volumes.c
> > +++ b/fs/btrfs/volumes.c
> > @@ -7765,7 +7765,7 @@ static int btrfs_device_init_dev_stats(struct btrfs_device *device,
> >   			btrfs_dev_stat_set(device, i, 0);
> >   		device->dev_stats_valid = 1;
> >   		btrfs_release_path(path);
> > -		return ret < 0 ? ret : 0;
> > +		return min(ret, 0);
> 
> Nope, please don't blindly follow whatever the static checker reports, 
> but spend sometime on the code.
> 
> In this particular case, min(ret, 0) is not really making the code any 
> easier to read.
> 
> The "if (ret)" branch means, either we got a critical error (ret < 0) or 
> we didn't find the dev status item
> 
> For no dev status item case, it's no big deal and we can continue 
> returning 0. For fatal error case, it mostly means the device tree is 
> corrupted, and we return @ret directly.
> 
> Are you really thinking we're calculating a minimal value between 0 and ret?

That's probably the most important point. Although the expression could
be equivalent to calculating minimum, the code should read "if there was
an error, return it, otherwise return 0". Using min() for that obscures
that.

      reply	other threads:[~2022-01-03 18:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-27 11:34 Jiapeng Chong
2021-12-27 11:49 ` Qu Wenruo
2022-01-03 18:12   ` David Sterba [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=20220103181255.GL28560@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=abaci@linux.alibaba.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=jiapeng.chong@linux.alibaba.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wqu@suse.com \
    /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

all inboxes | Powered by JetHome®