830-v6.4-22-thermal-drivers-mediatek-Use-devm_of_iomap-to-avoid-.patch 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. From 458fa1d508de3f17e49d974a0158d9aeff273a58 Mon Sep 17 00:00:00 2001
  2. From: Kang Chen <[email protected]>
  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. Smatch reports:
  7. 1. mtk_thermal_probe() warn: 'apmixed_base' from of_iomap() not released.
  8. 2. mtk_thermal_probe() warn: 'auxadc_base' from of_iomap() not released.
  9. The original code forgets to release iomap resource when handling errors,
  10. fix it by switch to devm_of_iomap.
  11. Fixes: 89945047b166 ("thermal: mediatek: Add tsensor support for V2 thermal system")
  12. Signed-off-by: Kang Chen <[email protected]>
  13. Reviewed-by: Dongliang Mu <[email protected]>
  14. Reviewed-by: AngeloGioacchino Del Regno <[email protected]>
  15. Signed-off-by: Daniel Lezcano <[email protected]>
  16. Link: https://lore.kernel.org/r/[email protected]
  17. ---
  18. drivers/thermal/mediatek/auxadc_thermal.c | 14 ++++++++++++--
  19. 1 file changed, 12 insertions(+), 2 deletions(-)
  20. --- a/drivers/thermal/mediatek/auxadc_thermal.c
  21. +++ b/drivers/thermal/mediatek/auxadc_thermal.c
  22. @@ -1232,7 +1232,12 @@ static int mtk_thermal_probe(struct plat
  23. return -ENODEV;
  24. }
  25. - auxadc_base = of_iomap(auxadc, 0);
  26. + auxadc_base = devm_of_iomap(&pdev->dev, auxadc, 0, NULL);
  27. + if (IS_ERR(auxadc_base)) {
  28. + of_node_put(auxadc);
  29. + return PTR_ERR(auxadc_base);
  30. + }
  31. +
  32. auxadc_phys_base = of_get_phys_base(auxadc);
  33. of_node_put(auxadc);
  34. @@ -1248,7 +1253,12 @@ static int mtk_thermal_probe(struct plat
  35. return -ENODEV;
  36. }
  37. - apmixed_base = of_iomap(apmixedsys, 0);
  38. + apmixed_base = devm_of_iomap(&pdev->dev, apmixedsys, 0, NULL);
  39. + if (IS_ERR(apmixed_base)) {
  40. + of_node_put(apmixedsys);
  41. + return PTR_ERR(apmixed_base);
  42. + }
  43. +
  44. apmixed_phys_base = of_get_phys_base(apmixedsys);
  45. of_node_put(apmixedsys);