All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <natechancellor@gmail.com>
To: Richard Weinberger <richard@nod.at>
Cc: Boris Brezillon <bbrezillon@kernel.org>,
	Artem Bityutskiy <dedekind1@gmail.com>,
	kernel-janitors@vger.kernel.org,
	Marek Vasut <marek.vasut@gmail.com>,
	linux-mtd@lists.infradead.org,
	Brian Norris <computersforpeace@gmail.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [PATCH] ubi: wl: Silence uninitialized variable warning
Date: Thu, 28 Feb 2019 08:50:58 +0000	[thread overview]
Message-ID: <20190228085058.GA5694@archlinux-ryzen> (raw)
In-Reply-To: <8490920.CCJDc82j5X@blindfold>

On Thu, Feb 28, 2019 at 09:35:50AM +0100, Richard Weinberger wrote:
> Am Donnerstag, 28. Februar 2019, 06:35:51 CET schrieb Dan Carpenter:
> > This condition needs to be fipped around because "err" is uninitialized
> > when "force" is set.  The Smatch static analysis tool complains and
> > UBsan will also complain at runtime.
> > 
> > Fixes: 663586c0a892 ("ubi: Expose the bitrot interface")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>

This fixes a -Wsometimes-uninitialized warning from Clang:

drivers/mtd/ubi/wl.c:1514:6: warning: variable 'err' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
        if (!force) {
            ^~~~~~
drivers/mtd/ubi/wl.c:1520:6: note: uninitialized use occurs here
        if (err = UBI_IO_BITFLIPS || force) {
            ^~~
drivers/mtd/ubi/wl.c:1514:2: note: remove the 'if' if its condition is always true
        if (!force) {
        ^~~~~~~~~~~~
drivers/mtd/ubi/wl.c:1478:9: note: initialize the variable 'err' to silence this warning
        int err;
               ^
                = 0
1 warning generated.

> > ---
> >  drivers/mtd/ubi/wl.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
> > index 40f838d54b0f..2709dc02fc24 100644
> > --- a/drivers/mtd/ubi/wl.c
> > +++ b/drivers/mtd/ubi/wl.c
> > @@ -1517,7 +1517,7 @@ int ubi_bitflip_check(struct ubi_device *ubi, int pnum, int force)
> >  		mutex_unlock(&ubi->buf_mutex);
> >  	}
> >  
> > -	if (err = UBI_IO_BITFLIPS || force) {
> > +	if (force || err = UBI_IO_BITFLIPS) {
> >  		/*
> >  		 * Okay, bit flip happened, let's figure out what we can do.
> >  		 */
> > 
> 
> Good catch, Dan!
> I thought gcc is supposed to find such issues too. :-/

This isn't the first time GCC hasn't caught something...

https://lore.kernel.org/lkml/20190221222123.GC6474@magnolia/

> 
> Thanks,
> //richard
> 
> 

Thanks,
Nathan

WARNING: multiple messages have this Message-ID (diff)
From: Nathan Chancellor <natechancellor@gmail.com>
To: Richard Weinberger <richard@nod.at>
Cc: Boris Brezillon <bbrezillon@kernel.org>,
	Artem Bityutskiy <dedekind1@gmail.com>,
	kernel-janitors@vger.kernel.org,
	Marek Vasut <marek.vasut@gmail.com>,
	linux-mtd@lists.infradead.org,
	Brian Norris <computersforpeace@gmail.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [PATCH] ubi: wl: Silence uninitialized variable warning
Date: Thu, 28 Feb 2019 01:50:58 -0700	[thread overview]
Message-ID: <20190228085058.GA5694@archlinux-ryzen> (raw)
In-Reply-To: <8490920.CCJDc82j5X@blindfold>

On Thu, Feb 28, 2019 at 09:35:50AM +0100, Richard Weinberger wrote:
> Am Donnerstag, 28. Februar 2019, 06:35:51 CET schrieb Dan Carpenter:
> > This condition needs to be fipped around because "err" is uninitialized
> > when "force" is set.  The Smatch static analysis tool complains and
> > UBsan will also complain at runtime.
> > 
> > Fixes: 663586c0a892 ("ubi: Expose the bitrot interface")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>

This fixes a -Wsometimes-uninitialized warning from Clang:

drivers/mtd/ubi/wl.c:1514:6: warning: variable 'err' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
        if (!force) {
            ^~~~~~
drivers/mtd/ubi/wl.c:1520:6: note: uninitialized use occurs here
        if (err == UBI_IO_BITFLIPS || force) {
            ^~~
drivers/mtd/ubi/wl.c:1514:2: note: remove the 'if' if its condition is always true
        if (!force) {
        ^~~~~~~~~~~~
drivers/mtd/ubi/wl.c:1478:9: note: initialize the variable 'err' to silence this warning
        int err;
               ^
                = 0
1 warning generated.

> > ---
> >  drivers/mtd/ubi/wl.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
> > index 40f838d54b0f..2709dc02fc24 100644
> > --- a/drivers/mtd/ubi/wl.c
> > +++ b/drivers/mtd/ubi/wl.c
> > @@ -1517,7 +1517,7 @@ int ubi_bitflip_check(struct ubi_device *ubi, int pnum, int force)
> >  		mutex_unlock(&ubi->buf_mutex);
> >  	}
> >  
> > -	if (err == UBI_IO_BITFLIPS || force) {
> > +	if (force || err == UBI_IO_BITFLIPS) {
> >  		/*
> >  		 * Okay, bit flip happened, let's figure out what we can do.
> >  		 */
> > 
> 
> Good catch, Dan!
> I thought gcc is supposed to find such issues too. :-/

This isn't the first time GCC hasn't caught something...

https://lore.kernel.org/lkml/20190221222123.GC6474@magnolia/

> 
> Thanks,
> //richard
> 
> 

Thanks,
Nathan

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2019-02-28  8:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-28  5:35 [PATCH] ubi: wl: Silence uninitialized variable warning Dan Carpenter
2019-02-28  5:35 ` Dan Carpenter
2019-02-28  8:35 ` Richard Weinberger
2019-02-28  8:35   ` Richard Weinberger
2019-02-28  8:50   ` Nathan Chancellor [this message]
2019-02-28  8:50     ` Nathan Chancellor
2019-02-28  9:51     ` Richard Weinberger
2019-02-28  9:51       ` Richard Weinberger
2019-02-28 15:33       ` Nathan Chancellor
2019-02-28 15:33         ` 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=20190228085058.GA5694@archlinux-ryzen \
    --to=natechancellor@gmail.com \
    --cc=bbrezillon@kernel.org \
    --cc=computersforpeace@gmail.com \
    --cc=dan.carpenter@oracle.com \
    --cc=dedekind1@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=richard@nod.at \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.