public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: green@linuxhacker.ru
To: David Airlie <airlied@linux.ie>, dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org (open list),
	kernel-janitors@vger.kernel.org,
	Oleg Drokin <green@linuxhacker.ru>
Subject: [PATCH 1/2] drm/qlx: Fix a memory leak on error path
Date: Sun, 26 Apr 2015 01:14:28 -0400	[thread overview]
Message-ID: <1430025269-26243-2-git-send-email-green@linuxhacker.ru> (raw)
In-Reply-To: <1430025269-26243-1-git-send-email-green@linuxhacker.ru>

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


  reply	other threads:[~2015-04-26  5:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-26  5:14 [PATCH 0/2] Fix a couple of dri drivers memory leaks green
2015-04-26  5:14 ` green [this message]
2015-04-26  5:14 ` [PATCH 2/2] drm: fix a memleak on mutex failure path green
2015-04-27  8:56   ` Jani Nikula
2015-04-27 15:36     ` Oleg Drokin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1430025269-26243-2-git-send-email-green@linuxhacker.ru \
    --to=green@linuxhacker.ru \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox