Linux Power Management development
 help / color / mirror / Atom feed
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 01/12] thermal: core: Add thermal zone device reference helpers
Date: Thu, 19 Nov 2026 10:46:43 +0100	[thread overview]
Message-ID: <20261119094706.3439040-2-daniel.lezcano@oss.qualcomm.com> (raw)
In-Reply-To: <20261119094706.3439040-1-daniel.lezcano@oss.qualcomm.com>

Add private thermal_zone_device_get() and thermal_zone_device_put()
helpers around the embedded device reference count. Document that callers
must protect the zone pointer when acquiring a reference and that a
reference protects lifetime, not operational availability.

Use the helpers in thermal_zone_get_by_id() and its scoped cleanup class
to keep reference acquisition and release within the thermal core
abstraction. Preserve the existing reference ownership and teardown
behavior.

Signed-off-by: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
---
 drivers/thermal/thermal_core.c | 35 ++++++++++++++++++++++++++++++----
 drivers/thermal/thermal_core.h |  5 ++++-
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index e8d4da0aeac3..02c2c08077bf 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -698,6 +698,35 @@ int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
 	return 0;
 }
 
+/**
+ * thermal_zone_device_get() - acquire a thermal zone device reference
+ * @tz: thermal zone device, or NULL
+ *
+ * The caller must protect @tz against concurrent destruction, for example
+ * by holding an existing reference or thermal_list_lock. The reference
+ * protects the zone's lifetime, not its operational availability.
+ *
+ * Return: @tz, or NULL if @tz is NULL.
+ */
+struct thermal_zone_device *
+thermal_zone_device_get(struct thermal_zone_device *tz)
+{
+	if (tz)
+		get_device(&tz->device);
+
+	return tz;
+}
+
+/**
+ * thermal_zone_device_put() - release a thermal zone device reference
+ * @tz: thermal zone device, or NULL
+ */
+void thermal_zone_device_put(struct thermal_zone_device *tz)
+{
+	if (tz)
+		put_device(&tz->device);
+}
+
 struct thermal_zone_device *thermal_zone_get_by_id(int id)
 {
 	struct thermal_zone_device *tz;
@@ -705,10 +734,8 @@ struct thermal_zone_device *thermal_zone_get_by_id(int id)
 	guard(mutex)(&thermal_list_lock);
 
 	list_for_each_entry(tz, &thermal_tz_list, node) {
-		if (tz->id == id) {
-			get_device(&tz->device);
-			return tz;
-		}
+		if (tz->id == id)
+			return thermal_zone_device_get(tz);
 	}
 
 	return NULL;
diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index 7ef7c6cab437..7b91717d9d74 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -211,10 +211,13 @@ int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *,
 int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
 			      void *thermal_governor);
 
+struct thermal_zone_device *thermal_zone_device_get(struct thermal_zone_device *tz);
+void thermal_zone_device_put(struct thermal_zone_device *tz);
+
 struct thermal_zone_device *thermal_zone_get_by_id(int id);
 
 DEFINE_CLASS(thermal_zone_get_by_id, struct thermal_zone_device *,
-	     if (_T) put_device(&_T->device), thermal_zone_get_by_id(id), int id)
+	     thermal_zone_device_put(_T), thermal_zone_get_by_id(id), int id)
 
 static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
 {

base-commit: 0dd55073c872df387d28480d1197c013423d1705
-- 
2.43.0


  reply	other threads:[~2026-11-19  9:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  9:46 [PATCH v1 00/12] thermal: Add multi-source thermal zone aggregation Daniel Lezcano
2026-11-19  9:46 ` Daniel Lezcano [this message]
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 ` [PATCH v1 09/12] thermal: of: Track registered hardware temperature sources Daniel Lezcano
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-2-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