Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[MIPS] au1000: Make sure GPIO value is zero or one

David Brownell <david-b@pacbell.net> wrote:
> The problem is that "value" is zero-or-nonzero.
> This code wrongly assumes it's zero-or-one.
> Possible fix: "((!!value) << gpio)".

Signed-off-by: Bruno Randolf <br1@einfach.org>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Bruno Randolf and committed by
Ralf Baechle
19506fc5 6ef190cc

+2 -2
+2 -2
arch/mips/au1000/common/gpio.c
··· 48 48 { 49 49 gpio -= AU1XXX_GPIO_BASE; 50 50 51 - gpio2->output = (GPIO2_OUTPUT_ENABLE_MASK << gpio) | (value << gpio); 51 + gpio2->output = (GPIO2_OUTPUT_ENABLE_MASK << gpio) | ((!!value) << gpio); 52 52 } 53 53 54 54 static int au1xxx_gpio2_direction_input(unsigned gpio) ··· 62 62 { 63 63 gpio -= AU1XXX_GPIO_BASE; 64 64 gpio2->dir |= 0x01 << gpio; 65 - gpio2->output = (GPIO2_OUTPUT_ENABLE_MASK << gpio) | (value << gpio); 65 + gpio2->output = (GPIO2_OUTPUT_ENABLE_MASK << gpio) | ((!!value) << gpio); 66 66 return 0; 67 67 } 68 68