From patchwork Fri Nov 23 11:57:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tushar Behera X-Patchwork-Id: 13154 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id C314423DFE for ; Fri, 23 Nov 2012 12:03:33 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 530FFA180A7 for ; Fri, 23 Nov 2012 12:03:33 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id c10so1711916ieb.11 for ; Fri, 23 Nov 2012 04:03:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=IJ7c9tNhCh+4TxyukQ8nO7rnkNxt+F8UVHbuTF2MYJg=; b=BdXRNO0CUotZWPr7s7lgw4NMWrgBkVlLeI/OmKt+aj0fERMJD4hXMnw1vfAPR6OXrn mr2jfMNTnKD61xG0w5DwAW+2LlXKR72rWsa+mfKuxnxiE9XMOIzgLXYMIQqpxTfjJF6y K1wtK0DkwFlGT8kXGnBtBS6LAgvfXhKB5s6kP3a/ruxZH85L9mDIT5Ldw/GbZUYLnjrM mxql4oUp3OUwIUx8jTgTW9Sana6nuO+3v0j+2b9Eaj8ggk/R1IRQdGg+1RN/UBQoWFDS vfxUx0QKKv6JUU7Q63yHXnVzYbNJSZ8BJ/iWINmnYrLC8qL9uUxZD1Poyi6Xogg9UVzB z8kg== Received: by 10.50.186.199 with SMTP id fm7mr3200342igc.62.1353672212752; Fri, 23 Nov 2012 04:03:32 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp341962igt; Fri, 23 Nov 2012 04:03:32 -0800 (PST) Received: by 10.66.80.65 with SMTP id p1mr9945478pax.20.1353672212129; Fri, 23 Nov 2012 04:03:32 -0800 (PST) Received: from mail-da0-f51.google.com (mail-da0-f51.google.com [209.85.210.51]) by mx.google.com with ESMTPS id oi10si8276169pbb.188.2012.11.23.04.03.31 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 23 Nov 2012 04:03:32 -0800 (PST) Received-SPF: neutral (google.com: 209.85.210.51 is neither permitted nor denied by best guess record for domain of tushar.behera@linaro.org) client-ip=209.85.210.51; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.51 is neither permitted nor denied by best guess record for domain of tushar.behera@linaro.org) smtp.mail=tushar.behera@linaro.org Received: by mail-da0-f51.google.com with SMTP id i30so2121627dad.24 for ; Fri, 23 Nov 2012 04:03:31 -0800 (PST) Received: by 10.66.85.67 with SMTP id f3mr10073263paz.0.1353672211813; Fri, 23 Nov 2012 04:03:31 -0800 (PST) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id a10sm3611830paz.35.2012.11.23.04.03.28 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 23 Nov 2012 04:03:30 -0800 (PST) From: Tushar Behera To: linux-kernel@vger.kernel.org, linux-fbdev@vger.kernel.org Cc: FlorianSchandinat@gmx.de, linux@prisktech.co.nz, patches@linaro.org Subject: [PATCH] video: vt8505: Use devm_* APIs Date: Fri, 23 Nov 2012 17:27:13 +0530 Message-Id: <1353671833-14516-1-git-send-email-tushar.behera@linaro.org> X-Mailer: git-send-email 1.7.4.1 X-Gm-Message-State: ALoCoQl3LQjWQ7/NM9Pm2tUvpJ+MQFL1yWKE0y66rsc6AyFIlePi5nMmxEArupmTMaKbemCI1f8W Use devm_request_and_ioremap(), dmam_alloc_coherent() APIs to cleanup driver probe and remove functions. This also fixes a possible memory leak as the memory allocated by dma_alloc_coherent() was not getting freed up. Signed-off-by: Tushar Behera --- This patch has only been build tested. drivers/video/wm8505fb.c | 46 +++++++++------------------------------------- 1 files changed, 9 insertions(+), 37 deletions(-) diff --git a/drivers/video/wm8505fb.c b/drivers/video/wm8505fb.c index 77539c1..95539af 100644 --- a/drivers/video/wm8505fb.c +++ b/drivers/video/wm8505fb.c @@ -281,8 +281,7 @@ static int __devinit wm8505fb_probe(struct platform_device *pdev) sizeof(u32) * 16, GFP_KERNEL); if (!fbi) { dev_err(&pdev->dev, "Failed to initialize framebuffer device\n"); - ret = -ENOMEM; - goto failed; + return -ENOMEM; } strcpy(fbi->fb.fix.id, DRIVER_NAME); @@ -310,29 +309,19 @@ static int __devinit wm8505fb_probe(struct platform_device *pdev) 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; + return -ENODEV; } - 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; + dev_err(&pdev->dev, "failed to request and map I/O memory\n"); + return -EBUSY; } 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; + return -EINVAL; } /* @@ -351,7 +340,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; + return ret; } of_mode.vmode = FB_VMODE_NONINTERLACED; @@ -365,7 +354,7 @@ static int __devinit wm8505fb_probe(struct platform_device *pdev) /* try allocating the framebuffer */ fb_mem_len = of_mode.xres * of_mode.yres * 2 * (bpp / 8); - fb_mem_virt = dma_alloc_coherent(&pdev->dev, fb_mem_len, &fb_mem_phys, + fb_mem_virt = dmam_alloc_coherent(&pdev->dev, fb_mem_len, &fb_mem_phys, GFP_KERNEL); if (!fb_mem_virt) { pr_err("%s: Failed to allocate framebuffer\n", __func__); @@ -383,8 +372,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; + return -ENOMEM; } wm8505fb_init_hw(&fbi->fb); @@ -420,21 +408,12 @@ 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; } 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; }