From: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
To: daniel.lezcano@oss.qualcomm.com, rafael@kernel.org
Cc: Zhang Rui <rui.zhang@intel.com>,
Lukasz Luba <lukasz.luba@arm.com>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Anvesh Jain P <anvesh.p@oss.qualcomm.com>,
Ulf Hansson <ulf.hansson@oss.qualcomm.com>,
linux-pm@vger.kernel.org,
Daniel Lezcano <daniel.lezcano@kernel.org>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v1 09/12] thermal: of: Track registered hardware temperature sources
Date: Thu, 19 Nov 2026 10:46:51 +0100 [thread overview]
Message-ID: <20261119094706.3439040-10-daniel.lezcano@oss.qualcomm.com> (raw)
In-Reply-To: <20261119094706.3439040-1-daniel.lezcano@oss.qualcomm.com>
Record successfully enabled OF source zones by provider node and sensor
specifier ID. Serialize source publication and removal with an OF-private
lifecycle mutex and retain the provider node while its mapping exists.
Reject ambiguous duplicate provider and ID mappings. Remove the mapping
before unregistering the hardware zone, providing an ownership boundary
for subsequent OF aggregate consumers.
Signed-off-by: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
---
drivers/thermal/thermal_of.c | 79 ++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index 710ff25140e7..1fa7e29f5bc8 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -18,6 +18,75 @@
#include "thermal_core.h"
+#ifdef CONFIG_THERMAL_AGGREGATION
+struct thermal_of_source {
+ struct list_head node;
+ struct device_node *provider;
+ int id;
+ /*
+ * Borrowed from the OF zone registration. The mapping is removed under
+ * thermal_of_lock before the zone is unregistered. Aggregate consumers
+ * acquire their own references while holding the same lock.
+ */
+ struct thermal_zone_device *tz;
+};
+
+/*
+ * OF lifecycle operations are serialized outside thermal zone locks. Thermal
+ * callbacks must not acquire this mutex. Source removal holds it until all OF
+ * consumers have released their references, before calling core unregister.
+ */
+static DEFINE_MUTEX(thermal_of_lock);
+static LIST_HEAD(thermal_of_sources);
+
+static int thermal_of_source_add(struct device_node *provider, int id,
+ struct thermal_zone_device *tz)
+{
+ struct thermal_of_source *source, *pos;
+
+ source = kzalloc_obj(*source);
+ if (!source)
+ return -ENOMEM;
+
+ guard(mutex)(&thermal_of_lock);
+ list_for_each_entry(pos, &thermal_of_sources, node) {
+ if (pos->provider == provider && pos->id == id) {
+ kfree(source);
+ return -EEXIST;
+ }
+ }
+ source->provider = of_node_get(provider);
+ source->id = id;
+ source->tz = tz;
+ list_add_tail(&source->node, &thermal_of_sources);
+ return 0;
+}
+
+static void thermal_of_source_remove(struct thermal_zone_device *tz)
+{
+ struct thermal_of_source *source;
+
+ guard(mutex)(&thermal_of_lock);
+ list_for_each_entry(source, &thermal_of_sources, node) {
+ if (source->tz != tz)
+ continue;
+ list_del(&source->node);
+ of_node_put(source->provider);
+ kfree(source);
+ break;
+ }
+}
+
+#else
+static int thermal_of_source_add(struct device_node *provider, int id,
+ struct thermal_zone_device *tz)
+{
+ return 0;
+}
+
+static void thermal_of_source_remove(struct thermal_zone_device *tz) {}
+#endif
+
/*** functions parsing device tree nodes ***/
/*
@@ -359,6 +428,7 @@ static bool thermal_of_should_bind(struct thermal_zone_device *tz,
*/
static void thermal_of_zone_unregister(struct thermal_zone_device *tz)
{
+ thermal_of_source_remove(tz);
thermal_zone_device_disable(tz);
thermal_zone_device_unregister(tz);
}
@@ -446,6 +516,15 @@ thermal_of_zone_register(struct device_node *sensor, int id, void *data,
tz = thermal_of_zone_register_node(np, data, ops, &tzp);
of_node_put(np);
+ if (!IS_ERR(tz)) {
+ int ret = thermal_of_source_add(sensor, id, tz);
+
+ if (ret) {
+ thermal_of_zone_unregister(tz);
+ return ERR_PTR(ret);
+ }
+ }
+
return tz;
}
--
2.43.0
next prev parent reply other threads:[~2026-11-19 9:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261119094706.3439040-1-daniel.lezcano@oss.qualcomm.com>
2026-11-19 9:46 ` [PATCH v1 01/12] thermal: core: Add thermal zone device reference helpers Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 02/12] thermal: core: Introduce private thermal zone aggregation structures Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 03/12] thermal: core: Validate thermal zone aggregation descriptions Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 04/12] thermal: core: Initialize thermal zone aggregation coefficients Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 05/12] thermal: core: Dispatch aggregate temperature reads Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 06/12] thermal: core: Calculate aggregated thermal zone temperatures Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 07/12] thermal: core: Initialize aggregation during zone registration Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 08/12] thermal: of: Separate zone parsing from sensor lookup Daniel Lezcano
2026-11-19 9:46 ` Daniel Lezcano [this message]
2026-11-19 9:46 ` [PATCH v1 10/12] thermal: of: Instantiate aggregates after their source zones Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 11/12] dt-bindings: thermal: Describe multi-source zone aggregation Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 12/12] thermal: testing: Add KUnit coverage for " Daniel Lezcano
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=20261119094706.3439040-10-daniel.lezcano@oss.qualcomm.com \
--to=daniel.lezcano@oss.qualcomm.com \
--cc=anvesh.p@oss.qualcomm.com \
--cc=daniel.lezcano@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=rui.zhang@intel.com \
--cc=ulf.hansson@oss.qualcomm.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®