From patchwork Thu Jul 20 09:42:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "J, KEERTHY" X-Patchwork-Id: 9854421 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2B672602BA for ; Thu, 20 Jul 2017 09:43:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F40B2875E for ; Thu, 20 Jul 2017 09:43:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13D9628776; Thu, 20 Jul 2017 09:43:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8F1FE2875E for ; Thu, 20 Jul 2017 09:43:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=rkcYfT5Z3Gzn4O9Hw7pHSTcBX+62Vz8k32hlu1ozCkw=; b=H+61za4ZlG2YvO SrvmSzXB74KXR10isgn7DF/ab7Dt22TRvUBUW54a9FxKKkPhzpe4KILPyN4e7Z5cla8JQmGEzQHFB mSm1omeih496+JBhUdNSKkd2bIkcFqyiUzWOiiK7bT+T4YQs1WZl4MCC8UEFJSGZo64fpPJc2N1tQ HWJMprNoHS1g2z0ragnNseQfOcuQDbdSNiDDCMj6jyZFUmpFXfQP+LxLipe3abtFjx1elb33CsUNk Rc1/v6r+7I2DIsA5Lo3GkXr123Oa5xGdjdbkF4hxl725kqYh74QiRz7vsdwwL3x0OSm65aXf5NyrI bTkTxCdCg3HK0rN05ZsQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dY7z4-0002AA-41; Thu, 20 Jul 2017 09:43:02 +0000 Received: from lelnx193.ext.ti.com ([198.47.27.77]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dY7z0-00028p-11 for linux-arm-kernel@lists.infradead.org; Thu, 20 Jul 2017 09:43:00 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by lelnx193.ext.ti.com (8.15.1/8.15.1) with ESMTP id v6K9gaUi017611; Thu, 20 Jul 2017 04:42:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1500543756; bh=9Iij0ctqVt+ZKLTnljt0xnlanBN53TLQP+38Eoa4Cfc=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=PR1BbM4cIbVG3HLM/pt7AAxwTw5mtrh3iuSCBleb2wIasvVNVLiynMIB4IoivKpT6 XEX7aokC9u7GHh5HbBmEz0vDXKcwbI2dYB79GM39c5udRcfjETFulBOW9wNS18VzCW c6P4UlUpvX/8tlzFZFZqSsNyNjCVMCqfi6dTAfKU= Received: from DLEE70.ent.ti.com (dlemailx.itg.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id v6K9gaFI017823; Thu, 20 Jul 2017 04:42:36 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.294.0; Thu, 20 Jul 2017 04:42:36 -0500 Received: from ula0393675.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id v6K9gQAK020613; Thu, 20 Jul 2017 04:42:32 -0500 From: Keerthy To: Subject: [PATCH v2 1/3] gpio: davinci: Use devm_gpiochip_add_data in place of gpiochip_add_data Date: Thu, 20 Jul 2017 15:12:16 +0530 Message-ID: <1500543738-9696-2-git-send-email-j-keerthy@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500543738-9696-1-git-send-email-j-keerthy@ti.com> References: <1500543738-9696-1-git-send-email-j-keerthy@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170720_024258_219662_64CD6543 X-CRM114-Status: GOOD ( 10.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: j-keerthy@ti.com, nsekhar@ti.com, t-kristo@ti.com, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, fcooper@ti.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Use the devm version of gpiochip_add_data and pass on the return value. This avoids memory leak due to gpiochip_add_data in case the driver is unbound. Signed-off-by: Keerthy --- Changes in v2: * Restoring the previous values of ctrl_num and bank_base in case of an error. drivers/gpio/gpio-davinci.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c index 65cb359..27499ec 100644 --- a/drivers/gpio/gpio-davinci.c +++ b/drivers/gpio/gpio-davinci.c @@ -166,7 +166,7 @@ static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset) static int davinci_gpio_probe(struct platform_device *pdev) { static int ctrl_num, bank_base; - int gpio, bank; + int gpio, bank, ret = 0; unsigned ngpio, nbank; struct davinci_gpio_controller *chips; struct davinci_gpio_platform_data *pdata; @@ -232,10 +232,20 @@ static int davinci_gpio_probe(struct platform_device *pdev) for (gpio = 0, bank = 0; gpio < ngpio; gpio += 32, bank++) chips->regs[bank] = gpio_base + offset_array[bank]; - gpiochip_add_data(&chips->chip, chips); + ret = devm_gpiochip_add_data(dev, &chips->chip, chips); + if (ret) + goto err; + platform_set_drvdata(pdev, chips); davinci_gpio_irq_setup(pdev); return 0; + +err: + /* Revert the static variable increments */ + ctrl_num--; + bank_base -= ngpio; + + return ret; } /*--------------------------------------------------------------------------*/