From: David Daney <ddaney@caviumnetworks.com>
To: Alexander Beregalov <a.beregalov@gmail.com>
Cc: arnd@arndb.de, linux-kernel@vger.kernel.org,
David Miller <davem@davemloft.net>,
sam@ravnborg.org, dhowells@redhat.com
Subject: Re: [PATCH] BUG(): CONFIG_BUG=n version of BUG() should be unreachable()
Date: Tue, 22 Dec 2009 17:37:03 -0800 [thread overview]
Message-ID: <4B31743F.8070804@caviumnetworks.com> (raw)
In-Reply-To: <4B3171DF.4070903@caviumnetworks.com>
David Daney wrote:
> Alexander Beregalov wrote:
>> Previouss definition of BUG() as 'do {} while(0)' produced compilation
>> warnings when BUG() was used in default branch of switch() statement
>> (control reaches end of non-void function).
>>
>> Example:
>> unsigned long function()
>> {
>> switch() {
>> case 1:
>> return 1;
>> case 2:
>> return 2;
>> default:
>> BUG();
>> }
>>
>> Using unreachable() fixes the problem.
>>
>> Signed-off-by: Alexander Beregalov <a.beregalov@gmail.com>
>>
>
> NAK.
>
Well that may be too strong an objection, but I would really recommend
deeper consideration.
If you use: #define BUG() __builtin_unreachable()
which is what your patch does for GCC >= 4.5, it is truly undefined what
happens if it is ever reached. One typical thing that might happen is
that you start to try to execute data. It is unclear to me if it is
preferable in the kernel to do that, rather than loop endlessly. You
would likely achieve smaller code, but at what cost?
David Daney
>
>> diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
>> index 18c435d..1106439 100644
>> --- a/include/asm-generic/bug.h
>> +++ b/include/asm-generic/bug.h
>> @@ -89,7 +89,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
>
> You can only use 'unreachable()' in situations where it is truly
> unreachable. In the case above you will reach it in the default case.
>
> I would suggest one of the following instead:
>
> #define BUG() BUILD_BUG_ON(1)
>
> #define BUG() do {} while(1)
>
>
> David Daney
>
next prev parent reply other threads:[~2009-12-23 1:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-23 1:17 [PATCH] BUG(): CONFIG_BUG=n version of BUG() should be unreachable() Alexander Beregalov
2009-12-23 1:26 ` David Daney
2009-12-23 1:37 ` David Daney [this message]
2009-12-30 19:12 ` Arnd Bergmann
2010-01-04 18:06 ` David Daney
2010-01-05 11:35 ` Arnd Bergmann
2009-12-26 18:47 ` Sam Ravnborg
2010-01-05 17:58 ` David Howells
2010-01-05 18:30 ` Arnd Bergmann
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=4B31743F.8070804@caviumnetworks.com \
--to=ddaney@caviumnetworks.com \
--cc=a.beregalov@gmail.com \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sam@ravnborg.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