From patchwork Sat May 17 19:18:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 4197031 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1435CBEEAB for ; Sat, 17 May 2014 19:22:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8EB722039E for ; Sat, 17 May 2014 19:21:57 +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 C751320395 for ; Sat, 17 May 2014 19:21:52 +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 1Wlk8F-0004sh-Gp; Sat, 17 May 2014 19:18:55 +0000 Received: from metis.ext.pengutronix.de ([2001:6f8:1178:4:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wlk88-0004rN-8B for linux-arm-kernel@lists.infradead.org; Sat, 17 May 2014 19:18:53 +0000 Received: from ptx.hi.pengutronix.de ([2001:6f8:1178:2:5054:ff:fec0:8e10] ident=Debian-exim) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1Wlk7c-00007y-5I; Sat, 17 May 2014 21:18:16 +0200 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.80) (envelope-from ) id 1Wlk7h-0004ho-7v; Sat, 17 May 2014 21:18:21 +0200 Date: Sat, 17 May 2014 21:18:21 +0200 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Emil Goode Subject: Re: [PATCH v3] ARM: imx: fix error handling in ipu device registration Message-ID: <20140517191821.GD16662@pengutronix.de> References: <1400352033-18262-1-git-send-email-emilgoode@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1400352033-18262-1-git-send-email-emilgoode@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-SA-Exim-Connect-IP: 2001:6f8:1178:2:5054:ff:fec0:8e10 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140517_121848_755055_888C09F9 X-CRM114-Status: GOOD ( 19.44 ) X-Spam-Score: -0.7 (/) Cc: Russell King , kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, Shawn Guo , Sascha Hauer , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,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 Hello Emil, On Sat, May 17, 2014 at 08:40:33PM +0200, Emil Goode wrote: > If we fail to allocate struct platform_device pdev we > dereference it after the goto label err. > > I have rearranged the error handling a bit to fix the issue > and also make it more clear. > > Signed-off-by: Emil Goode > --- > v3: Made subject line more specific. > v2: Changed to return -ENOMEM instead of ret where possible and > updated the subject line. > > arch/arm/mach-imx/devices/platform-ipu-core.c | 22 +++++++++++++--------- > 1 file changed, 13 insertions(+), 9 deletions(-) Considering that you can fix the issue also by just doing: I would prefer one of them as it is easier to justify and for the next cycle convert the function to platform_device_register_full. Also you should point out in the commit log that the issue was found by coccinelle. Best regards Uwe diff --git a/arch/arm/mach-imx/devices/platform-ipu-core.c b/arch/arm/mach-imx/devices/platform-ipu-core.c index fc4dd7cedc11..6bd7c3f37ac0 100644 --- a/arch/arm/mach-imx/devices/platform-ipu-core.c +++ b/arch/arm/mach-imx/devices/platform-ipu-core.c @@ -77,7 +77,7 @@ struct platform_device *__init imx_alloc_mx3_camera( pdev = platform_device_alloc("mx3-camera", 0); if (!pdev) - goto err; + return ERR_PTR(-ENOMEM); pdev->dev.dma_mask = kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL); if (!pdev->dev.dma_mask) or diff --git a/arch/arm/mach-imx/devices/platform-ipu-core.c b/arch/arm/mach-imx/devices/platform-ipu-core.c index fc4dd7cedc11..c609f3667200 100644 --- a/arch/arm/mach-imx/devices/platform-ipu-core.c +++ b/arch/arm/mach-imx/devices/platform-ipu-core.c @@ -96,7 +96,8 @@ struct platform_device *__init imx_alloc_mx3_camera( ret = platform_device_add_data(pdev, pdata, sizeof(*pdata)); if (ret) { err: - kfree(pdev->dev.dma_mask); + if (pdev) + kfree(pdev->dev.dma_mask); platform_device_put(pdev); return ERR_PTR(-ENODEV); }