From: Felix Gu <ustc.gu@gmail.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
Daniel Lezcano <daniel.lezcano@kernel.org>,
Zhang Rui <rui.zhang@intel.com>,
Lukasz Luba <lukasz.luba@arm.com>, Frank Li <Frank.Li@nxp.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
Oleksij Rempel <o.rempel@pengutronix.de>
Cc: linux-pm@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Felix Gu <ustc.gu@gmail.com>
Subject: [PATCH v2 1/2] thermal/drivers/imx: Fix thermal zone leak on probe error path
Date: Wed, 15 Apr 2026 21:10:27 +0800 [thread overview]
Message-ID: <20260415-imx-v2-1-aeacff9e72b2@gmail.com> (raw)
In-Reply-To: <20260415-imx-v2-0-aeacff9e72b2@gmail.com>
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
next prev parent reply other threads:[~2026-04-15 13:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 13:10 [PATCH v2 0/2] thermal/drivers/imx: two fixes Felix Gu
2026-04-15 13:10 ` Felix Gu [this message]
2026-04-16 13:04 ` [PATCH v2 1/2] thermal/drivers/imx: Fix thermal zone leak on probe error path 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260415-imx-v2-1-aeacff9e72b2@gmail.com \
--to=ustc.gu@gmail.com \
--cc=Frank.Li@nxp.com \
--cc=daniel.lezcano@kernel.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=o.rempel@pengutronix.de \
--cc=rafael@kernel.org \
--cc=rui.zhang@intel.com \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox