Avoid assigning u32 to the bool 'enabled'.
Signed-off-by: Nicolas Kaiser <[email protected]>
---
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
2011/4/1 Nicolas Kaiser <[email protected]>:
> Avoid assigning u32 to the bool 'enabled'.
>
> Signed-off-by: Nicolas Kaiser <[email protected]>
> ---
> ?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 <[email protected]>
Linus Walleij
>> - 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 <[email protected]>
/alessandro
On Sat, Apr 2, 2011 at 03:21, Nicolas Kaiser <[email protected]> wrote:
> Avoid assigning u32 to the bool 'enabled'.
>
> Signed-off-by: Nicolas Kaiser <[email protected]>
> ---
> ?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.
* Rabin Vincent <[email protected]>:
> On Sat, Apr 2, 2011 at 03:21, Nicolas Kaiser <[email protected]> wrote:
> > Avoid assigning u32 to the bool 'enabled'.
> >
> > Signed-off-by: Nicolas Kaiser <[email protected]>
> > ---
> > ?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
>> 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