All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] thermal/drivers/imx: two fixes
@ 2026-04-15 13:10 Felix Gu
  2026-04-15 13:10 ` [PATCH v2 1/2] thermal/drivers/imx: Fix thermal zone leak on probe error path Felix Gu
  2026-04-15 13:10 ` [PATCH v2 2/2] thermal/drivers/imxl:Fix runtime PM handling on early returns Felix Gu
  0 siblings, 2 replies; 5+ messages in thread
From: Felix Gu @ 2026-04-15 13:10 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Frank Li, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	Oleksij Rempel
  Cc: linux-pm, imx, linux-arm-kernel, linux-kernel, Felix Gu

Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
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/20260412-imx-v1-0-cc3b45d63811@gmail.com

---
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,
-- 
Felix Gu <ustc.gu@gmail.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] thermal/drivers/imx: Fix thermal zone leak on probe error path
  2026-04-15 13:10 [PATCH v2 0/2] thermal/drivers/imx: two fixes Felix Gu
@ 2026-04-15 13:10 ` Felix Gu
  2026-04-16 13:04   ` Felix Gu
  2026-04-15 13:10 ` [PATCH v2 2/2] thermal/drivers/imxl:Fix runtime PM handling on early returns Felix Gu
  1 sibling, 1 reply; 5+ messages in thread
From: Felix Gu @ 2026-04-15 13:10 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Frank Li, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	Oleksij Rempel
  Cc: linux-pm, imx, linux-arm-kernel, linux-kernel, 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 skips
thermal_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 <ustc.gu@gmail.com>
---
 drivers/thermal/imx_thermal.c | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index 38c993d1bcb3..3729c3eac748 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -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);
 }
 

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] thermal/drivers/imxl:Fix runtime PM handling on early returns
  2026-04-15 13:10 [PATCH v2 0/2] thermal/drivers/imx: two fixes Felix Gu
  2026-04-15 13:10 ` [PATCH v2 1/2] thermal/drivers/imx: Fix thermal zone leak on probe error path Felix Gu
@ 2026-04-15 13:10 ` Felix Gu
  1 sibling, 0 replies; 5+ messages in thread
From: Felix Gu @ 2026-04-15 13:10 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Frank Li, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	Oleksij Rempel
  Cc: linux-pm, imx, linux-arm-kernel, linux-kernel, Felix Gu

Use 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.

Fixes: 4cf2ddf16e17 ("thermal/drivers/imx: Implement runtime PM support")
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/thermal/imx_thermal.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index 3729c3eac748..057dbab70266 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -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;
 }
 

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] thermal/drivers/imx: Fix thermal zone leak on probe error path
  2026-04-15 13:10 ` [PATCH v2 1/2] thermal/drivers/imx: Fix thermal zone leak on probe error path Felix Gu
@ 2026-04-16 13:04   ` Felix Gu
  2026-04-17  8:16     ` Frank Li
  0 siblings, 1 reply; 5+ messages in thread
From: Felix Gu @ 2026-04-16 13:04 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Frank Li, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	Oleksij Rempel
  Cc: linux-pm, imx, linux-arm-kernel, linux-kernel

On Wed, Apr 15, 2026 at 9:10 PM Felix Gu <ustc.gu@gmail.com> wrote:
>
> 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.
>
> Fixes: 4cf2ddf16e17 ("thermal/drivers/imx: Implement runtime PM support")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
>  drivers/thermal/imx_thermal.c | 35 +++++++++++++++++++----------------
>  1 file changed, 19 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
> index 38c993d1bcb3..3729c3eac748 100644
> --- a/drivers/thermal/imx_thermal.c
> +++ b/drivers/thermal/imx_thermal.c
> @@ -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);
>  }
>
>
> --
> 2.43.0
>

Hi all,
This patch has a problem, I will fix it and send v3.

Best regards,
Felix

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] thermal/drivers/imx: Fix thermal zone leak on probe error path
  2026-04-16 13:04   ` Felix Gu
@ 2026-04-17  8:16     ` Frank Li
  0 siblings, 0 replies; 5+ messages in thread
From: Frank Li @ 2026-04-17  8:16 UTC (permalink / raw)
  To: Felix Gu
  Cc: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	Oleksij Rempel, linux-pm, imx, linux-arm-kernel, linux-kernel

On Thu, Apr 16, 2026 at 09:04:38PM +0800, Felix Gu wrote:
> On Wed, Apr 15, 2026 at 9:10 PM Felix Gu <ustc.gu@gmail.com> wrote:

...
> > 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

>
> Best regards,
> Felix

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-04-17  8:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-15 13:10 [PATCH v2 0/2] thermal/drivers/imx: two fixes Felix Gu
2026-04-15 13:10 ` [PATCH v2 1/2] thermal/drivers/imx: Fix thermal zone leak on probe error path Felix Gu
2026-04-16 13:04   ` Felix Gu
2026-04-17  8:16     ` Frank Li
2026-04-15 13:10 ` [PATCH v2 2/2] thermal/drivers/imxl:Fix runtime PM handling on early returns Felix Gu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.