From patchwork Fri Dec 7 14:16:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1853131 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 D40443FC64 for ; Sat, 8 Dec 2012 18:53:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CE3D5E5F67 for ; Sat, 8 Dec 2012 10:53:54 -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 75FCEE6664 for ; Fri, 7 Dec 2012 06:16:48 -0800 (PST) Received: from salmon.rtg.net (mail.tpi.com [70.99.223.143]) by mail.tpi.com (Postfix) with ESMTP id 7E5ED32DB8F; Fri, 7 Dec 2012 06:16:43 -0800 (PST) Received: by salmon.rtg.net (Postfix, from userid 1000) id 26182217B2; Fri, 7 Dec 2012 07:16:43 -0700 (MST) From: Tim Gardner To: linux-kernel@vger.kernel.org Subject: [PATCH v2 3.7-rc8] ttm: Fix possible _manager memory allocation oops Date: Fri, 7 Dec 2012 07:16:22 -0700 Message-Id: <1354889782-16830-1-git-send-email-tim.gardner@canonical.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: X-Mailman-Approved-At: Sat, 08 Dec 2012 10:49:22 -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. 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. 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");