From: Sasha Levin <sasha.levin@oracle.com>
To: Russell King - ARM Linux <linux@arm.linux.org.uk>
Cc: Maarten Lankhorst <m.b.lankhorst@gmail.com>,
linux-kernel@vger.kernel.org, Kukjin Kim <kgene.kim@samsung.com>,
linux-arm-kernel@lists.infradead.org,
linux-samsung-soc@vger.kernel.org
Subject: Re: [PATCH] ARM: EXYNOS: use BUG_ON where possible
Date: Mon, 12 Nov 2012 10:52:27 -0500 [thread overview]
Message-ID: <50A11B3B.1080600@oracle.com> (raw)
In-Reply-To: <20121112152349.GH28327@n2100.arm.linux.org.uk>
On 11/12/2012 10:23 AM, Russell King - ARM Linux wrote:
> On Mon, Nov 12, 2012 at 04:12:29PM +0100, Maarten Lankhorst wrote:
>> Op 08-11-12 21:23, Sasha Levin schreef:
>>> @@ -465,10 +465,8 @@ static void __init combiner_cascade_irq(unsigned int combiner_nr, unsigned int i
>>> else
>>> max_nr = EXYNOS4_MAX_COMBINER_NR;
>>>
>>> - if (combiner_nr >= max_nr)
>>> - BUG();
>>> - if (irq_set_handler_data(irq, &combiner_data[combiner_nr]) != 0)
>>> - BUG();
>>> + BUG_ON(combiner_nr >= max_nr);
>>> + BUG_ON(irq_set_handler_data(irq, &combiner_data[combiner_nr]) != 0);
>>
>> Is it really a good idea to put functions that perform work in a BUG_ON?
>> I don't know, but for some reason it just feels wrong. I'd expect code to
>> compile fine if BUG_ON was a noop, so doing verification calls only, not
>> actual work..
>
> Well, it is currently defined as:
>
> include/asm-generic/bug.h:#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
> include/asm-generic/bug.h:#define BUG_ON(condition) do { if (condition) ; } while(0)
>
> but as these can be overridden, I don't think relying on those
> implementations is a good idea; to do so would be fragile. Eg, what if
> the BUG_ON() implementation becomes just:
>
> #define BUG_ON(x)
>
> then the function call itself vanishes. So, only put the actual bug test
> inside a BUG_ON(), not the functional part which must always be executed.
Even if we ignore that modifying the side-effects is wrong, there's already
more than enough code in the kernel (both in kernel/ / mm/, and in arch/) to
cause breakage if for some reason the expression is not evaluated.
If some arch decides to not evaluate the expression there it's going to be
inherently broken.
Thanks,
Sasha
WARNING: multiple messages have this Message-ID (diff)
From: sasha.levin@oracle.com (Sasha Levin)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: EXYNOS: use BUG_ON where possible
Date: Mon, 12 Nov 2012 10:52:27 -0500 [thread overview]
Message-ID: <50A11B3B.1080600@oracle.com> (raw)
In-Reply-To: <20121112152349.GH28327@n2100.arm.linux.org.uk>
On 11/12/2012 10:23 AM, Russell King - ARM Linux wrote:
> On Mon, Nov 12, 2012 at 04:12:29PM +0100, Maarten Lankhorst wrote:
>> Op 08-11-12 21:23, Sasha Levin schreef:
>>> @@ -465,10 +465,8 @@ static void __init combiner_cascade_irq(unsigned int combiner_nr, unsigned int i
>>> else
>>> max_nr = EXYNOS4_MAX_COMBINER_NR;
>>>
>>> - if (combiner_nr >= max_nr)
>>> - BUG();
>>> - if (irq_set_handler_data(irq, &combiner_data[combiner_nr]) != 0)
>>> - BUG();
>>> + BUG_ON(combiner_nr >= max_nr);
>>> + BUG_ON(irq_set_handler_data(irq, &combiner_data[combiner_nr]) != 0);
>>
>> Is it really a good idea to put functions that perform work in a BUG_ON?
>> I don't know, but for some reason it just feels wrong. I'd expect code to
>> compile fine if BUG_ON was a noop, so doing verification calls only, not
>> actual work..
>
> Well, it is currently defined as:
>
> include/asm-generic/bug.h:#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
> include/asm-generic/bug.h:#define BUG_ON(condition) do { if (condition) ; } while(0)
>
> but as these can be overridden, I don't think relying on those
> implementations is a good idea; to do so would be fragile. Eg, what if
> the BUG_ON() implementation becomes just:
>
> #define BUG_ON(x)
>
> then the function call itself vanishes. So, only put the actual bug test
> inside a BUG_ON(), not the functional part which must always be executed.
Even if we ignore that modifying the side-effects is wrong, there's already
more than enough code in the kernel (both in kernel/ / mm/, and in arch/) to
cause breakage if for some reason the expression is not evaluated.
If some arch decides to not evaluate the expression there it's going to be
inherently broken.
Thanks,
Sasha
next prev parent reply other threads:[~2012-11-12 15:53 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-08 20:23 [PATCH] vmxnet3: convert BUG_ON(true) into a simple BUG() Sasha Levin
2012-11-08 20:23 ` [PATCH] alpha: use BUG_ON where possible Sasha Levin
2012-11-08 21:42 ` Jiri Kosina
2012-11-09 16:23 ` Sasha Levin
2012-11-12 14:43 ` Jiri Kosina
2012-11-12 15:03 ` Sasha Levin
2012-11-08 20:23 ` [PATCH] ARM: gic: " Sasha Levin
2012-11-08 20:23 ` Sasha Levin
2012-11-08 20:23 ` [PATCH] ARM: kprobes: " Sasha Levin
2012-11-08 20:23 ` Sasha Levin
2012-11-09 9:26 ` Jon Medhurst (Tixy)
2012-11-09 9:26 ` Jon Medhurst (Tixy)
2012-11-08 20:23 ` [PATCH] ARM: EXYNOS: " Sasha Levin
2012-11-08 20:23 ` Sasha Levin
2012-11-12 15:12 ` Maarten Lankhorst
2012-11-12 15:12 ` Maarten Lankhorst
2012-11-12 15:23 ` Russell King - ARM Linux
2012-11-12 15:23 ` Russell King - ARM Linux
2012-11-12 15:52 ` Sasha Levin [this message]
2012-11-12 15:52 ` Sasha Levin
2012-11-12 15:25 ` Sasha Levin
2012-11-12 15:25 ` Sasha Levin
2012-11-08 20:23 ` [PATCH] ARM: integrator: " Sasha Levin
2012-11-08 20:23 ` Sasha Levin
2012-11-12 20:44 ` Arnd Bergmann
2012-11-12 20:44 ` Arnd Bergmann
2012-11-17 18:41 ` Linus Walleij
2012-11-17 18:41 ` Linus Walleij
2012-11-08 20:23 ` [PATCH] ARM: OMAP1: " Sasha Levin
2012-11-08 20:23 ` Sasha Levin
2012-11-08 20:23 ` Sasha Levin
2012-11-12 23:21 ` Tony Lindgren
2012-11-12 23:21 ` Tony Lindgren
2012-11-08 20:23 ` [PATCH] ARM: dma: " Sasha Levin
2012-11-08 20:23 ` Sasha Levin
2012-11-08 20:23 ` [PATCH] ARM: versatile: " Sasha Levin
2012-11-08 20:23 ` Sasha Levin
2012-11-09 6:02 ` [PATCH] vmxnet3: convert BUG_ON(true) into a simple BUG() Shreyas Bhatewara
2012-11-09 22:03 ` David Miller
2012-11-11 22:27 ` Ryan Mallon
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=50A11B3B.1080600@oracle.com \
--to=sasha.levin@oracle.com \
--cc=kgene.kim@samsung.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=m.b.lankhorst@gmail.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 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.