[PATCH] soc/tegra: fuse: fix possible null-ptr-deref in tegra_fuse_probe()

From: Yang Yingliang
Date: Thu May 05 2022 - 05:25:58 EST


It will cause null-ptr-deref when using 'res', if platform_get_resource()
returns NULL, so move using 'res' after devm_ioremap_resource() that
will check it to avoid null-ptr-deref.
And use devm_platform_get_and_ioremap_resource() to simplify code.

Fixes: 55a042b3f68f ("soc/tegra: fuse: Fix reading registers using DMA on Tegra20")
Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx>
---
drivers/soc/tegra/fuse/fuse-tegra.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
index aa94fda282f4..e85a78a80c48 100644
--- a/drivers/soc/tegra/fuse/fuse-tegra.c
+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
@@ -218,13 +218,12 @@ static int tegra_fuse_probe(struct platform_device *pdev)
return err;

/* take over the memory region from the early initialization */
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- fuse->phys = res->start;
- fuse->base = devm_ioremap_resource(&pdev->dev, res);
+ fuse->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
if (IS_ERR(fuse->base)) {
err = PTR_ERR(fuse->base);
return err;
}
+ fuse->phys = res->start;

fuse->clk = devm_clk_get(&pdev->dev, "fuse");
if (IS_ERR(fuse->clk)) {
--
2.25.1