Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [PATCH] thermal/drivers/imx: drop the runtime PM reference on early error returns
@ 2026-11-29  6:44 Cong Nguyen
  2026-11-29  6:47 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Cong Nguyen @ 2026-11-29  6:44 UTC (permalink / raw)
  To: Rafael J . Wysocki, Daniel Lezcano
  Cc: Zhang Rui, Lukasz Luba, Frank Li, Sascha Hauer, Fabio Estevam,
	linux-pm, imx, linux-arm-kernel, linux-kernel

imx_get_temp() returns -EAGAIN and imx_set_trip_temp() returns -EINVAL
after taking a runtime PM reference, without dropping it. The usage count
stays raised, so the device can no longer runtime suspend.

Drop the reference before returning on those paths.

Fixes: 4cf2ddf16e17 ("thermal/drivers/imx: Implement runtime PM support")
Signed-off-by: Cong Nguyen <congnt264@gmail.com>
---
 drivers/thermal/imx_thermal.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index 1a57aa9dc900..3529b4a4cce1 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -266,8 +266,10 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
 
 	regmap_read(map, soc_data->temp_data, &val);
 
-	if ((val & soc_data->temp_valid_mask) == 0)
+	if ((val & soc_data->temp_valid_mask) == 0) {
+		pm_runtime_put(data->dev);
 		return -EAGAIN;
+	}
 
 	n_meas = (val & soc_data->temp_value_mask)
 		>> soc_data->temp_value_shift;
@@ -342,8 +344,10 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz,
 		return ret;
 
 	/* do not allow passive to be set higher than critical */
-	if (temp < 0 || temp > trips[IMX_TRIP_CRITICAL].temperature)
+	if (temp < 0 || temp > trips[IMX_TRIP_CRITICAL].temperature) {
+		pm_runtime_put(data->dev);
 		return -EINVAL;
+	}
 
 	imx_set_alarm_temp(data, temp);
 	trips[IMX_TRIP_PASSIVE].temperature = temp;
-- 
2.25.1


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

* Re: [PATCH] thermal/drivers/imx: drop the runtime PM reference on early error returns
  2026-11-29  6:44 [PATCH] thermal/drivers/imx: drop the runtime PM reference on early error returns Cong Nguyen
@ 2026-11-29  6:47 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-29  6:47 UTC (permalink / raw)
  To: Cong Nguyen; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] thermal/imx: double pm_runtime_put() in imx_thermal_probe() [1]
--

commit 7763b771c159bce40eb214229e69123499779dca
Author: Cong Nguyen <congnt264@gmail.com>

thermal/drivers/imx: drop the runtime PM reference on early error returns

This commit drops the runtime PM reference on data->dev before returning early
on error in imx_get_temp() and imx_set_trip_temp().

> diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
> index 1a57aa9dc9001..3529b4a4cce1e 100644
> --- a/drivers/thermal/imx_thermal.c
> +++ b/drivers/thermal/imx_thermal.c
> @@ -266,8 +266,10 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
>  
>  	regmap_read(map, soc_data->temp_data, &val);
>  
> -	if ((val & soc_data->temp_valid_mask) == 0)
> +	if ((val & soc_data->temp_valid_mask) == 0) {
> +		pm_runtime_put(data->dev);
>  		return -EAGAIN;
> +	}
>  
>  	n_meas = (val & soc_data->temp_value_mask)
>  		>> soc_data->temp_value_shift;
> @@ -342,8 +344,10 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz,
>  		return ret;
>  
>  	/* do not allow passive to be set higher than critical */
> -	if (temp < 0 || temp > trips[IMX_TRIP_CRITICAL].temperature)
> +	if (temp < 0 || temp > trips[IMX_TRIP_CRITICAL].temperature) {
> +		pm_runtime_put(data->dev);
>  		return -EINVAL;
> +	}
>  
>  	imx_set_alarm_temp(data, temp);
>  	trips[IMX_TRIP_PASSIVE].temperature = temp;

[Severity: High]
This problem wasn't introduced by this patch, but can imx_thermal_probe()
underflow the runtime PM usage counter on data->dev [1] if
pm_runtime_resume_and_get() fails?

drivers/thermal/imx_thermal.c:imx_thermal_probe() {
	...
	ret = pm_runtime_resume_and_get(data->dev);
	if (ret < 0)
		goto disable_runtime_pm;
	...
disable_runtime_pm:
	pm_runtime_put_noidle(data->dev);
	pm_runtime_disable(data->dev);
	...
}

pm_runtime_resume_and_get() already drops its usage reference on failure, so
jumping to disable_runtime_pm decrements the usage counter a second time.

[1] https://sashiko.dev/#/bug/linux-2ad226fd-def3-4ce1-8261-087d5f0a6696

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129064412.2874472-1-congnt264@gmail.com?part=1

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

end of thread, other threads:[~2026-11-29  6:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29  6:44 [PATCH] thermal/drivers/imx: drop the runtime PM reference on early error returns Cong Nguyen
2026-11-29  6:47 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox