782684aacc683943e0223df0eab8943789ce7fa6
[openwrt/staging/ldir.git] /
1 From 458fa1d508de3f17e49d974a0158d9aeff273a58 Mon Sep 17 00:00:00 2001
2 From: Kang Chen <void0red@hust.edu.cn>
3 Date: Wed, 19 Apr 2023 10:07:48 +0800
4 Subject: [PATCH 18/42] thermal/drivers/mediatek: Use devm_of_iomap to avoid
5 resource leak in mtk_thermal_probe
6
7 Smatch reports:
8 1. mtk_thermal_probe() warn: 'apmixed_base' from of_iomap() not released.
9 2. mtk_thermal_probe() warn: 'auxadc_base' from of_iomap() not released.
10
11 The original code forgets to release iomap resource when handling errors,
12 fix it by switch to devm_of_iomap.
13
14 Fixes: 89945047b166 ("thermal: mediatek: Add tsensor support for V2 thermal system")
15 Signed-off-by: Kang Chen <void0red@hust.edu.cn>
16 Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
17 Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
18 Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
19 Link: https://lore.kernel.org/r/20230419020749.621257-1-void0red@hust.edu.cn
20 ---
21 drivers/thermal/mediatek/auxadc_thermal.c | 14 ++++++++++++--
22 1 file changed, 12 insertions(+), 2 deletions(-)
23
24 --- a/drivers/thermal/mediatek/auxadc_thermal.c
25 +++ b/drivers/thermal/mediatek/auxadc_thermal.c
26 @@ -1232,7 +1232,12 @@ static int mtk_thermal_probe(struct plat
27 return -ENODEV;
28 }
29
30 - auxadc_base = of_iomap(auxadc, 0);
31 + auxadc_base = devm_of_iomap(&pdev->dev, auxadc, 0, NULL);
32 + if (IS_ERR(auxadc_base)) {
33 + of_node_put(auxadc);
34 + return PTR_ERR(auxadc_base);
35 + }
36 +
37 auxadc_phys_base = of_get_phys_base(auxadc);
38
39 of_node_put(auxadc);
40 @@ -1248,7 +1253,12 @@ static int mtk_thermal_probe(struct plat
41 return -ENODEV;
42 }
43
44 - apmixed_base = of_iomap(apmixedsys, 0);
45 + apmixed_base = devm_of_iomap(&pdev->dev, apmixedsys, 0, NULL);
46 + if (IS_ERR(apmixed_base)) {
47 + of_node_put(apmixedsys);
48 + return PTR_ERR(apmixed_base);
49 + }
50 +
51 apmixed_phys_base = of_get_phys_base(apmixedsys);
52
53 of_node_put(apmixedsys);