lkml.org 
[lkml]   [2015]   [Apr]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 1/2] drm/qlx: Fix a memory leak on error path
Date
From: Oleg Drokin <green@linuxhacker.ru>

shadow allocation could be leaked if framebuffer allocation failed,
so need to free it.
Also added handling for shadow allocation failure itself instead
of causing a crash.

Found with smatch.

Signed-off-by: Oleg Drokin <green@linuxhacker.ru>
---
drivers/gpu/drm/qxl/qxl_fb.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/qxl/qxl_fb.c b/drivers/gpu/drm/qxl/qxl_fb.c
index f778c0e..2a88eae 100644
--- a/drivers/gpu/drm/qxl/qxl_fb.c
+++ b/drivers/gpu/drm/qxl/qxl_fb.c
@@ -526,8 +526,10 @@ static int qxlfb_create(struct qxl_fbdev *qfbdev,
mode_cmd.height, mode_cmd.pitches[0]);

shadow = vmalloc(mode_cmd.pitches[0] * mode_cmd.height);
- /* TODO: what's the usual response to memory allocation errors? */
- BUG_ON(!shadow);
+ if (!shadow) {
+ ret = -ENOMEM;
+ goto out_unref;
+ }
QXL_INFO(qdev,
"surface0 at gpu offset %lld, mmap_offset %lld (virt %p, shadow %p)\n",
qxl_bo_gpu_offset(qbo),
@@ -538,6 +540,7 @@ static int qxlfb_create(struct qxl_fbdev *qfbdev,

info = framebuffer_alloc(0, device);
if (info == NULL) {
+ vfree(shadow);
ret = -ENOMEM;
goto out_unref;
}
--
2.1.0


\
 
 \ /
  Last update: 2015-04-26 07:41    [W:0.118 / U:0.592 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site