All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rabin Vincent <rabin.vincent@stericsson.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCHv2 06/13] nomadik-gpio: check for invalid gpio numbers
Date: Thu, 8 Apr 2010 19:13:13 +0530	[thread overview]
Message-ID: <1270734200-17762-7-git-send-email-rabin.vincent@stericsson.com> (raw)
In-Reply-To: <1270734200-17762-6-git-send-email-rabin.vincent@stericsson.com>

Cc: Alessandro Rubini <rubini@unipv.it>
Acked-by: Michael Brandt <michael.brandt@stericsson.com>
Signed-off-by: Rabin Vincent <rabin.vincent@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

  reply	other threads:[~2010-04-08 13:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-08 13:43 [U-Boot] [PATCHv2 00/13] ST-Ericsson Ux500 support Rabin Vincent
2010-04-08 13:43 ` [U-Boot] [PATCHv2 01/13] Nomadik: move nomadik.h to asm/arch/nhk8815.h Rabin Vincent
2010-04-08 13:43   ` [U-Boot] [PATCHv2 02/13] Nomadik: timer: push down single-use macros Rabin Vincent
2010-04-08 13:43     ` [U-Boot] [PATCHv2 03/13] Nomadik: timer: remove header and use C structs Rabin Vincent
2010-04-08 13:43       ` [U-Boot] [PATCHv2 04/13] Nomadik: move timer code to drivers/misc Rabin Vincent
2010-04-08 13:43         ` [U-Boot] [PATCHv2 05/13] Nomadik: move gpio driver to drivers/gpio Rabin Vincent
2010-04-08 13:43           ` Rabin Vincent [this message]
2010-04-08 13:43             ` [U-Boot] [PATCHv2 07/13] nomadik-gpio: get base address from platform code Rabin Vincent
2010-04-08 13:43               ` [U-Boot] [PATCHv2 08/13] nomadik-mtu: support configurable clock rates Rabin Vincent
2010-04-08 13:43                 ` [U-Boot] [PATCHv2 09/13] arm: add Cortex A9 support Rabin Vincent
2010-04-08 13:43                   ` [U-Boot] [PATCHv2 10/13] ARM Cortex A9: ifdef code calling lowlevel init Rabin Vincent
2010-04-08 13:43                     ` [U-Boot] [PATCHv2 11/13] ux500: add SoC-specific code Rabin Vincent
2010-04-08 13:43                       ` [U-Boot] [PATCHv2 12/13] pl01x: add support for Ux500 variant of pl011 Rabin Vincent
2010-04-08 13:43                         ` [U-Boot] [PATCHv2 13/13] mop500: add board-specific files Rabin Vincent
2010-04-09 23:04                         ` [U-Boot] [PATCHv2 12/13] pl01x: add support for Ux500 variant of pl011 Wolfgang Denk
2010-04-09 11:29                   ` [U-Boot] [PATCHv2 09/13] arm: add Cortex A9 support Nishanth Menon
2010-04-09 13:27                     ` Vaibhav Bedia
2010-04-09 23:06                       ` Wolfgang Denk
2010-04-10  0:22                         ` Nishanth Menon
2010-04-10 16:54                       ` Rabin Vincent
2010-04-11 20:45                         ` Tom
2010-04-20 12:16                           ` Rabin VINCENT

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1270734200-17762-7-git-send-email-rabin.vincent@stericsson.com \
    --to=rabin.vincent@stericsson.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.