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 EA981C433EF for ; Fri, 22 Apr 2022 09:00:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445723AbiDVJDJ (ORCPT ); Fri, 22 Apr 2022 05:03:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445685AbiDVJC7 (ORCPT ); Fri, 22 Apr 2022 05:02:59 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43FD19FED; Fri, 22 Apr 2022 02:00:07 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Kl7dn39YmzhXZj; Fri, 22 Apr 2022 16:59:57 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500024.china.huawei.com (7.185.36.203) 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:05 +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:05 +0800 From: Yang Yingliang To: , CC: , Subject: [PATCH 05/20] hwmon: (f71882fg) check return value after calling platform_get_resource() Date: Fri, 22 Apr 2022 17:11:52 +0800 Message-ID: <20220422091207.4034406-6-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: 45fb366940d5 ("hwmon: add support for Fintek F71882FG and F71883FG") Signed-off-by: Yang Yingliang --- drivers/hwmon/f71882fg.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c index 938a8b9ec70d..33aec2a35e57 100644 --- a/drivers/hwmon/f71882fg.c +++ b/drivers/hwmon/f71882fg.c @@ -2336,13 +2336,17 @@ static int f71882fg_probe(struct platform_device *pdev) int err, i; int size; u8 start_reg, reg; + struct resource *res; data = devm_kzalloc(&pdev->dev, sizeof(struct f71882fg_data), GFP_KERNEL); if (!data) return -ENOMEM; - data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start; + res = platform_get_resource(pdev, IORESOURCE_IO, 0); + if (!res) + return -EINVAL; + data->addr = res->start; data->type = sio_data->type; data->temp_start = (data->type == f71858fg || data->type == f8000 || -- 2.25.1