[PATCH v3 03/11] thermal/of: Move the node pointer assignation in the OF code file

From: Daniel Lezcano

Date: Wed Apr 29 2026 - 12:16:02 EST


The node pointer being assigned to the cooling device structure is an
action done by the thermal OF only and does not belong to the core
framework code. Move the node pointer assignation in the thermal OF
code. Consequently, the devm_thermal_of_cooling_device_register() can
call its non-devm version resulting in a more intuitive design of the
API.

Signed-off-by: Daniel Lezcano <daniel.lezcano@xxxxxxxxxxxxxxxx>
---
drivers/thermal/thermal_core.c | 51 +++++++++++++++++-----------------
1 file changed, 26 insertions(+), 25 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 5c954bcae4a4..7867e6bc0a6c 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1040,26 +1040,11 @@ static void thermal_cooling_device_init_complete(struct thermal_cooling_device *
thermal_zone_cdev_bind(tz, cdev);
}

-/**
- * __thermal_cooling_device_register() - register a new thermal cooling device
- * @np: a pointer to a device tree node.
- * @type: the thermal cooling device type.
- * @devdata: device private data.
- * @ops: standard thermal cooling devices callbacks.
- *
- * This interface function adds a new thermal cooling device (fan/processor/...)
- * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
- * to all the thermal zone devices registered at the same time.
- * It also gives the opportunity to link the cooling device to a device tree
- * node, so that it can be bound to a thermal zone created out of device tree.
- *
- * Return: a pointer to the created struct thermal_cooling_device or an
- * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
- */
static struct thermal_cooling_device *
-__thermal_cooling_device_register(struct device_node *np,
- const char *type, void *devdata,
- const struct thermal_cooling_device_ops *ops)
+__thermal_cooling_device_register(const char *type, void *devdata,
+ const struct thermal_cooling_device_ops *ops,
+ void (*initcb)(struct thermal_cooling_device *,
+ void *), void *data)
{
struct thermal_cooling_device *cdev;
unsigned long current_state;
@@ -1089,7 +1074,6 @@ __thermal_cooling_device_register(struct device_node *np,

mutex_init(&cdev->lock);
INIT_LIST_HEAD(&cdev->thermal_instances);
- cdev->np = np;
cdev->ops = ops;
cdev->updated = false;
cdev->device.class = &thermal_class;
@@ -1127,6 +1111,9 @@ __thermal_cooling_device_register(struct device_node *np,
if (current_state <= cdev->max_state)
thermal_debug_cdev_add(cdev, current_state);

+ if (initcb)
+ initcb(cdev, data);
+
thermal_cooling_device_init_complete(cdev);

return cdev;
@@ -1146,7 +1133,7 @@ __thermal_cooling_device_register(struct device_node *np,
* thermal_cooling_device_register() - register a new thermal cooling device
* @type: the thermal cooling device type.
* @devdata: device private data.
- * @ops: standard thermal cooling devices callbacks.
+ * @ops: standard thermal cooling devices callbacks.
*
* This interface function adds a new thermal cooling device (fan/processor/...)
* to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
@@ -1159,10 +1146,17 @@ struct thermal_cooling_device *
thermal_cooling_device_register(const char *type, void *devdata,
const struct thermal_cooling_device_ops *ops)
{
- return __thermal_cooling_device_register(NULL, type, devdata, ops);
+ return __thermal_cooling_device_register(type, devdata, ops, NULL, NULL);
}
EXPORT_SYMBOL_GPL(thermal_cooling_device_register);

+static void thermal_of_cooling_device_init(struct thermal_cooling_device *cdev, void *data)
+{
+ struct device_node *np = data;
+
+ cdev->np = np;
+}
+
/**
* thermal_of_cooling_device_register() - register an OF thermal cooling device
* @np: a pointer to a device tree node.
@@ -1183,7 +1177,14 @@ thermal_of_cooling_device_register(struct device_node *np,
const char *type, void *devdata,
const struct thermal_cooling_device_ops *ops)
{
- return __thermal_cooling_device_register(np, type, devdata, ops);
+ struct thermal_cooling_device *cdev;
+
+ cdev = __thermal_cooling_device_register(type, devdata, ops,
+ thermal_of_cooling_device_init, np);
+ if (IS_ERR(cdev))
+ return cdev;
+
+ return cdev;
}
EXPORT_SYMBOL_GPL(thermal_of_cooling_device_register);

@@ -1217,7 +1218,7 @@ devm_thermal_cooling_device_register(struct device *dev,
struct thermal_cooling_device *cdev;
int ret;

- cdev = __thermal_cooling_device_register(NULL, type, devdata, ops);
+ cdev = thermal_cooling_device_register(type, devdata, ops);
if (IS_ERR(cdev))
return cdev;

@@ -1255,7 +1256,7 @@ devm_thermal_of_cooling_device_register(struct device *dev,
struct thermal_cooling_device *cdev;
int ret;

- cdev = __thermal_cooling_device_register(np, type, devdata, ops);
+ cdev = thermal_of_cooling_device_register(np, type, devdata, ops);
if (IS_ERR(cdev))
return cdev;

--
2.43.0