From patchwork Tue Dec 17 05:07:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 22551 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f70.google.com (mail-pb0-f70.google.com [209.85.160.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5389F202E2 for ; Tue, 17 Dec 2013 05:08:04 +0000 (UTC) Received: by mail-pb0-f70.google.com with SMTP id rq2sf17902398pbb.1 for ; Mon, 16 Dec 2013 21:08:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=1F1dZ38YAxhuBlqCZDtCNBSPhMjPXsKbNSJNmx02t28=; b=LqNSmEB7v4u6mE1v9IHsf8w7MrgptX6QrH3E3iMzehxSHYUlzB18mOvQjaCboyM7nl 1pgz5R9WWLkQWVXf00FPl+SLHpGEYHnNnIyyF+ZBKvjUXXWhgF4M/OQ4/9PR73jfxcDX pM655RrIxvuLIn18CyYHuXtT/ecmiGZVAELOmddIrM19iFXSUBk7fxxRqWQ9ZAZtmm3X rOz7wbbI5BlqQOgWl3EWrZfKARKW8FiTQY+lrhnQAv92NXRsQE6BY3dS8IyfnzumdchO P5uXuThkcUx9D4yej+U8a3+DhChyPLxyNeGM0FzhojlgKA6HeFQDeO40S+EXwFnpKzSV HPpw== X-Gm-Message-State: ALoCoQmfBgDK4czYfDx56HbHIhqHTYrTtCegM0Aqtxeg+1SmTGaAnrz59KUYSKMlsFlh5ET37S6R X-Received: by 10.66.248.193 with SMTP id yo1mr10943940pac.6.1387256883426; Mon, 16 Dec 2013 21:08:03 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.94.41 with SMTP id cz9ls2485569qeb.57.gmail; Mon, 16 Dec 2013 21:08:03 -0800 (PST) X-Received: by 10.220.175.16 with SMTP id v16mr12113vcz.72.1387256883241; Mon, 16 Dec 2013 21:08:03 -0800 (PST) Received: from mail-vb0-f54.google.com (mail-vb0-f54.google.com [209.85.212.54]) by mx.google.com with ESMTPS id sx7si4537117vdc.81.2013.12.16.21.08.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 21:08:03 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.54 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.54; Received: by mail-vb0-f54.google.com with SMTP id g10so3749041vbg.41 for ; Mon, 16 Dec 2013 21:08:03 -0800 (PST) X-Received: by 10.58.117.7 with SMTP id ka7mr509205veb.44.1387256883154; Mon, 16 Dec 2013 21:08:03 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp43448vcz; Mon, 16 Dec 2013 21:08:02 -0800 (PST) X-Received: by 10.68.240.36 with SMTP id vx4mr24972008pbc.140.1387256882326; Mon, 16 Dec 2013 21:08:02 -0800 (PST) Received: from mail-pb0-f42.google.com (mail-pb0-f42.google.com [209.85.160.42]) by mx.google.com with ESMTPS id ez5si10691790pab.280.2013.12.16.21.08.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 21:08:02 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.42 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.160.42; Received: by mail-pb0-f42.google.com with SMTP id uo5so6468776pbc.15 for ; Mon, 16 Dec 2013 21:08:01 -0800 (PST) X-Received: by 10.68.191.106 with SMTP id gx10mr25031175pbc.47.1387256881901; Mon, 16 Dec 2013 21:08:01 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id oj6sm41996751pab.9.2013.12.16.21.08.00 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 21:08:01 -0800 (PST) From: John Stultz To: LKML Cc: John Stultz , Colin Cross , Greg KH , Android Kernel Team , kbuild test robot Subject: [PATCH 2/3] staging: ion: Fix possible null pointer dereference Date: Mon, 16 Dec 2013 21:07:52 -0800 Message-Id: <1387256873-21350-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1387256873-21350-1-git-send-email-john.stultz@linaro.org> References: <1387256873-21350-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.54 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The kbuild test robot reported: drivers/staging/android/ion/ion_system_heap.c:122 alloc_largest_available() error: potential null dereference 'info'. (kmalloc returns null) Where the pointer returned from kmalloc goes unchecked for failure. This patch checks the return for NULL, and reworks the logic, as suggested by Colin, so we allocate the page_info structure first. Cc: Colin Cross Cc: Greg KH Cc: Android Kernel Team Cc: kbuild test robot Reported-by: kbuild test robot Signed-off-by: John Stultz --- drivers/staging/android/ion/ion_system_heap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index 144b2272..7f07291 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -108,6 +108,10 @@ static struct page_info *alloc_largest_available(struct ion_system_heap *heap, struct page_info *info; int i; + info = kmalloc(sizeof(struct page_info), GFP_KERNEL); + if (!info) + return NULL; + for (i = 0; i < num_orders; i++) { if (size < order_to_size(orders[i])) continue; @@ -118,11 +122,12 @@ static struct page_info *alloc_largest_available(struct ion_system_heap *heap, if (!page) continue; - info = kmalloc(sizeof(struct page_info), GFP_KERNEL); info->page = page; info->order = orders[i]; return info; } + kfree(info); + return NULL; }