[U-Boot] [PATCHv2 06/13] nomadik-gpio: check for invalid gpio numbers
Rabin Vincent
rabin.vincent at stericsson.com
Thu Apr 8 15:43:13 CEST 2010
Cc: Alessandro Rubini <rubini at unipv.it>
Acked-by: Michael Brandt <michael.brandt at stericsson.com>
Signed-off-by: Rabin Vincent <rabin.vincent at stericsson.com>
---
drivers/gpio/nomadik_gpio.c | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/drivers/gpio/nomadik_gpio.c b/drivers/gpio/nomadik_gpio.c
index 670b684..d084235 100644
--- a/drivers/gpio/nomadik_gpio.c
+++ b/drivers/gpio/nomadik_gpio.c
@@ -45,6 +45,11 @@ enum gpio_registers {
static inline unsigned long gpio_to_base(int gpio)
{
+ if ((gpio / 32) >= ARRAY_SIZE(gpio_base)) {
+ printf("nomadik-gpio: invalid gpio %d\n", gpio);
+ return 0;
+ }
+
return gpio_base[gpio / 32];
}
@@ -59,6 +64,9 @@ void nmk_gpio_af(int gpio, int alternate_function)
u32 bit = gpio_to_bit(gpio);
u32 afunc, bfunc;
+ if (!base)
+ return;
+
/* alternate function is 0..3, with one bit per register */
afunc = readl(base + GPIO_AFSLA) & ~bit;
bfunc = readl(base + GPIO_AFSLB) & ~bit;
@@ -73,6 +81,9 @@ void nmk_gpio_dir(int gpio, int dir)
unsigned long base = gpio_to_base(gpio);
u32 bit = gpio_to_bit(gpio);
+ if (!base)
+ return;
+
if (dir)
writel(bit, base + GPIO_DIRS);
else
@@ -84,6 +95,9 @@ void nmk_gpio_set(int gpio, int val)
unsigned long base = gpio_to_base(gpio);
u32 bit = gpio_to_bit(gpio);
+ if (!base)
+ return;
+
if (val)
writel(bit, base + GPIO_DATS);
else
@@ -95,5 +109,8 @@ int nmk_gpio_get(int gpio)
unsigned long base = gpio_to_base(gpio);
u32 bit = gpio_to_bit(gpio);
+ if (!base)
+ return -1;
+
return readl(base + GPIO_DAT) & bit;
}
--
1.7.0
More information about the U-Boot
mailing list