Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1166644AbdDXIWU (ORCPT ); Mon, 24 Apr 2017 04:22:20 -0400 Received: from m12-11.163.com ([220.181.12.11]:36914 "EHLO m12-11.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758242AbdDXIWQ (ORCPT ); Mon, 24 Apr 2017 04:22:16 -0400 From: Pan Bian To: =?UTF-8?q?Pali=20Roh=C3=A1r?= , Sebastian Reichel , linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 1/1] power: Fix unchecked return value of devm_kzalloc Date: Mon, 24 Apr 2017 16:22:08 +0800 Message-Id: <1493022128-3918-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: C8CowABHxTmwtf1Y8sAlAg--.6082S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7GF4rAF4xKr4UAw4kWF43GFg_yoWfuwb_Za y8Ar97KryDur1UKr15trWfZryFkry7Zrn3Wan2qw1aqa47Gws8J34UZrn8XwsrWayxCFZ8 AF90yF9xZFyxtjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUn8hLUUUUUU== X-Originating-IP: [106.120.213.67] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiNhPDclWBV6tkFAAAsM Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 900 Lines: 27 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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/power/supply/isp1704_charger.c b/drivers/power/supply/isp1704_charger.c index 4cd6899..95af5f3 100644 --- a/drivers/power/supply/isp1704_charger.c +++ b/drivers/power/supply/isp1704_charger.c @@ -418,6 +418,10 @@ static int isp1704_charger_probe(struct platform_device *pdev) pdata = devm_kzalloc(&pdev->dev, sizeof(struct isp1704_charger_data), GFP_KERNEL); + if (!pdata) { + ret = -ENOMEM; + goto fail0; + } pdata->enable_gpio = gpio; dev_info(&pdev->dev, "init gpio %d\n", pdata->enable_gpio); -- 1.9.1