From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 525BFC433F5 for ; Fri, 22 Apr 2022 09:00:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445692AbiDVJDB (ORCPT ); Fri, 22 Apr 2022 05:03:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229975AbiDVJC6 (ORCPT ); Fri, 22 Apr 2022 05:02:58 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C70F76252; Fri, 22 Apr 2022 02:00:05 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Kl7dj2HlxzQpZL; Fri, 22 Apr 2022 16:59:53 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 22 Apr 2022 17:00:04 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 22 Apr 2022 17:00:03 +0800 From: Yang Yingliang To: , CC: , Subject: [PATCH 01/20] hwmon: (abituguru) check return value after calling platform_get_resource() Date: Fri, 22 Apr 2022 17:11:48 +0800 Message-ID: <20220422091207.4034406-2-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220422091207.4034406-1-yangyingliang@huawei.com> References: <20220422091207.4034406-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It will cause null-ptr-deref if platform_get_resource() returns NULL, we need check the return value. Fixes: f2b84bbcebfd ("[PATCH] abituguru: New hardware monitoring driver") Signed-off-by: Yang Yingliang --- drivers/hwmon/abituguru.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c index 681f0623868f..58595567440c 100644 --- a/drivers/hwmon/abituguru.c +++ b/drivers/hwmon/abituguru.c @@ -1259,6 +1259,7 @@ static int abituguru_probe(struct platform_device *pdev) struct abituguru_data *data; int i, j, used, sysfs_names_free, sysfs_attr_i, res = -ENODEV; char *sysfs_filename; + struct resource *r; /* * El weirdo probe order, to keep the sysfs order identical to the @@ -1273,7 +1274,10 @@ static int abituguru_probe(struct platform_device *pdev) if (!data) return -ENOMEM; - data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start; + r = platform_get_resource(pdev, IORESOURCE_IO, 0); + if (!r) + return -EINVAL; + data->addr = r->start; mutex_init(&data->update_lock); platform_set_drvdata(pdev, data); -- 2.25.1