thermal/drivers/broadcom: Fix potential NULL dereference in sr_thermal_probe
authorZheng Yongjun <zhengyongjun3@huawei.com>
Mon, 25 Apr 2022 09:29:29 +0000 (09:29 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Jun 2022 08:23:01 +0000 (10:23 +0200)
[ Upstream commit e20d136ec7d6f309989c447638365840d3424c8e ]

platform_get_resource() may return NULL, add proper check to
avoid potential NULL dereferencing.

Fixes: 250e211057c72 ("thermal: broadcom: Add Stingray thermal driver")
Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
Link: https://lore.kernel.org/r/20220425092929.90412-1-zhengyongjun3@huawei.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/thermal/broadcom/sr-thermal.c

index 475ce2900771337f5398b21f406a3c9877324222..85ab9edd580cc7151824bcb1e1681e1d63a7259c 100644 (file)
@@ -60,6 +60,9 @@ static int sr_thermal_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res)
+               return -ENOENT;
+
        sr_thermal->regs = (void __iomem *)devm_memremap(&pdev->dev, res->start,
                                                         resource_size(res),
                                                         MEMREMAP_WB);