Patchwork TILER: Corrrect PAT array allocation error handling

login
register
mail settings
Submitter Sin, David
Date July 14, 2010, 4:01 p.m.
Message ID <513FF747EED39B4AADBB4D6C9D9F9F7903D6103FCE@dlee02.ent.ti.com>
Download mbox | patch
Permalink /patch/58972/
State Accepted
Delegated to: Tim Gardner
Headers show

Comments

Sin, David - July 14, 2010, 4:01 p.m.
Bryan,
Can you please review this patch?  This patch fixes resource leaks if dma_alloc_coherent fails during TILER init.

Thanks for your input.

-David


From ba6db483a22314f1e5fd7227158213ca9eaa94e9 Mon Sep 17 00:00:00 2001
From: David Sin <davidsin@ti.com>
Date: Wed, 14 Jul 2010 10:47:07 -0500
Subject: [PATCH] TILER: Corrrect PAT array allocation error handling

Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
Signed-off-by: David Sin <davidsin@ti.com>
---
 drivers/media/video/tiler/tiler.c |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)

Patch

diff --git a/drivers/media/video/tiler/tiler.c b/drivers/media/video/tiler/tiler.c
index 3b6cef3..2b8292d 100644
--- a/drivers/media/video/tiler/tiler.c
+++ b/drivers/media/video/tiler/tiler.c
@@ -1486,6 +1486,15 @@  static s32 __init tiler_init(void)
 	struct tcm *sita = NULL;
 	struct tmm *tmm_pat = NULL;
 
+	/**
+	  * Array of physical pages for PAT programming, which must be a 16-byte
+	  * aligned physical address
+	*/
+	dmac_va = dma_alloc_coherent(NULL, TILER_WIDTH * TILER_HEIGHT *
+					sizeof(*dmac_va), &dmac_pa, GFP_ATOMIC);
+	if (!dmac_va)
+		return -ENOMEM;
+
 	/* Allocate tiler container manager (we share 1 on OMAP4) */
 	div_pt.x = TILER_WIDTH;   /* hardcoded default */
 	div_pt.y = (3 * TILER_HEIGHT) / 4;
@@ -1503,15 +1512,6 @@  static s32 __init tiler_init(void)
 	TMM_SET(TILFMT_32BIT, tmm_pat);
 	TMM_SET(TILFMT_PAGE, tmm_pat);
 
-	/**
-	  * Array of physical pages for PAT programming, which must be a 16-byte
-	  * aligned physical address
-	*/
-	dmac_va = dma_alloc_coherent(NULL, TILER_WIDTH * TILER_HEIGHT *
-					sizeof(*dmac_va), &dmac_pa, GFP_ATOMIC);
-	if (!dmac_va)
-		return -ENOMEM;
-
 	tiler_device = kmalloc(sizeof(*tiler_device), GFP_KERNEL);
 	if (!tiler_device || !sita || !tmm_pat) {
 		r = -ENOMEM;
@@ -1561,6 +1561,8 @@  error:
 		kfree(tiler_device);
 		tcm_deinit(sita);
 		tmm_deinit(tmm_pat);
+		dma_free_coherent(NULL, TILER_WIDTH * TILER_HEIGHT *
+					sizeof(*dmac_va), dmac_va, dmac_pa);
 	}
 
 	return r;