* [PATCH 1/3] thermal/drivers/qcom/tsens: Release parent resources on probe failure
@ 2026-10-21 8:57 Daniel Lezcano
2026-10-21 8:57 ` [PATCH 2/3] thermal/drivers/qcom/tsens: Validate the sensor count before initialization Daniel Lezcano
2026-10-21 8:57 ` [PATCH 3/3] thermal/drivers/qcom/tsens: Disable hardware on probe failure Daniel Lezcano
0 siblings, 2 replies; 4+ messages in thread
From: Daniel Lezcano @ 2026-10-21 8:57 UTC (permalink / raw)
To: daniel.lezcano
Cc: andersson, Rajendra Nayak, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
open list:QUALCOMM TSENS THERMAL DRIVER,
open list:QUALCOMM TSENS THERMAL DRIVER, open list
On legacy MSM8960/APQ8064 device trees without a separate TSENS child
node, the Global Clock Controller (GCC) driver creates a qcom-tsens
platform device without an OF node. TSENS consequently uses the parent
device for firmware lookups and managed resource allocations.
If probing fails, including calibration returning -EPROBE_DEFER, the
driver core releases only the child device's managed resources.
Allocations attached to the parent remain, accumulating across repeated
probe attempts.
Wrap the parent-bound allocations in a devres group and register a
cleanup action on the TSENS child. This releases the resources on probe
failure and unbind while preserving legacy firmware lookups. Keep the
group handling in a probe wrapper so the existing initialization path
remains self-contained.
Fixes: 9066073c6c27 ("thermal: qcom: tsens: Add a skeletal TSENS drivers")
Closes: https://sashiko.dev/#/bug/linux-7dc6dad0-c471-47ca-b493-8402752cf13a
Signed-off-by: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
Cc: Rajendra Nayak <rajendra.nayak@oss.qualcomm.com>
---
drivers/thermal/qcom/tsens.c | 37 +++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index b5ec70201e2f..4f69ce4976d9 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -1374,7 +1374,7 @@ static int tsens_register(struct tsens_priv *priv)
return ret;
}
-static int tsens_probe(struct platform_device *pdev)
+static int tsens_probe_common(struct platform_device *pdev)
{
int ret, i;
struct device *dev;
@@ -1452,6 +1452,41 @@ static int tsens_probe(struct platform_device *pdev)
return ret;
}
+static void tsens_release_resources(void *data)
+{
+ struct device *dev = data;
+
+ devres_release_group(dev->parent, dev);
+}
+
+static int tsens_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ int ret;
+
+ /*
+ * DT-backed devices own their managed resources directly. Legacy devices
+ * created by the Global Clock Controller (GCC) driver have no OF node and
+ * use the parent's firmware data and managed resources instead. Group
+ * those resources so the child releases them on probe failure or unbind.
+ */
+ if (dev->of_node)
+ return tsens_probe_common(pdev);
+
+ /* Tie resources allocated on the parent to the TSENS lifetime. */
+ if (!devres_open_group(dev->parent, dev, GFP_KERNEL))
+ return -ENOMEM;
+
+ ret = devm_add_action_or_reset(dev, tsens_release_resources, dev);
+ if (ret)
+ return ret;
+
+ ret = tsens_probe_common(pdev);
+ devres_close_group(dev->parent, dev);
+
+ return ret;
+}
+
static void tsens_remove(struct platform_device *pdev)
{
struct tsens_priv *priv = platform_get_drvdata(pdev);
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 2/3] thermal/drivers/qcom/tsens: Validate the sensor count before initialization
2026-10-21 8:57 [PATCH 1/3] thermal/drivers/qcom/tsens: Release parent resources on probe failure Daniel Lezcano
@ 2026-10-21 8:57 ` Daniel Lezcano
2026-10-21 8:57 ` [PATCH 3/3] thermal/drivers/qcom/tsens: Disable hardware on probe failure Daniel Lezcano
1 sibling, 0 replies; 4+ messages in thread
From: Daniel Lezcano @ 2026-10-21 8:57 UTC (permalink / raw)
To: daniel.lezcano
Cc: andersson, Amit Kucheria, Thara Gopinath, Rafael J. Wysocki,
Daniel Lezcano, Zhang Rui, Lukasz Luba,
open list:ARM/QUALCOMM MAILING LIST,
open list:QUALCOMM TSENS THERMAL DRIVER, open list
The #qcom,sensors property can override the platform sensor count without
an upper-bound check. A count exceeding the IP's maximum causes the
driver to access uninitialized regmap fields when handling interrupts.
Platforms with an explicit hardware-ID table can also read beyond that
table, even when the count remains within the IP's hardware limit.
Reject zero counts and counts exceeding the hardware maximum or, when
present, the hardware-ID table length before allocating the private
structure and assigning sensor IDs. Preserve the existing fallback to
the platform default when the property cannot be read, and document
both the fallback and the sensor-count limits.
Fixes: 6d7c70d1cd65 ("thermal: qcom: tsens: Allow number of sensors to come from DT")
Closes: https://sashiko.dev/#/bug/linux-d0867095-c131-491e-a6aa-a81debfd0df5
Signed-off-by: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
Cc: Bjorn Andersson <andersson@kernel.org>
---
drivers/thermal/qcom/tsens.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index 4f69ce4976d9..9134637a3458 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -1399,10 +1399,20 @@ static int tsens_probe_common(struct platform_device *pdev)
num_sensors = data->num_sensors;
+ /*
+ * DT may override the platform sensor count. A missing, empty or too
+ * short property leaves num_sensors unchanged, retaining the default.
+ */
if (np)
of_property_read_u32(np, "#qcom,sensors", &num_sensors);
- if (num_sensors <= 0) {
+ /*
+ * Require at least one sensor and stay within the IP's hardware limit.
+ * Platforms with an explicit hardware-ID table also limit the count to
+ * its number of entries, which may be smaller than the hardware limit.
+ */
+ if (!num_sensors || num_sensors > data->feat->max_sensors ||
+ (data->hw_ids && num_sensors > data->num_sensors)) {
dev_err(dev, "%s: invalid number of sensors\n", __func__);
return -EINVAL;
}
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 3/3] thermal/drivers/qcom/tsens: Disable hardware on probe failure
2026-10-21 8:57 [PATCH 1/3] thermal/drivers/qcom/tsens: Release parent resources on probe failure Daniel Lezcano
2026-10-21 8:57 ` [PATCH 2/3] thermal/drivers/qcom/tsens: Validate the sensor count before initialization Daniel Lezcano
@ 2026-10-21 8:57 ` Daniel Lezcano
2026-10-21 10:27 ` Konrad Dybcio
1 sibling, 1 reply; 4+ messages in thread
From: Daniel Lezcano @ 2026-10-21 8:57 UTC (permalink / raw)
To: daniel.lezcano
Cc: andersson, Amit Kucheria, Thara Gopinath, Rafael J. Wysocki,
Daniel Lezcano, Zhang Rui, Lukasz Luba,
open list:ARM/QUALCOMM MAILING LIST,
open list:QUALCOMM TSENS THERMAL DRIVER, open list
Hardware initialization enables TSENS interrupts before calibration and
thermal zone and IRQ registration have completed. If calibration or
registration fails, probe returns without disabling the hardware. Devres
then releases any registered IRQ handlers, leaving the interrupt source
enabled without a handler.
Factor the hardware shutdown sequence out of the remove callback and
invoke it when calibration or registration fails after successful
initialization. Disable hardware interrupts and call the optional sensor
disable callback before devres releases IRQ handlers and register maps.
Fixes: 634e11d5b450 ("drivers: thermal: tsens: Add interrupt support")
Closes: https://sashiko.dev/#/bug/linux-4b873699-7a0d-46e9-b768-169916c70d1d
Signed-off-by: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
Cc: Amit Kucheria <amitk@kernel.org>
---
drivers/thermal/qcom/tsens.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index 9134637a3458..57d71159bd4b 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -1374,6 +1374,13 @@ static int tsens_register(struct tsens_priv *priv)
return ret;
}
+static void tsens_disable(struct tsens_priv *priv)
+{
+ tsens_disable_irq(priv);
+ if (priv->ops->disable)
+ priv->ops->disable(priv);
+}
+
static int tsens_probe_common(struct platform_device *pdev)
{
int ret, i;
@@ -1450,15 +1457,22 @@ static int tsens_probe_common(struct platform_device *pdev)
if (priv->ops->calibrate) {
ret = priv->ops->calibrate(priv);
- if (ret < 0)
- return dev_err_probe(dev, ret, "%s: calibration failed\n",
- __func__);
+ if (ret < 0) {
+ dev_err_probe(dev, ret, "%s: calibration failed\n", __func__);
+ goto err_disable;
+ }
}
ret = tsens_register(priv);
- if (!ret)
- tsens_debug_init(pdev);
+ if (ret)
+ goto err_disable;
+
+ tsens_debug_init(pdev);
+ return 0;
+err_disable:
+ /* Stop hardware events before devres releases IRQs and register maps. */
+ tsens_disable(priv);
return ret;
}
@@ -1502,9 +1516,7 @@ static void tsens_remove(struct platform_device *pdev)
struct tsens_priv *priv = platform_get_drvdata(pdev);
debugfs_remove_recursive(priv->debug_root);
- tsens_disable_irq(priv);
- if (priv->ops->disable)
- priv->ops->disable(priv);
+ tsens_disable(priv);
}
static struct platform_driver tsens_driver = {
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 3/3] thermal/drivers/qcom/tsens: Disable hardware on probe failure
2026-10-21 8:57 ` [PATCH 3/3] thermal/drivers/qcom/tsens: Disable hardware on probe failure Daniel Lezcano
@ 2026-10-21 10:27 ` Konrad Dybcio
0 siblings, 0 replies; 4+ messages in thread
From: Konrad Dybcio @ 2026-10-21 10:27 UTC (permalink / raw)
To: Daniel Lezcano
Cc: andersson, Amit Kucheria, Thara Gopinath, Rafael J. Wysocki,
Daniel Lezcano, Zhang Rui, Lukasz Luba,
open list:ARM/QUALCOMM MAILING LIST,
open list:QUALCOMM TSENS THERMAL DRIVER, open list
On 10/21/26 10:57 AM, Daniel Lezcano wrote:
> Hardware initialization enables TSENS interrupts before calibration and
> thermal zone and IRQ registration have completed. If calibration or
> registration fails, probe returns without disabling the hardware. Devres
> then releases any registered IRQ handlers, leaving the interrupt source
> enabled without a handler.
>
> Factor the hardware shutdown sequence out of the remove callback and
> invoke it when calibration or registration fails after successful
> initialization. Disable hardware interrupts and call the optional sensor
> disable callback before devres releases IRQ handlers and register maps.
>
> Fixes: 634e11d5b450 ("drivers: thermal: tsens: Add interrupt support")
> Closes: https://sashiko.dev/#/bug/linux-4b873699-7a0d-46e9-b768-169916c70d1d
> Signed-off-by: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
> Cc: Amit Kucheria <amitk@kernel.org>
> ---
Acked-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Konrad
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-21 10:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 8:57 [PATCH 1/3] thermal/drivers/qcom/tsens: Release parent resources on probe failure Daniel Lezcano
2026-10-21 8:57 ` [PATCH 2/3] thermal/drivers/qcom/tsens: Validate the sensor count before initialization Daniel Lezcano
2026-10-21 8:57 ` [PATCH 3/3] thermal/drivers/qcom/tsens: Disable hardware on probe failure Daniel Lezcano
2026-10-21 10:27 ` Konrad Dybcio
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®