Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1163800AbdDXAeg (ORCPT ); Sun, 23 Apr 2017 20:34:36 -0400 Received: from m12-14.163.com ([220.181.12.14]:54761 "EHLO m12-14.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163783AbdDXAe3 (ORCPT ); Sun, 23 Apr 2017 20:34:29 -0400 From: Pan Bian To: =?UTF-8?q?Pali=20Roh=C3=A1r?= , Sebastian Reichel Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 1/1] power: Fix unchecked return value of devm_kzalloc Date: Mon, 24 Apr 2017 08:34:08 +0800 Message-Id: <1492994048-15733-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: DsCowADnHpMMSP1Y3ScUAg--.34498S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7GF4rAF4xKr4xGFWUCr48WFg_yoWfCwb_Za y8Ar97KryDur1UKr15KrWfZryFkryUur93Wan2qw1aqa47Gws8J34UZr15XwsrWayxCFZ8 AF90yFZ8ZFyxGjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUn1lk7UUUUU== X-Originating-IP: [106.120.213.67] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiVALCclUMAEhCbQACsa Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 870 Lines: 25 Function devm_kzalloc() will return a NULL pointer. However, in function isp1704_charger_probe(), the return value of devm_kzalloc() is directly used without validation. This may result in a bad memory access bug. Signed-off-by: Pan Bian --- drivers/power/supply/isp1704_charger.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/power/supply/isp1704_charger.c b/drivers/power/supply/isp1704_charger.c index 4cd6899..2f02463 100644 --- a/drivers/power/supply/isp1704_charger.c +++ b/drivers/power/supply/isp1704_charger.c @@ -418,6 +418,8 @@ static int isp1704_charger_probe(struct platform_device *pdev) pdata = devm_kzalloc(&pdev->dev, sizeof(struct isp1704_charger_data), GFP_KERNEL); + if (pdata) + goto fail0; pdata->enable_gpio = gpio; dev_info(&pdev->dev, "init gpio %d\n", pdata->enable_gpio); -- 1.9.1