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: 1787561 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 657723FC64 for ; Thu, 22 Nov 2012 20:13:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757002Ab2KVUNk (ORCPT ); Thu, 22 Nov 2012 15:13:40 -0500 Received: from mail-pa0-f46.google.com ([209.85.220.46]:48722 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753106Ab2KVUNj (ORCPT ); Thu, 22 Nov 2012 15:13:39 -0500 Received: by mail-pa0-f46.google.com with SMTP id bh2so3074432pad.19 for ; Thu, 22 Nov 2012 12:13:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=9w99KPahHq5nF+n52MypUnbbyROdxC9Ok4pQB1mSCZM=; b=a+bE10A5bJVxeiH1qEtlqNbZg1Vmj5LyprRFK5tK5wj6enj062ZUIu30ig1MwsU0/S PPYktf5cCHfby+G3ywGf3zkjRz0DNWaSUGHY0ljEdAcDxALu6K4Oums2DvU3/IUuah2H AhpO4ZQuYSxdwn8wnKyWR7uOUg6qQKc9K5EZbIiYidZf/dFyag1OY6Tu8tZT0xSuoLKf TUGDRZC06SKBK/fr5+PknC80Qmkof6zMEWniq9MeJg1lOd0ZYQ3lo7xqGh59oQHpeImk uNw3J8MUaMJvF/VTd/sEYHh4uX9Pg5yd88ptgPDB/vPf/01SSVygNfIntUjLqFjosvju l//Q== 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: ALoCoQmPJ7R3LAPp/9/s/nHfzIT36D1B9Y9fw4Js7lpxkNWEXgnpSfUZDseGtp5DH3xibwvLJ/cz Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org 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);