From: Khaled Romdhani <khaledromdhani216@gmail.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] fs/btrfs: Fix uninitialized variable
Date: Mon, 3 May 2021 09:49:49 +0100 [thread overview]
Message-ID: <20210503084949.GA27017@ard0534> (raw)
In-Reply-To: <eba16312-9d50-9549-76c0-b0512a394669@wanadoo.fr>
On Sun, May 02, 2021 at 12:17:51PM +0200, Christophe JAILLET wrote:
> Le 02/05/2021 à 00:50, Khaled ROMDHANI a écrit :
> > Fix the warning: variable 'zone' is used
> > uninitialized whenever '?:' condition is true.
> >
> > Fix that by preventing the code to reach
> > the last assertion. If the variable 'mirror'
> > is invalid, the assertion fails and we return
> > immediately.
> >
> > Reported-by: kernel test robot <lkp@intel.com>
> > Signed-off-by: Khaled ROMDHANI <khaledromdhani216@gmail.com>
> > ---
> > fs/btrfs/zoned.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> > index 8250ab3f0868..23da9d8dc184 100644
> > --- a/fs/btrfs/zoned.c
> > +++ b/fs/btrfs/zoned.c
> > @@ -145,7 +145,7 @@ static inline u32 sb_zone_number(int shift, int mirror)
> > case 2: zone = 1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift); break;
> > default:
> > ASSERT((u32)mirror < 3);
> > - break;
> > + return 0;
> > }
> > ASSERT(zone <= U32_MAX);
> >
> > base-commit: b5c294aac8a6164ddf38bfbdd1776091b4a1eeba
> >
> Hi,
>
> just a few comments.
>
> If I understand correctly, what you try to do is to silence a compiler
> warning if no case branch is taken.
>
> First, all your proposals are based on the previous one.
> I find it hard to follow because we don't easily see what are the
> differences since the beginning.
>
> The "base-commit" at the bottom of your mail, is related to your own local
> tree, I guess. It can't be used by any-one.
>
> My understanding it that a patch, should it be v2, v3..., must apply to the
> current tree. (In my case, it is the latest linux-next)
> This is not the case here and you have to apply each step to see the final
> result.
>
> Should this version be fine, a maintainer wouldn't be able to apply it
> as-is.
>
> You also try to take into account previous comments to check for incorrect
> negative values for minor and catch (the can't happen today) cases, should
> BTRFS_SUPER_MIRROR_MAX change and this function remain the same.
>
> So, why hard-coding '3'?
> The reason of magic numbers are hard to remember. You should avoid them or
> add a comment about it.
>
> My own personal variation would be something like the code below (untested).
>
> Hope this helps.
>
> CJ
>
>
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index 70b23a0d03b1..75fe5f001d8b 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -138,11 +138,14 @@ static inline u32 sb_zone_number(int shift, int
> mirror)
> {
> u64 zone;
>
> - ASSERT(mirror < BTRFS_SUPER_MIRROR_MAX);
> + ASSERT(mirror >= 0 && mirror < BTRFS_SUPER_MIRROR_MAX);
> switch (mirror) {
> case 0: zone = 0; break;
> case 1: zone = 1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift); break;
> case 2: zone = 1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift); break;
> + default:
> + ASSERT(! "mirror < BTRFS_SUPER_MIRROR_MAX but not handled above.");
> + return 0;
> }
>
> ASSERT(zone <= U32_MAX);
>
Thank you for all of your comments. Yes, of course, they will help me.
I will try to handle that more properly.
Thanks again.
next prev parent reply other threads:[~2021-05-03 8:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-01 22:50 [PATCH] fs/btrfs: Fix uninitialized variable Khaled ROMDHANI
2021-05-02 10:17 ` Christophe JAILLET
2021-05-03 8:49 ` Khaled Romdhani [this message]
2021-05-03 7:23 ` Dan Carpenter
2021-05-03 10:13 ` Khaled Romdhani
2021-05-03 11:55 ` Dan Carpenter
2021-05-03 11:58 ` Colin Ian King
2021-05-17 10:51 ` David Sterba
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=20210503084949.GA27017@ard0534 \
--to=khaledromdhani216@gmail.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@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