* [PATCH] arm: nomadik: avoid assigning u32 to bool
@ 2011-04-01 21:51 Nicolas Kaiser
2011-04-02 21:02 ` Linus Walleij
2011-04-03 3:58 ` Rabin Vincent
0 siblings, 2 replies; 6+ messages in thread
From: Nicolas Kaiser @ 2011-04-01 21:51 UTC (permalink / raw)
To: linux-arm-kernel
Avoid assigning u32 to the bool 'enabled'.
Signed-off-by: Nicolas Kaiser <nikai@nikai.net>
---
arch/arm/plat-nomadik/gpio.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/arch/arm/plat-nomadik/gpio.c b/arch/arm/plat-nomadik/gpio.c
index f49748e..8b722f7 100644
--- a/arch/arm/plat-nomadik/gpio.c
+++ b/arch/arm/plat-nomadik/gpio.c
@@ -636,7 +636,7 @@ static int nmk_gpio_irq_set_type(struct irq_data *d, unsigned int type)
if (type & IRQ_TYPE_LEVEL_LOW)
return -EINVAL;
- enabled = nmk_chip->enabled & bitmask;
+ enabled = !!(nmk_chip->enabled & bitmask);
spin_lock_irqsave(&nmk_chip->lock, flags);
--
1.7.3.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] arm: nomadik: avoid assigning u32 to bool
2011-04-01 21:51 [PATCH] arm: nomadik: avoid assigning u32 to bool Nicolas Kaiser
@ 2011-04-02 21:02 ` Linus Walleij
2011-04-02 21:19 ` Alessandro Rubini
2011-04-03 3:58 ` Rabin Vincent
1 sibling, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2011-04-02 21:02 UTC (permalink / raw)
To: linux-arm-kernel
2011/4/1 Nicolas Kaiser <nikai@nikai.net>:
> Avoid assigning u32 to the bool 'enabled'.
>
> Signed-off-by: Nicolas Kaiser <nikai@nikai.net>
> ---
> ?arch/arm/plat-nomadik/gpio.c | ? ?2 +-
> ?1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/arch/arm/plat-nomadik/gpio.c b/arch/arm/plat-nomadik/gpio.c
> index f49748e..8b722f7 100644
> --- a/arch/arm/plat-nomadik/gpio.c
> +++ b/arch/arm/plat-nomadik/gpio.c
> @@ -636,7 +636,7 @@ static int nmk_gpio_irq_set_type(struct irq_data *d, unsigned int type)
> ? ? ? ?if (type & IRQ_TYPE_LEVEL_LOW)
> ? ? ? ? ? ? ? ?return -EINVAL;
>
> - ? ? ? enabled = nmk_chip->enabled & bitmask;
> + ? ? ? enabled = !!(nmk_chip->enabled & bitmask);
I've learned to live this way of casting stuff into boolean,
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Linus Walleij
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] arm: nomadik: avoid assigning u32 to bool
2011-04-02 21:02 ` Linus Walleij
@ 2011-04-02 21:19 ` Alessandro Rubini
0 siblings, 0 replies; 6+ messages in thread
From: Alessandro Rubini @ 2011-04-02 21:19 UTC (permalink / raw)
To: linux-arm-kernel
>> - enabled = nmk_chip->enabled & bitmask;
>> + enabled = !!(nmk_chip->enabled & bitmask);
>
> I've learned to live this way of casting stuff into boolean,
I use (and love) !! since I learnt C. What I really dislike is the
concept of boolean that doesn't fit in the C way of thinking, in my opinion.
But I'm not going to change that.
Acked-by: Alessandro Rubini <rubini@unipv.it>
/alessandro
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] arm: nomadik: avoid assigning u32 to bool
2011-04-01 21:51 [PATCH] arm: nomadik: avoid assigning u32 to bool Nicolas Kaiser
2011-04-02 21:02 ` Linus Walleij
@ 2011-04-03 3:58 ` Rabin Vincent
2011-04-03 10:26 ` Nicolas Kaiser
1 sibling, 1 reply; 6+ messages in thread
From: Rabin Vincent @ 2011-04-03 3:58 UTC (permalink / raw)
To: linux-arm-kernel
On Sat, Apr 2, 2011 at 03:21, Nicolas Kaiser <nikai@nikai.net> wrote:
> Avoid assigning u32 to the bool 'enabled'.
>
> Signed-off-by: Nicolas Kaiser <nikai@nikai.net>
> ---
> ?arch/arm/plat-nomadik/gpio.c | ? ?2 +-
> ?1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/arch/arm/plat-nomadik/gpio.c b/arch/arm/plat-nomadik/gpio.c
> index f49748e..8b722f7 100644
> --- a/arch/arm/plat-nomadik/gpio.c
> +++ b/arch/arm/plat-nomadik/gpio.c
> @@ -636,7 +636,7 @@ static int nmk_gpio_irq_set_type(struct irq_data *d, unsigned int type)
> ? ? ? ?if (type & IRQ_TYPE_LEVEL_LOW)
> ? ? ? ? ? ? ? ?return -EINVAL;
>
> - ? ? ? enabled = nmk_chip->enabled & bitmask;
> + ? ? ? enabled = !!(nmk_chip->enabled & bitmask);
Why? There are dozens of places in the kernel where this done, the code
generated should be the same, and it's pretty obvious what is being done
as it is.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] arm: nomadik: avoid assigning u32 to bool
2011-04-03 3:58 ` Rabin Vincent
@ 2011-04-03 10:26 ` Nicolas Kaiser
2011-04-03 10:52 ` Alessandro Rubini
0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Kaiser @ 2011-04-03 10:26 UTC (permalink / raw)
To: linux-arm-kernel
* Rabin Vincent <rabin@rab.in>:
> On Sat, Apr 2, 2011 at 03:21, Nicolas Kaiser <nikai@nikai.net> wrote:
> > Avoid assigning u32 to the bool 'enabled'.
> >
> > Signed-off-by: Nicolas Kaiser <nikai@nikai.net>
> > ---
> > ?arch/arm/plat-nomadik/gpio.c | ? ?2 +-
> > ?1 files changed, 1 insertions(+), 1 deletions(-)
> >
> > diff --git a/arch/arm/plat-nomadik/gpio.c b/arch/arm/plat-nomadik/gpio.c
> > index f49748e..8b722f7 100644
> > --- a/arch/arm/plat-nomadik/gpio.c
> > +++ b/arch/arm/plat-nomadik/gpio.c
> > @@ -636,7 +636,7 @@ static int nmk_gpio_irq_set_type(struct irq_data *d, unsigned int type)
> > ? ? ? ?if (type & IRQ_TYPE_LEVEL_LOW)
> > ? ? ? ? ? ? ? ?return -EINVAL;
> >
> > - ? ? ? enabled = nmk_chip->enabled & bitmask;
> > + ? ? ? enabled = !!(nmk_chip->enabled & bitmask);
>
> Why? There are dozens of places in the kernel where this done, the code
> generated should be the same, and it's pretty obvious what is being done
> as it is.
Primarily because we were asked to avoid casts to bool even if
they are safe.
https://lkml.org/lkml/2011/4/1/255
Besides, many of the places I found that do 'bool a = b & c;'
actually do 'bool a = b & 1;'.
Best regards,
Nicolas Kaiser
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] arm: nomadik: avoid assigning u32 to bool
2011-04-03 10:26 ` Nicolas Kaiser
@ 2011-04-03 10:52 ` Alessandro Rubini
0 siblings, 0 replies; 6+ messages in thread
From: Alessandro Rubini @ 2011-04-03 10:52 UTC (permalink / raw)
To: linux-arm-kernel
>> Why? There are dozens of places in the kernel where this done, the code
>> generated should be the same, and it's pretty obvious what is being done
>> as it is.
>
> Primarily because we were asked to avoid casts to bool even if
> they are safe.
[I have studied, meanwhile]
Actually the point of Rabin is, I think, that the patch is not needed.
Our "bool" is the C99 "_Bool" type, for which the compiler
automatically converts all non-0 assignments to 1. Even if storage
is still one byte.
IIUC, the point of _Bool is allowing comparisong with "true", while in
general non-0 is considered true if evaluated in a conditional
but may be "!= 1" so "!= true" if compared explicitly.
You can compile a one-liner to check. I used a few more:
_Bool i[10];
int main(void)
{
i[0] = 1;
i[1] = 10;
return i[0];
}
/alessandro
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-04-03 10:52 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-01 21:51 [PATCH] arm: nomadik: avoid assigning u32 to bool Nicolas Kaiser
2011-04-02 21:02 ` Linus Walleij
2011-04-02 21:19 ` Alessandro Rubini
2011-04-03 3:58 ` Rabin Vincent
2011-04-03 10:26 ` Nicolas Kaiser
2011-04-03 10:52 ` Alessandro Rubini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).