thermal/drivers/imx: two fixes
Subsystems (2)
v2 cover thermal/drivers/imx: two fixes
---
Changes in v2:
- Switch to use devm_thermal_of_zone_register() to fix Frank and Daniel's comment.
- Collect Frank's Reviewed-by tag for patch 2.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Felix Gu (2):
thermal/drivers/imx: Fix thermal zone leak on probe error path thermal/drivers/imxl:Fix runtime PM handling on early returns
drivers/thermal/imx_thermal.c | 49 ++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 24 deletions(-)
---
base-commit: 66672af7a095d89f082c5327f3b15bc2f93d558e
change-id: 20260411-imx-b022791ea1b9
Best regards,
Signature · 1 line
Felix Gu <[email protected]>
PATCH v2 1/2 thermal/drivers/imx: Fix thermal zone leak on probe error path
If pm_runtime_resume_and_get() fails after the thermal zone has been registered, the probe error path cleans up runtime PM but skips thermal_zone_device_unregister(), leaking the thermal zone device.
Switch to use devm_thermal_of_zone_register() to fix the problem.
--- drivers/thermal/imx_thermal.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)
drivers/thermal/imx_thermal.c +19 -16
@@ -216,6 +216,20 @@ struct imx_thermal_data {const char *temp_grade; }; +static int imx_thermal_sync_zone_trip (struct thermal_trip *trip,void *arg) +{ +struct imx_thermal_data *data = arg; +int temp; + +if (trip->type !=THERMAL_TRIP_PASSIVE && trip->type !=THERMAL_TRIP_CRITICAL ) +return 0 ; + + temp = trips[trip->type].temperature; +thermal_zone_set_trip_temp (data->tz, trip, temp); + +return 0 ; +} +static void imx_set_panic_temp (struct imx_thermal_data *data,int panic_temp) {
@@ -679,13 +693,8 @@ static int imx_thermal_probe(struct platform_device *pdev) goto legacy_cleanup; } - data->tz =thermal_zone_device_register_with_trips ("imx_thermal_zone" , - trips, -ARRAY_SIZE (trips), - data, - &imx_tz_ops,NULL , -IMX_PASSIVE_DELAY , -IMX_POLLING_DELAY ); + data->irq_enabled = true; + data->tz =devm_thermal_of_zone_register (dev,0 , data, &imx_tz_ops);if (IS_ERR (data->tz)) { ret =PTR_ERR (data->tz); dev_err(dev, "failed to register thermal zone device %d\n",
@@ -693,6 +702,8 @@ static int imx_thermal_probe(struct platform_device *pdev) goto clk_disable; } +thermal_zone_for_each_trip (data->tz, imx_thermal_sync_zone_trip, data); + dev_info(dev, "%s CPU temperature grade - max:%dC" " critical:%dC passive:%dC\n", data->temp_grade, data->temp_max / 1000, trips[IMX_TRIP_CRITICAL].temperature / 1000,
@@ -724,25 +735,18 @@ static int imx_thermal_probe(struct platform_device *pdev)if (ret <0 ) goto disable_runtime_pm; - data->irq_enabled = true; - ret =thermal_zone_device_enable (data->tz); -if (ret) - goto thermal_zone_unregister; - ret =devm_request_threaded_irq (dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread,0 ,"imx_thermal" , data);if (ret <0 ) {dev_err (dev,"failed to request alarm irq: %d\n" , ret); - goto thermal_zone_unregister; + goto disable_runtime_pm; }pm_runtime_put (data->dev);return 0 ; -thermal_zone_unregister: -thermal_zone_device_unregister (data->tz); disable_runtime_pm:pm_runtime_put_noidle (data->dev);pm_runtime_disable (data->dev);
@@ -761,7 +765,6 @@ static void imx_thermal_remove(struct platform_device *pdev)pm_runtime_put_noidle (data->dev);pm_runtime_disable (data->dev); -thermal_zone_device_unregister (data->tz);imx_thermal_unregister_legacy_cooling (data); }
Signature · 1 line
2.43.0
PATCH v2 2/2 thermal/drivers/imxl:Fix runtime PM handling on early returns
In reply to Felix GuUse PM_RUNTIME_ACQUIRE() in imx_get_temp() and imx_set_trip_temp() so runtime PM references are released correctly even when the functions return early on errors.
--- drivers/thermal/imx_thermal.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/thermal/imx_thermal.c +6 -8
@@ -274,8 +274,9 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)u32 val;int ret; - ret =pm_runtime_resume_and_get (data->dev); -if (ret <0 ) +PM_RUNTIME_ACQUIRE (data->dev, pm); + ret =PM_RUNTIME_ACQUIRE_ERR (&pm); +if (ret)return ret;regmap_read (map, soc_data->temp_data, &val);
@@ -316,8 +317,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)enable_irq (data->irq); } -pm_runtime_put (data->dev); -return 0 ; }
@@ -351,8 +350,9 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz,struct imx_thermal_data *data =thermal_zone_device_priv (tz);int ret; - ret =pm_runtime_resume_and_get (data->dev); -if (ret <0 ) +PM_RUNTIME_ACQUIRE (data->dev, pm); + ret =PM_RUNTIME_ACQUIRE_ERR (&pm); +if (ret)return ret;/* do not allow passive to be set higher than critical */
@@ -362,8 +362,6 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz,imx_set_alarm_temp (data, temp); trips[IMX_TRIP_PASSIVE ].temperature = temp; -pm_runtime_put (data->dev); -return 0 ; }
Signature · 1 line
2.43.0
Re: [PATCH v2 1/2] thermal/drivers/imx: Fix thermal zone leak on probe error path
In reply to Felix GuQuoted 100 lines · Felix Gu
If
pm_runtime_resume_and_get()fails after the thermal zone has been registered, the probe error path cleans up runtime PM but skipsthermal_zone_device_unregister(), leaking the thermal zone device.Switch to use
devm_thermal_of_zone_register()to fix the problem.Fixes 4cf2ddf16e17 ("thermal/drivers/imx: Implement runtime PM support")Signed-off-by Felix Gu <[email protected]>--- drivers/thermal/imx_thermal.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)drivers/thermal/imx_thermal.c +19
-17@@ -216,6 +216,20 @@ struct imx_thermal_data {const char *temp_grade; }; +static int imx_thermal_sync_zone_trip (struct thermal_trip *trip,void *arg) +{ +struct imx_thermal_data *data = arg; +int temp; + +if (trip->type !=THERMAL_TRIP_PASSIVE && trip->type !=THERMAL_TRIP_CRITICAL ) +return 0 ; + + temp = trips[trip->type].temperature; +thermal_zone_set_trip_temp (data->tz, trip, temp); + +return 0 ; +} +static void imx_set_panic_temp (struct imx_thermal_data *data,int panic_temp) {@@ -679,13 +693,8 @@ static int imx_thermal_probe(struct platform_device *pdev) goto legacy_cleanup; } - data->tz =thermal_zone_device_register_with_trips ("imx_thermal_zone" , - trips, -ARRAY_SIZE (trips), - data, - &imx_tz_ops,NULL , -IMX_PASSIVE_DELAY , -IMX_POLLING_DELAY ); + data->irq_enabled = true; + data->tz =devm_thermal_of_zone_register (dev,0 , data, &imx_tz_ops);if (IS_ERR (data->tz)) { ret =PTR_ERR (data->tz); dev_err(dev, "failed to register thermal zone device %d\n",@@ -693,6 +702,8 @@ static int imx_thermal_probe(struct platform_device *pdev) goto clk_disable; } +thermal_zone_for_each_trip (data->tz, imx_thermal_sync_zone_trip, data); + dev_info(dev, "%s CPU temperature grade - max:%dC" " critical:%dC passive:%dC\n", data->temp_grade, data->temp_max / 1000, trips[IMX_TRIP_CRITICAL].temperature / 1000,@@ -724,25 +735,18 @@ static int imx_thermal_probe(struct platform_device *pdev)if (ret <0 ) goto disable_runtime_pm; - data->irq_enabled = true; - ret =thermal_zone_device_enable (data->tz); -if (ret) - goto thermal_zone_unregister; - ret =devm_request_threaded_irq (dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread,0 ,"imx_thermal" , data);if (ret <0 ) {dev_err (dev,"failed to request alarm irq: %d\n" , ret); - goto thermal_zone_unregister; + goto disable_runtime_pm; }pm_runtime_put (data->dev);return 0 ; -thermal_zone_unregister: -thermal_zone_device_unregister (data->tz); disable_runtime_pm:pm_runtime_put_noidle (data->dev);pm_runtime_disable (data->dev);@@ -761,7 +765,6 @@ static void imx_thermal_remove(struct platform_device *pdev)pm_runtime_put_noidle (data->dev);pm_runtime_disable (data->dev); -thermal_zone_device_unregister (data->tz);imx_thermal_unregister_legacy_cooling (data); } --
Quoted 2 lines
2.43.0
Hi all,
This patch has a problem, I will fix it and send v3.
Best regards,
Felix
Frank Li
maintainerRe: [PATCH v2 1/2] thermal/drivers/imx: Fix thermal zone leak on probe error path
Quoted 1 line · Felix Gu
On Wed, Apr 15, 2026 at 9:10 PM Felix Gu <[email protected]> wrote:
...
Quoted 5 lines
Quoted 2 lines
2.43.0
Hi all,
This patch has a problem, I will fix it and send v3.
Next time trim context to let reviewer see important information before scoll down email.
Frank
Quoted 3 lines
Best regards,
Felix