Skip to contentSkip to conversation

thermal: mediatek: Fix some leaks in mtk_thermal_probe

PATCH In review Miaoqian Lin 2 participants 2 messages Mar 7, 2022 – Mar 8, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: mediatek: Fix some leaks in mtk_thermal_probe

If an error occurs after a successful 'of_iomap()' call, it must be undone by a corresponding 'iounmap()' call

Fixes 89945047b166 ("thermal: mediatek: Add tsensor support for V2 thermal system")
---
 drivers/thermal/mtk_thermal.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/thermal/mtk_thermal.c +12 -5
index ede94eadddda..9d7461a5c2c1 100644
@@ -1035,13 +1035,15 @@ static int mtk_thermal_probe(struct platform_device *pdev)
 
 	if (auxadc_phys_base == OF_BAD_ADDR) {
 		dev_err(&pdev->dev, "Can't get auxadc phys address\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_umap_auxadc;
 	}
 
 	apmixedsys = of_parse_phandle(np, "mediatek,apmixedsys", 0);
 	if (!apmixedsys) {
 		dev_err(&pdev->dev, "missing apmixedsys node\n");
-		return -ENODEV;
+		ret = -ENODEV;
+		goto err_umap_auxadc;
 	}
 
 	apmixed_base = of_iomap(apmixedsys, 0);
@@ -1051,17 +1053,18 @@ static int mtk_thermal_probe(struct platform_device *pdev)
 
 	if (apmixed_phys_base == OF_BAD_ADDR) {
 		dev_err(&pdev->dev, "Can't get auxadc phys address\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto  err_umap_apmixed;
 	}
 
 	ret = device_reset_optional(&pdev->dev);
 	if (ret)
-		return ret;
+		goto err_umap_apmixed;
 
 	ret = clk_prepare_enable(mt->clk_auxadc);
 	if (ret) {
 		dev_err(&pdev->dev, "Can't enable auxadc clk: %d\n", ret);
-		return ret;
+		goto err_umap_apmixed;
 	}
 
 	ret = clk_prepare_enable(mt->clk_peri_therm);
@@ -1099,6 +1102,10 @@ static int mtk_thermal_probe(struct platform_device *pdev)
 	clk_disable_unprepare(mt->clk_peri_therm);
 err_disable_clk_auxadc:
 	clk_disable_unprepare(mt->clk_auxadc);
+err_umap_apmixed:
+	iounmap(apmixed_base);
+err_umap_auxadc:
+	iounmap(auxadc_base);
 
 	return ret;
 }
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Miaoqian,

Quoted 6 lines

If an error occurs after a successful 'of_iomap()' call, it must be undone by a corresponding 'iounmap()' call

Fixes 89945047b166 ("thermal: mediatek: Add tsensor support for V2 thermal system")

Thanks for fixing this.

Thanks,
Miles

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek