From patchwork Sat Dec 8 16:31:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 1852991 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id A8A453FC8C for ; Sat, 8 Dec 2012 15:43:13 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1ThMUr-00006b-Ln; Sat, 08 Dec 2012 15:39:21 +0000 Received: from mail1-relais-roc.national.inria.fr ([192.134.164.82]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1ThMUh-00006G-3e for linux-arm-kernel@lists.infradead.org; Sat, 08 Dec 2012 15:39:12 +0000 X-IronPort-AV: E=Sophos;i="4.84,243,1355094000"; d="scan'208";a="185236119" Received: from palace.lip6.fr (HELO localhost.localdomain) ([132.227.105.202]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 08 Dec 2012 16:31:32 +0100 From: Julia Lawall To: Tony Prisk Subject: [PATCH] drivers/video/wm8505fb.c: use devm_ functions Date: Sat, 8 Dec 2012 17:31:28 +0100 Message-Id: <1354984288-773-1-git-send-email-Julia.Lawall@lip6.fr> X-Mailer: git-send-email 1.7.8.6 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121208_103911_409062_A720EB94 X-CRM114-Status: GOOD ( 16.20 ) X-Spam-Score: -6.1 (------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-6.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [192.134.164.82 listed in list.dnswl.org] 0.8 SPF_NEUTRAL SPF: sender does not match SPF record (neutral) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-fbdev@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Florian Tobias Schandinat X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Julia Lawall The various devm_ functions allocate memory that is released when a driver detaches. This patch uses these functions for data that is allocated in the probe function of a platform device and is only freed in the remove function. The patch makes some other cleanups. First, the original code used devm_kzalloc, but kfree. This would lead to a double free. The problem was found using the following semantic match (http://coccinelle.lip6.fr/): // @@ expression x,e; @@ x = devm_kzalloc(...) ... when != x = e ?-kfree(x,...); // The error-handling code for the call to dma_alloc_coherent is copied to the end of the function, like the other error-handling code. Given the introduction of the devm functions, this is just for uniformity, because the label at the end of the function now just returns the error code. A semicolon is removed at the end of this error handling code. The call platform_set_drvdata(pdev, NULL); is moved up under the label failed_free_cmap, because platform_set_drvdata(pdev, fbi); doesn't happen in the function until after gotos to this label are reached. The initializations of fbi and ret are not necessary and are removed. Signed-off-by: Julia Lawall --- drivers/video/wm8505fb.c | 44 ++++++++------------------------------------ 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/drivers/video/wm8505fb.c b/drivers/video/wm8505fb.c index 77539c1..3bad805 100644 --- a/drivers/video/wm8505fb.c +++ b/drivers/video/wm8505fb.c @@ -274,9 +274,6 @@ static int __devinit wm8505fb_probe(struct platform_device *pdev) unsigned long fb_mem_len; void *fb_mem_virt; - ret = -ENOMEM; - fbi = NULL; - fbi = devm_kzalloc(&pdev->dev, sizeof(struct wm8505fb_info) + sizeof(u32) * 16, GFP_KERNEL); if (!fbi) { @@ -308,31 +305,19 @@ static int __devinit wm8505fb_probe(struct platform_device *pdev) fbi->fb.pseudo_palette = addr; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (res == NULL) { - dev_err(&pdev->dev, "no I/O memory resource defined\n"); - ret = -ENODEV; - goto failed_fbi; - } - - res = request_mem_region(res->start, resource_size(res), DRIVER_NAME); - if (res == NULL) { - dev_err(&pdev->dev, "failed to request I/O memory\n"); - ret = -EBUSY; - goto failed_fbi; - } - fbi->regbase = ioremap(res->start, resource_size(res)); + fbi->regbase = devm_request_and_ioremap(&pdev->dev, res); if (fbi->regbase == NULL) { dev_err(&pdev->dev, "failed to map I/O memory\n"); ret = -EBUSY; - goto failed_free_res; + goto failed; } np = of_parse_phandle(pdev->dev.of_node, "default-mode", 0); if (!np) { pr_err("%s: No display description in Device Tree\n", __func__); ret = -EINVAL; - goto failed_free_res; + goto failed; } /* @@ -351,7 +336,7 @@ static int __devinit wm8505fb_probe(struct platform_device *pdev) ret |= of_property_read_u32(np, "bpp", &bpp); if (ret) { pr_err("%s: Unable to read display properties\n", __func__); - goto failed_free_res; + goto failed; } of_mode.vmode = FB_VMODE_NONINTERLACED; @@ -369,8 +354,9 @@ static int __devinit wm8505fb_probe(struct platform_device *pdev) GFP_KERNEL); if (!fb_mem_virt) { pr_err("%s: Failed to allocate framebuffer\n", __func__); - return -ENOMEM; - }; + ret = -ENOMEM; + goto failed; + } fbi->fb.var.xres_virtual = of_mode.xres; fbi->fb.var.yres_virtual = of_mode.yres * 2; @@ -384,7 +370,7 @@ static int __devinit wm8505fb_probe(struct platform_device *pdev) if (fb_alloc_cmap(&fbi->fb.cmap, 256, 0) < 0) { dev_err(&pdev->dev, "Failed to allocate color map\n"); ret = -ENOMEM; - goto failed_free_io; + goto failed; } wm8505fb_init_hw(&fbi->fb); @@ -420,13 +406,7 @@ static int __devinit wm8505fb_probe(struct platform_device *pdev) failed_free_cmap: if (fbi->fb.cmap.len) fb_dealloc_cmap(&fbi->fb.cmap); -failed_free_io: - iounmap(fbi->regbase); -failed_free_res: - release_mem_region(res->start, resource_size(res)); -failed_fbi: platform_set_drvdata(pdev, NULL); - kfree(fbi); failed: return ret; } @@ -434,7 +414,6 @@ failed: static int __devexit wm8505fb_remove(struct platform_device *pdev) { struct wm8505fb_info *fbi = platform_get_drvdata(pdev); - struct resource *res; device_remove_file(&pdev->dev, &dev_attr_contrast); @@ -445,13 +424,6 @@ static int __devexit wm8505fb_remove(struct platform_device *pdev) if (fbi->fb.cmap.len) fb_dealloc_cmap(&fbi->fb.cmap); - iounmap(fbi->regbase); - - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - release_mem_region(res->start, resource_size(res)); - - kfree(fbi); - return 0; }