diff mbox

drm/cirrus: fix error handling in cirrus_device_init()

Message ID CAPgLHd8v7oSuXuRwiMRJZQhW1UNHXwD-UtxFNMVW8LcP465xKA@mail.gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Yongjun July 28, 2013, 12:08 a.m. UTC
From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

Fix the error handling in function cirrus_device_init() to avoid resources
leak in the error handling case.

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 drivers/gpu/drm/cirrus/cirrus_main.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
diff mbox

Patch

diff --git a/drivers/gpu/drm/cirrus/cirrus_main.c b/drivers/gpu/drm/cirrus/cirrus_main.c
index 3a7a0ef..5f59bb0 100644
--- a/drivers/gpu/drm/cirrus/cirrus_main.c
+++ b/drivers/gpu/drm/cirrus/cirrus_main.c
@@ -138,17 +138,22 @@  int cirrus_device_init(struct cirrus_device *cdev,
 	}
 
 	cdev->rmmio = ioremap(cdev->rmmio_base, cdev->rmmio_size);
-
-	if (cdev->rmmio == NULL)
-		return -ENOMEM;
+	if (cdev->rmmio == NULL) {
+		ret = -ENOMEM;
+		goto err_ioremap;
+	}
 
 	ret = cirrus_vram_init(cdev);
-	if (ret) {
-		release_mem_region(cdev->rmmio_base, cdev->rmmio_size);
-		return ret;
-	}
+	if (ret)
+		goto err_init;
 
 	return 0;
+
+err_init:
+	iounmap(cdev->rmmio);
+err_ioremap:
+	release_mem_region(cdev->rmmio_base, cdev->rmmio_size);
+	return ret;
 }
 
 void cirrus_device_fini(struct cirrus_device *cdev)