[PATCH 2/2] thermal/drivers/mediatek: unmap foreign MMIO after probing
Icenowy Zheng
uwu at icenowy.me
Mon May 29 09:20:56 PDT 2023
The MMIO space from auxadc and apmixedsys devices are only needed when
initializing the thermal sensors, so these memory regions could be
safely unmapped after the probing process to prevent resource leak.
Unmap them at the end of the probe method, and route the unmap codepath
to early exits of the probe method for preventing leak when error
handling.
Signed-off-by: Icenowy Zheng <uwu at icenowy.me>
---
drivers/thermal/mediatek/auxadc_thermal.c | 32 ++++++++++++++++-------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c
index f59d36de20a0..c010a96f9aca 100644
--- a/drivers/thermal/mediatek/auxadc_thermal.c
+++ b/drivers/thermal/mediatek/auxadc_thermal.c
@@ -1229,13 +1229,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 out_unmap_auxadc;
}
apmixedsys = of_parse_phandle(np, "mediatek,apmixedsys", 0);
if (!apmixedsys) {
dev_err(&pdev->dev, "missing apmixedsys node\n");
- return -ENODEV;
+ ret = -ENODEV;
+ goto out_unmap_auxadc;
}
apmixed_base = of_iomap(apmixedsys, 0);
@@ -1245,25 +1247,26 @@ 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 out_unmap_apmixed;
}
ret = device_reset_optional(&pdev->dev);
if (ret)
- return ret;
+ goto out_unmap_apmixed;
mt->clk_auxadc = devm_clk_get_enabled(&pdev->dev, "auxadc");
if (IS_ERR(mt->clk_auxadc)) {
ret = PTR_ERR(mt->clk_auxadc);
dev_err(&pdev->dev, "Can't enable auxadc clk: %d\n", ret);
- return ret;
+ goto out_unmap_apmixed;
}
mt->clk_peri_therm = devm_clk_get_enabled(&pdev->dev, "therm");
if (IS_ERR(mt->clk_peri_therm)) {
ret = PTR_ERR(mt->clk_peri_therm);
dev_err(&pdev->dev, "Can't enable peri clk: %d\n", ret);
- return ret;
+ goto out_unmap_apmixed;
}
mtk_thermal_turn_on_buffer(mt, apmixed_base);
@@ -1287,14 +1290,23 @@ static int mtk_thermal_probe(struct platform_device *pdev)
tzdev = devm_thermal_of_zone_register(&pdev->dev, 0, mt,
&mtk_thermal_ops);
- if (IS_ERR(tzdev))
- return PTR_ERR(tzdev);
+ if (IS_ERR(tzdev)) {
+ ret = PTR_ERR(tzdev);
+ goto out_unmap_apmixed;
+ }
ret = devm_thermal_add_hwmon_sysfs(&pdev->dev, tzdev);
- if (ret)
+ if (ret) {
dev_warn(&pdev->dev, "error in thermal_add_hwmon_sysfs");
+ ret = 0;
+ }
- return 0;
+out_unmap_apmixed:
+ iounmap(apmixed_base);
+out_unmap_auxadc:
+ iounmap(auxadc_base);
+
+ return ret;
}
static struct platform_driver mtk_thermal_driver = {
--
2.39.1
More information about the Linux-mediatek
mailing list