From patchwork Thu Nov 22 06:42:08 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tushar Behera X-Patchwork-Id: 13062 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 F0FF023FC6 for ; Thu, 22 Nov 2012 06:48:32 +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 854CEA19D3C for ; Thu, 22 Nov 2012 06:48:32 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id c10so171152ieb.11 for ; Wed, 21 Nov 2012 22:48: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:in-reply-to:references :x-gm-message-state; bh=9w99KPahHq5nF+n52MypUnbbyROdxC9Ok4pQB1mSCZM=; b=D2byuuZvMF8JK6cEuPpNB3T1ls3mGxIjjmC0EkZ99ZND7OVSKu0KEK9ZIYYrjBF7b0 dDeVr9s1Y1vZRe26lNnprjNilrSouDwY7oU5YjBvK4wPGBjhe21M8/t++L5/Vk0Est3c y5spj9EwfeZtzwfUGNwmPfgtdd+ZwQ6l8iTrM4RMsr0jPXtUQP595FX7SHdQXk7Tf4y/ QXOHv7M4MyVK1Q4sa1mVz9mH4eDp3rPAsXhFTCm6FWZQanYwmXwUJkMxsHYhJrGuVZM2 sQicMRI+b59Fc/Gya2XI1wb0r1SwbvREnktg44EwROy/B3PSE6RstzdZMB53nLsmFsgT dlCQ== Received: by 10.43.7.132 with SMTP id oo4mr19594319icb.6.1353566911962; Wed, 21 Nov 2012 22:48:31 -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 n20csp164689igt; Wed, 21 Nov 2012 22:48:31 -0800 (PST) Received: by 10.66.87.163 with SMTP id az3mr24636435pab.62.1353566911186; Wed, 21 Nov 2012 22:48:31 -0800 (PST) Received: from mail-da0-f52.google.com (mail-da0-f52.google.com [209.85.210.52]) by mx.google.com with ESMTPS id xj3si3815113pbc.142.2012.11.21.22.48.31 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 21 Nov 2012 22:48:31 -0800 (PST) Received-SPF: neutral (google.com: 209.85.210.52 is neither permitted nor denied by best guess record for domain of tushar.behera@linaro.org) client-ip=209.85.210.52; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.52 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-f52.google.com with SMTP id f10so3969188dak.39 for ; Wed, 21 Nov 2012 22:48:30 -0800 (PST) Received: by 10.68.189.8 with SMTP id ge8mr2153498pbc.24.1353566910819; Wed, 21 Nov 2012 22:48:30 -0800 (PST) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id vn2sm1558688pbc.31.2012.11.21.22.48.26 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 21 Nov 2012 22:48: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 1/4] video: vt8500: Fix memory leak in probe function Date: Thu, 22 Nov 2012 12:12:08 +0530 Message-Id: <1353566531-31251-2-git-send-email-tushar.behera@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1353566531-31251-1-git-send-email-tushar.behera@linaro.org> References: <1353566531-31251-1-git-send-email-tushar.behera@linaro.org> X-Gm-Message-State: ALoCoQmxneOA2cr4YUJkrOmVM3raEwKsGlh7ZxdTVM+JADDHllr+OuNqKa7zri53aNwEqwFr7gJq In case of error in probe function, there is a possibility of either iounmap not getting called or memory allocated for fb_mem_virt not getting freed. Signed-off-by: Tushar Behera --- drivers/video/vt8500lcdfb.c | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/video/vt8500lcdfb.c b/drivers/video/vt8500lcdfb.c index 9af8da7..5777adc 100644 --- a/drivers/video/vt8500lcdfb.c +++ b/drivers/video/vt8500lcdfb.c @@ -350,7 +350,7 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev) if (!np) { pr_err("%s: No display description in Device Tree\n", __func__); ret = -EINVAL; - goto failed_free_res; + goto failed_free_io; } /* @@ -369,7 +369,7 @@ static int __devinit vt8500lcd_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_free_io; } of_mode.vmode = FB_VMODE_NONINTERLACED; @@ -379,7 +379,8 @@ static int __devinit vt8500lcd_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_free_io; }; fbi->fb.fix.smem_start = fb_mem_phys; @@ -394,7 +395,7 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev) if (fbi->palette_cpu == NULL) { dev_err(&pdev->dev, "Failed to allocate palette buffer\n"); ret = -ENOMEM; - goto failed_free_io; + goto failed_free_fbmem; } irq = platform_get_irq(pdev, 0); @@ -458,6 +459,9 @@ failed_free_irq: failed_free_palette: dma_free_coherent(&pdev->dev, fbi->palette_size, fbi->palette_cpu, fbi->palette_phys); +failed_free_fbmem: + dma_free_coherent(&pdev->dev, fbi->fb.fix.smem_len, + fbi->fb.screen_base, fbi->fb.fix.smem_start); failed_free_io: iounmap(fbi->regbase); failed_free_res: @@ -485,6 +489,10 @@ static int __devexit vt8500lcd_remove(struct platform_device *pdev) irq = platform_get_irq(pdev, 0); free_irq(irq, fbi); + if (fbi->fb.screen_base) + dma_free_coherent(&pdev->dev, fbi->fb.fix.smem_len, + fbi->fb.screen_base, fbi->fb.fix.smem_start); + dma_free_coherent(&pdev->dev, fbi->palette_size, fbi->palette_cpu, fbi->palette_phys);