From patchwork Wed Apr 22 11:11:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Kokkonen X-Patchwork-Id: 6255631 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 372A7BF4A6 for ; Wed, 22 Apr 2015 11:16:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5B6B520253 for ; Wed, 22 Apr 2015 11:16:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7C0AF2024C for ; Wed, 22 Apr 2015 11:16:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yksbd-0001nK-RL; Wed, 22 Apr 2015 11:14:13 +0000 Received: from oul135-36.netplaza.fi ([80.75.100.36] helo=lime.offcode.fi) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YksaH-00010E-8o for linux-arm-kernel@lists.infradead.org; Wed, 22 Apr 2015 11:12:50 +0000 Received: from localhost (localhost [127.0.0.1]) by lime.offcode.fi (Postfix) with ESMTP id 175F756959; Wed, 22 Apr 2015 14:19:12 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at lime.offcode.fi Received: from lime.offcode.fi ([127.0.0.1]) by localhost (lime.offcode.fi [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id la3vDaKVt-ss; Wed, 22 Apr 2015 14:19:11 +0300 (EEST) Received: from kampiakseli.offcode.fi (kampiakseli.offcode.fi [10.1.1.154]) by lime.offcode.fi (Postfix) with ESMTP id 939535695B; Wed, 22 Apr 2015 14:19:08 +0300 (EEST) From: Timo Kokkonen To: linux-arm-kernel@lists.infradead.org, linux-watchdog@vger.kernel.org, boris.brezillon@free-electrons.com, nicolas.ferre@atmel.com, alexandre.belloni@free-electrons.com Subject: [PATCHv7 7/8] watchdog: omap_wdt: Fix memory leak on probe fail Date: Wed, 22 Apr 2015 14:11:41 +0300 Message-Id: <1429701102-22320-8-git-send-email-timo.kokkonen@offcode.fi> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1429701102-22320-1-git-send-email-timo.kokkonen@offcode.fi> References: <1429701102-22320-1-git-send-email-timo.kokkonen@offcode.fi> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150422_041249_564536_F12B9264 X-CRM114-Status: UNSURE ( 9.78 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) Cc: Timo Kokkonen , Wenyou.Yang@atmel.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Structures allocated on the beginning of the probe function must be freed in case of failure. Signed-off-by: Timo Kokkonen --- drivers/watchdog/omap_wdt.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/watchdog/omap_wdt.c b/drivers/watchdog/omap_wdt.c index 1e6be9e..bbaf39a 100644 --- a/drivers/watchdog/omap_wdt.c +++ b/drivers/watchdog/omap_wdt.c @@ -226,8 +226,10 @@ static int omap_wdt_probe(struct platform_device *pdev) /* reserve static register mappings */ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); wdev->base = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(wdev->base)) - return PTR_ERR(wdev->base); + if (IS_ERR(wdev->base)) { + ret = PTR_ERR(wdev->base); + goto err_ioremap; + } omap_wdt->info = &omap_wdt_info; omap_wdt->ops = &omap_wdt_ops; @@ -258,10 +260,8 @@ static int omap_wdt_probe(struct platform_device *pdev) omap_wdt_disable(wdev); ret = watchdog_register_device(omap_wdt); - if (ret) { - pm_runtime_disable(wdev->dev); - return ret; - } + if (ret) + goto err_register_device; pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n", readl_relaxed(wdev->base + OMAP_WATCHDOG_REV) & 0xFF, @@ -270,6 +270,14 @@ static int omap_wdt_probe(struct platform_device *pdev) pm_runtime_put_sync(wdev->dev); return 0; + +err_register_device: + pm_runtime_disable(wdev->dev); +err_ioremap: + kfree(wdev); + kfree(omap_wdt); + + return ret; } static void omap_wdt_shutdown(struct platform_device *pdev)