[PATCH 3/3] thermal/drivers/qcom/tsens: Disable hardware on probe failure

From: Daniel Lezcano

Date: Wed Oct 21 2026 - 05:00:40 EST


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@xxxxxxxxxxxxxxxx>
Cc: Amit Kucheria <amitk@xxxxxxxxxx>
---
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