From patchwork Thu Dec 6 16:20:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1845871 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 897AA400ED for ; Thu, 6 Dec 2012 16:49:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 662BDE689E for ; Thu, 6 Dec 2012 08:49:33 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail.tpi.com (mail.tpi.com [70.99.223.143]) by gabe.freedesktop.org (Postfix) with ESMTP id D6C92E63E2 for ; Thu, 6 Dec 2012 08:20:25 -0800 (PST) Received: from salmon.rtg.net (mail.tpi.com [70.99.223.143]) by mail.tpi.com (Postfix) with ESMTP id 48D813320B4; Thu, 6 Dec 2012 08:20:17 -0800 (PST) Received: by salmon.rtg.net (Postfix, from userid 1000) id 09BA1217B2; Thu, 6 Dec 2012 09:20:16 -0700 (MST) From: Tim Gardner To: linux-kernel@vger.kernel.org Subject: [PATCH 3.7-rc8] ttm: Fix possible _manager memory allocation oops Date: Thu, 6 Dec 2012 09:20:06 -0700 Message-Id: <1354810806-81681-1-git-send-email-tim.gardner@canonical.com> X-Mailer: git-send-email 1.7.9.5 X-Mailman-Approved-At: Thu, 06 Dec 2012 08:49:20 -0800 Cc: "Paul E. McKenney" , dri-devel@lists.freedesktop.org, David Howells , Dave Airlie , Tim Gardner X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Memory for _manager is allocated using kzalloc() but the result is not checked. Free _manager on error lest memory become orphaned. 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 Cc: Dave Airlie Cc: "Paul E. McKenney" Cc: Zhao Yakui Cc: David Howells Cc: dri-devel@lists.freedesktop.org Cc: stable@vger.kernel.org # 3.5+ Signed-off-by: Tim Gardner --- This patch applies to stable 3.5 and newer. drivers/gpu/drm/ttm/ttm_page_alloc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index bd2a3b4..2c73d0a 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"); @@ -817,6 +821,7 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages) &glob->kobj, "pool"); if (unlikely(ret != 0)) { kobject_put(&_manager->kobj); + kfree(_manager); _manager = NULL; return ret; }