Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1044287AbdDWJEY (ORCPT ); Sun, 23 Apr 2017 05:04:24 -0400 Received: from m50-134.163.com ([123.125.50.134]:58927 "EHLO m50-134.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756237AbdDWJEN (ORCPT ); Sun, 23 Apr 2017 05:04:13 -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: check return value of devm_kzalloc Date: Sun, 23 Apr 2017 17:03:56 +0800 Message-Id: <1492938236-9928-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: DtGowADXViv9bfxY3eHoAA--.476S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrKr18XFy5Cw1UXrWDJr1UZFb_yoWfKwcEva y8urZ7KryDWr1UKr15K3yfZryFkr98Zrn3uanIqw1aqa47Gan8J34UZrn8XwsrWayxCFZ8 CF90yF9xZa4xKjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUjRpBDUUUUU== X-Originating-IP: [123.118.194.153] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBzwDCclaDt5hYeQAAsk Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 921 Lines: 26 Function devm_kzalloc() will return a NULL pointer if there is no enough memory. However, in function isp1704_charger_probe(), the return value of devm_kzalloc() is used without validation. This may result in a bad memory access bug. This patch fixes the 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..4dd2482 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) + return -ENOMEM; pdata->enable_gpio = gpio; dev_info(&pdev->dev, "init gpio %d\n", pdata->enable_gpio); -- 1.9.1