mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yaohan Li <shunsheng1218@gmail.com>
To: rafael@kernel.org, daniel.lezcano@kernel.org
Cc: rui.zhang@intel.com, lukasz.luba@arm.com,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] thermal: db8500: register the zone before requesting the interrupts
Date: Tue, 17 Nov 2026 22:53:31 +0800	[thread overview]
Message-ID: <20261117145331.1092458-1-shunsheng1218@gmail.com> (raw)

Both threaded handlers call thermal_zone_device_update(th->tz, ...), but
the thermal zone is registered last, after both
devm_request_threaded_irq() calls.

That leaves two windows.  During probe an interrupt can be served while
th->tz is still NULL or holds an error pointer.  On removal devres runs
in reverse order, so the zone is unregistered and freed before the two
IRQs are released, and a handler that the hardirq has already woken can
then operate on a freed thermal_zone_device.

Register the zone first and request the interrupts afterwards, so devres
releases the IRQs before the zone.

Stopping the PRCMU measurement from .remove() would not be enough on its
own: db8500_thermal_update_config(), which both handlers call, stops the
sensing and starts it again, so a handler still running when .remove()
returns restarts it.  Register the stop as a devres action placed between
the zone and the interrupts instead.  It then runs after both handlers
have been released and before the zone goes away, and it also covers a
probe failure past that point.

Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
---
Prepared against v7.4-rc1-1969-g666539eecdf4.

AI assistance: the analysis, the change and its review notes were
prepared with Claude (Anthropic) as a coding assistant.  The author
reviewed the reasoning and takes responsibility for the content.

This revision registers the thermal zone before the interrupts and puts
the PRCMU stop into a devres action placed between them, so devres
releases both handlers first, then stops the measurement, then
unregisters the zone.  A stop issued from .remove() alone would be
undone by a handler still running db8500_thermal_update_config(), which
stops the sensing and starts it again.

Testing: compiled for ARCH=arm with u8500_defconfig (gcc 11.4,
arm-linux-gnueabi).  No Ux500 hardware was available, so neither the
normal removal nor the second-IRQ-failure path was exercised.
---
 drivers/thermal/db8500_thermal.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/drivers/thermal/db8500_thermal.c b/drivers/thermal/db8500_thermal.c
index 48981247763f..b8f75838cc4d 100644
--- a/drivers/thermal/db8500_thermal.c
+++ b/drivers/thermal/db8500_thermal.c
@@ -148,6 +148,11 @@ static irqreturn_t prcmu_high_irq_handler(int irq, void *irq_data)
 	return IRQ_HANDLED;
 }
 
+static void db8500_thermal_stop_action(void *data)
+{
+	db8500_prcmu_stop_temp_sense();
+}
+
 static int db8500_thermal_probe(struct platform_device *pdev)
 {
 	struct db8500_thermal_zone *th = NULL;
@@ -160,6 +165,23 @@ static int db8500_thermal_probe(struct platform_device *pdev)
 
 	th->dev = dev;
 
+	/* register of thermal sensor and get info from DT */
+	th->tz = devm_thermal_of_zone_register(dev, 0, th, &thdev_ops);
+	if (IS_ERR(th->tz)) {
+		dev_err(dev, "register thermal zone sensor failed\n");
+		return PTR_ERR(th->tz);
+	}
+	dev_info(dev, "thermal zone sensor registered\n");
+
+	/*
+	 * Registered after the zone and before the interrupts, so devres runs
+	 * it after both handlers have been released: a handler cannot restart
+	 * the measurement behind our back.
+	 */
+	ret = devm_add_action_or_reset(dev, db8500_thermal_stop_action, th);
+	if (ret)
+		return ret;
+
 	low_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_LOW");
 	if (low_irq < 0)
 		return low_irq;
@@ -180,14 +202,6 @@ static int db8500_thermal_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return ret;
 
-	/* register of thermal sensor and get info from DT */
-	th->tz = devm_thermal_of_zone_register(dev, 0, th, &thdev_ops);
-	if (IS_ERR(th->tz)) {
-		dev_err(dev, "register thermal zone sensor failed\n");
-		return PTR_ERR(th->tz);
-	}
-	dev_info(dev, "thermal zone sensor registered\n");
-
 	/* Start measuring at the lowest point */
 	db8500_thermal_update_config(th, 0, PRCMU_DEFAULT_LOW_TEMP,
 				     db8500_thermal_points[0]);
-- 
2.34.1


                 reply	other threads:[~2026-11-17 14:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261117145331.1092458-1-shunsheng1218@gmail.com \
    --to=shunsheng1218@gmail.com \
    --cc=daniel.lezcano@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    /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

all inboxes | Powered by JetHome®