From patchwork Wed Sep 30 12:36:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 54326 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by patches.linaro.org (Postfix) with ESMTPS id 90F5C22E23 for ; Wed, 30 Sep 2015 12:36:43 +0000 (UTC) Received: by labjc2 with SMTP id jc2sf12412889lab.1 for ; Wed, 30 Sep 2015 05:36:42 -0700 (PDT) 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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=FC/Ylx3r5Q4w3N/jnkFkRCqtizYS2Lnzc3mIThjhk3I=; b=gPw0oMCINgItHOy46j9EmpksDZp9xdubiw6YbWdF1Par66kEJm3al+g8mvFiaeLB3w t7tB9Weo9N2bNsgdICg+oWRC45CbBXDNN+axo5YGcm0XxL7VaEngFQNkSvE3Kb3X+dGD MWlS4XfGw7T8mApvXE/xdjzV3L53jF1NvORVDW+S9bC+fhHXe+Cj7ETBBpmsK6bJnLNk Ws4rKIki4Vkyz8ZW6kYWGzzqCQpN8km76FlkZDhb9k64UCDRa6HJzfdNsRDO2L+3JgEg NSQN7fvScVWoa5fI0XHWvrfCu8UnIRZkstxg2KdDLEhZ0rCdvGa0rfBW5QJrCdv3pmAI WS2A== X-Gm-Message-State: ALoCoQnwgIWpW6mjq+hPkOjItXiy6JK5qaigIu1o/md70QLJ5/f64jThumHI9prAPXbQ5ndcc4Iy X-Received: by 10.112.89.228 with SMTP id br4mr497334lbb.3.1443616602370; Wed, 30 Sep 2015 05:36:42 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.210.198 with SMTP id j189ls35521lfg.86.gmail; Wed, 30 Sep 2015 05:36:42 -0700 (PDT) X-Received: by 10.25.159.16 with SMTP id i16mr663516lfe.63.1443616602073; Wed, 30 Sep 2015 05:36:42 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id i8si191648lam.54.2015.09.30.05.36.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Sep 2015 05:36:42 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by lahh2 with SMTP id h2so44221434lah.0 for ; Wed, 30 Sep 2015 05:36:41 -0700 (PDT) X-Received: by 10.112.129.202 with SMTP id ny10mr1003242lbb.112.1443616601880; Wed, 30 Sep 2015 05:36:41 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2729456lbq; Wed, 30 Sep 2015 05:36:40 -0700 (PDT) X-Received: by 10.107.170.37 with SMTP id t37mr4109124ioe.166.1443616600717; Wed, 30 Sep 2015 05:36:40 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 28si406778iod.44.2015.09.30.05.36.40; Wed, 30 Sep 2015 05:36:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932726AbbI3Mgi (ORCPT + 30 others); Wed, 30 Sep 2015 08:36:38 -0400 Received: from mail-wi0-f174.google.com ([209.85.212.174]:36245 "EHLO mail-wi0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755491AbbI3Mgg (ORCPT ); Wed, 30 Sep 2015 08:36:36 -0400 Received: by wicgb1 with SMTP id gb1so193146896wic.1 for ; Wed, 30 Sep 2015 05:36:35 -0700 (PDT) X-Received: by 10.180.88.37 with SMTP id bd5mr33428452wib.82.1443616594665; Wed, 30 Sep 2015 05:36:34 -0700 (PDT) Received: from localhost.localdomain (host-92-13-246-184.as43234.net. [92.13.246.184]) by smtp.gmail.com with ESMTPSA id bs8sm401283wjc.47.2015.09.30.05.36.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Sep 2015 05:36:34 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: maxime.ripard@free-electrons.com, linux-kernel@vger.kernel.org, srinivas.kandagatla@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/4] nvmem: sunxi: Check for memory allocation failure Date: Wed, 30 Sep 2015 13:36:31 +0100 Message-Id: <1443616591-17867-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1443616298-17389-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1443616298-17389-1-git-send-email-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: srinivas.kandagatla@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Maxime Ripard The sunxi_sid driver doesn't check for kmalloc return status before derefencing the returned pointer, which could lead to a NULL pointer dereference if kmalloc failed. Check for its return code to make sure it deosn't happen. Reported-by: Dan Carpenter Signed-off-by: Maxime Ripard --- drivers/nvmem/sunxi_sid.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c index 14777dd..cfa3b85 100644 --- a/drivers/nvmem/sunxi_sid.c +++ b/drivers/nvmem/sunxi_sid.c @@ -103,7 +103,7 @@ static int sunxi_sid_probe(struct platform_device *pdev) struct nvmem_device *nvmem; struct regmap *regmap; struct sunxi_sid *sid; - int i, size; + int ret, i, size; char *randomness; sid = devm_kzalloc(dev, sizeof(*sid), GFP_KERNEL); @@ -131,6 +131,11 @@ static int sunxi_sid_probe(struct platform_device *pdev) return PTR_ERR(nvmem); randomness = kzalloc(sizeof(u8) * size, GFP_KERNEL); + if (!randomness) { + ret = -EINVAL; + goto err_unreg_nvmem; + } + for (i = 0; i < size; i++) randomness[i] = sunxi_sid_read_byte(sid, i); @@ -140,6 +145,10 @@ static int sunxi_sid_probe(struct platform_device *pdev) platform_set_drvdata(pdev, nvmem); return 0; + +err_unreg_nvmem: + nvmem_unregister(nvmem); + return ret; } static int sunxi_sid_remove(struct platform_device *pdev)