dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tim Gardner <tim.gardner@canonical.com>
To: linux-kernel@vger.kernel.org
Cc: Tim Gardner <tim.gardner@canonical.com>,
	David Airlie <airlied@linux.ie>, Dave Airlie <airlied@redhat.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Zhao Yakui <yakui.zhao@intel.com>,
	David Howells <dhowells@redhat.com>,
	dri-devel@lists.freedesktop.org
Subject: [PATCH v2 3.7-rc8] ttm: Fix possible _manager memory allocation oops
Date: Fri,  7 Dec 2012 07:16:22 -0700	[thread overview]
Message-ID: <1354889782-16830-1-git-send-email-tim.gardner@canonical.com> (raw)
In-Reply-To: <CAPM=9tyENuyjNYdRZM0Z-tWZsQ5TnHadtByXWv7yNE0j0gwxpQ@mail.gmail.com>

Memory for _manager is allocated using kzalloc() but the result is not checked.

I was led to scrutinize ttm_page_alloc_init() from a smatch warning:

drivers/gpu/drm/ttm/ttm_page_alloc.c:799 ttm_page_alloc_init() error: potential null dereference '_manager'.  (kzalloc returns null)

Cc: David Airlie <airlied@linux.ie>
Cc: Dave Airlie <airlied@redhat.com>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Zhao Yakui <yakui.zhao@intel.com>
Cc: David Howells <dhowells@redhat.com>
Cc: dri-devel@lists.freedesktop.org
Cc: stable@vger.kernel.org # 3.5+
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
---

This patch applies to stable 3.5 and newer.

V2 - kobject_put(&_manager->kobj) uses a destructor and
container_of() to free _mamanger.

 drivers/gpu/drm/ttm/ttm_page_alloc.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index bd2a3b4..c64e96c 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -798,6 +798,10 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages)
 	pr_info("Initializing pool allocator\n");
 
 	_manager = kzalloc(sizeof(*_manager), GFP_KERNEL);
+	if (!_manager) {
+		pr_err("ttm: Could not allocate _manager.\n");
+		return -ENOMEM;
+	}
 
 	ttm_page_pool_init_locked(&_manager->wc_pool, GFP_HIGHUSER, "wc");
 
-- 
1.7.9.5

      reply	other threads:[~2012-12-07 14:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-06 16:20 [PATCH 3.7-rc8] ttm: Fix possible _manager memory allocation oops Tim Gardner
2012-12-06 22:46 ` Dave Airlie
2012-12-06 23:05   ` Tim Gardner
2012-12-07  5:59     ` Dave Airlie
2012-12-07 14:16       ` Tim Gardner [this message]

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=1354889782-16830-1-git-send-email-tim.gardner@canonical.com \
    --to=tim.gardner@canonical.com \
    --cc=airlied@linux.ie \
    --cc=airlied@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=yakui.zhao@intel.com \
    /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