From: Oleg Drokin <gr...@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 <gr...@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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to