From patchwork Thu Apr 8 13:43:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rabin Vincent X-Patchwork-Id: 71742 X-Patchwork-Delegate: albert.aribaud@free.fr Return-Path: X-Original-To: wd@gemini.denx.de Delivered-To: wd@gemini.denx.de Received: from diddl.denx.de (diddl.denx.de [10.0.0.6]) by gemini.denx.de (Postfix) with ESMTP id E9F3A1051E73 for ; Thu, 8 Apr 2010 15:48:31 +0200 (CEST) Received: from diddl.denx.de (localhost.localdomain [127.0.0.1]) by diddl.denx.de (Postfix) with ESMTP id 76DE6C913116 for ; Thu, 8 Apr 2010 15:48:31 +0200 (CEST) Received: from pop.mnet-online.de by diddl.denx.de with POP3 (fetchmail-6.3.9) for (single-drop); Thu, 08 Apr 2010 15:48:31 +0200 (CEST) Received: from murder (svr19.m-online.net [192.168.3.147]) by backend2 (Cyrus v2.2.12) with LMTPA; Thu, 08 Apr 2010 15:45:50 +0200 X-Sieve: CMU Sieve 2.2 Received: from mail.m-online.net (localhost [127.0.0.1]) by frontend3.pop.m-online.net (Cyrus v2.2.13) with LMTPA; Thu, 08 Apr 2010 15:45:49 +0200 Received: from scanner-1.m-online.net (unknown [192.168.8.165]) by mail.m-online.net (Postfix) with ESMTP id BF4E6200122; Thu, 8 Apr 2010 15:45:49 +0200 (CEST) Received: from mxin-1.m-online.net ([192.168.6.164]) by scanner-1.m-online.net (scanner-1.m-online.net [192.168.8.165]) (amavisd-new, port 10026) with ESMTP id 03469-02-16; Thu, 8 Apr 2010 15:45:48 +0200 (CEST) Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by mxin-1.m-online.net (Postfix) with ESMTP id 5A09E46C0AE; Thu, 8 Apr 2010 15:45:44 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0DB4B281A6; Thu, 8 Apr 2010 15:44:41 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sT9d9g0ik7ug; Thu, 8 Apr 2010 15:44:40 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EF679281A8; Thu, 8 Apr 2010 15:44:10 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 063CC28173 for ; Thu, 8 Apr 2010 15:44:08 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MvtUEfGKJCNE for ; Thu, 8 Apr 2010 15:44:06 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from eu1sys200aog112.obsmtp.com (eu1sys200aog112.obsmtp.com [207.126.144.133]) by theia.denx.de (Postfix) with ESMTPS id 04DF92813D for ; Thu, 8 Apr 2010 15:43:55 +0200 (CEST) Received: from source ([138.198.100.35]) (using TLSv1) by eu1sys200aob112.postini.com ([207.126.147.11]) with SMTP ID DSNKS73dmlVw/i0aciTw5VkwAJFtWH/uA91g@postini.com; Thu, 08 Apr 2010 13:43:59 UTC Received: from zeta.dmz-ap.st.com (ns6.st.com [138.198.234.13]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 275F7146; Thu, 8 Apr 2010 13:43:51 +0000 (GMT) Received: from relay1.stm.gmessaging.net (exdcvyvsstm006.eq1stm.local [10.230.100.17]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 28F23229; Thu, 8 Apr 2010 13:43:39 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id D37F124C075; Thu, 8 Apr 2010 15:43:42 +0200 (CEST) Received: from localhost (10.201.54.39) by exdcvycastm022.EQ1STM.local (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.1.393.1; Thu, 8 Apr 2010 15:43:49 +0200 From: Rabin Vincent To: Date: Thu, 8 Apr 2010 19:13:13 +0530 Message-ID: <1270734200-17762-7-git-send-email-rabin.vincent@stericsson.com> X-Mailer: git-send-email 1.7.0 In-Reply-To: <1270734200-17762-6-git-send-email-rabin.vincent@stericsson.com> References: <1270734200-17762-1-git-send-email-rabin.vincent@stericsson.com> <1270734200-17762-2-git-send-email-rabin.vincent@stericsson.com> <1270734200-17762-3-git-send-email-rabin.vincent@stericsson.com> <1270734200-17762-4-git-send-email-rabin.vincent@stericsson.com> <1270734200-17762-5-git-send-email-rabin.vincent@stericsson.com> <1270734200-17762-6-git-send-email-rabin.vincent@stericsson.com> MIME-Version: 1.0 Cc: STEricsson_nomadik_linux@list.st.com, Michael Brandt , Alessandro Rubini Subject: [U-Boot] [PATCHv2 06/13] nomadik-gpio: check for invalid gpio numbers X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de X-Virus-Scanned: by amavisd-new at m-online.net 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; }