From: Ralf Baechle <ralf@linux-mips.org>
To: linux-kernel@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
David Howells <dhowells@redhat.com>,
Markos Chandras <Markos.Chandras@imgtec.com>
Cc: linux-mips@linux-mips.org
Subject: Re: [PATCH v2] MIPS: ath79: Avoid using unitialized 'reg' variable
Date: Wed, 18 Sep 2013 15:45:33 +0200 [thread overview]
Message-ID: <20130918134533.GN22468@linux-mips.org> (raw)
In-Reply-To: <5225EC3B.1070701@imgtec.com>
On Tue, Sep 03, 2013 at 03:03:39PM +0100, Markos Chandras wrote:
> >Was this triggered by CONFIG_BUG=n?
> >
> > Ralf
> >
>
> Hi Ralf,
>
> Yes it was triggered by CONFIG_BUG=n
So here's a small test case to demonstrate the issue:
/*
* Definition of BUG taken from asm-generic/bug.h for the CONFIG_BUG=n case
*/
#define BUG() do {} while(0)
int foo(int arg)
{
int res;
if (arg == 1)
res = 23;
else if (arg -= 2)
res = 42;
else
BUG();
return res;
}
[ralf@h7 linux-mips]$ gcc -O2 -Wall -c bug.c
bug.c: In function ‘foo’:
bug.c:17:2: warning: ‘res’ may be used uninitialized in this function [-Wmaybe-uninitialized]
return res;
^
It's fairly obvious to see what's happening here - GCC doesn't know that
the else case can not be reached, thus razorsharply concludes that res
may be used uninitialized.
I think the definition of BUG should be changed to something like
#define BUG() unreachable()
This has the disadvantage of of expanding into a while (1) loop for older
compilers - but that's only for older compilers, relativly minor in
bloat and last I checked BUG() wasn't performance critical ;-)
Ralf
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
include/asm-generic/bug.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 7d10f96..6f78771 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -108,7 +108,7 @@ extern void warn_slowpath_null(const char *file, const int line);
#else /* !CONFIG_BUG */
#ifndef HAVE_ARCH_BUG
-#define BUG() do {} while(0)
+#define BUG() unreachable()
#endif
#ifndef HAVE_ARCH_BUG_ON
next prev parent reply other threads:[~2013-09-18 13:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-21 10:47 [PATCH v2] MIPS: ath79: Avoid using unitialized 'reg' variable Markos Chandras
2013-08-21 10:47 ` Markos Chandras
2013-08-21 16:40 ` Gabor Juhos
2013-09-03 13:38 ` Ralf Baechle
2013-09-03 14:03 ` Markos Chandras
2013-09-03 14:03 ` Markos Chandras
2013-09-18 13:45 ` Ralf Baechle [this message]
2013-09-18 13:51 ` Ralf Baechle
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=20130918134533.GN22468@linux-mips.org \
--to=ralf@linux-mips.org \
--cc=Markos.Chandras@imgtec.com \
--cc=arnd@arndb.de \
--cc=dhowells@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.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 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.