From patchwork Thu Apr 8 13:43:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [U-Boot,PATCHv2,06/13] nomadik-gpio: check for invalid gpio numbers Date: Thu, 08 Apr 2010 03:43:13 -0000 From: Rabin Vincent X-Patchwork-Id: 71742 Message-Id: <1270734200-17762-7-git-send-email-rabin.vincent@stericsson.com> To: Cc: STEricsson_nomadik_linux@list.st.com, Michael Brandt , Alessandro Rubini Cc: Alessandro Rubini Acked-by: Michael Brandt Signed-off-by: Rabin Vincent --- 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; }