]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
thermal/core: Add devm_thermal_cooling_device_register()
authorDaniel Lezcano <daniel.lezcano@oss.qualcomm.com>
Tue, 26 May 2026 14:08:03 +0000 (16:08 +0200)
committerDaniel Lezcano <daniel.lezcano@kernel.org>
Wed, 3 Jun 2026 07:12:40 +0000 (09:12 +0200)
Introduce a device-managed variant of the non-OF cooling device
registration API.

This complements devm_thermal_of_cooling_device_register() and allows
non-device-tree users to register cooling devices with automatic
cleanup tied to the device lifecycle.

The helper relies on devm_add_action_or_reset() to release the cooling
device via thermal_cooling_device_release() on driver detach or probe
failure.

This keeps the API consistent across OF and non-OF users and avoids
manual cleanup in error paths.

Signed-off-by: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@kernel.org>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Acked-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Link: https://patch.msgid.link/20260526140802.1059293-14-daniel.lezcano@oss.qualcomm.com
drivers/thermal/thermal_core.c
include/linux/thermal.h

index 0b3db889d60df9fae47d15739c140529ac1cefb0..bb4fc3ff2ad50847ce7ba6e82ee860f07ac5af49 100644 (file)
@@ -1173,6 +1173,41 @@ devm_thermal_of_cooling_device_register(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(devm_thermal_of_cooling_device_register);
 
+/**
+ * devm_thermal_cooling_device_register() - register a thermal cooling device
+ *
+ * @dev:       a valid struct device pointer of a sensor device.
+ * @type:      the thermal cooling device type.
+ * @devdata:   device private data.
+ * @ops:       standard thermal cooling devices callbacks.
+ *
+ * This function will register a cooling device. 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.
+ *
+ * Return: a pointer to the created struct thermal_cooling_device or an
+ * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
+ */
+struct thermal_cooling_device *
+devm_thermal_cooling_device_register(struct device *dev, const char *type, void *devdata,
+                                    const struct thermal_cooling_device_ops *ops)
+{
+       struct thermal_cooling_device *cdev;
+       int ret;
+
+       cdev = thermal_cooling_device_register(type, devdata, ops);
+       if (IS_ERR(cdev))
+               return cdev;
+
+       ret = devm_add_action_or_reset(dev, thermal_cooling_device_release, cdev);
+       if (ret)
+               return ERR_PTR(ret);
+
+       return cdev;
+}
+EXPORT_SYMBOL_GPL(devm_thermal_cooling_device_register);
+
 static bool thermal_cooling_device_present(struct thermal_cooling_device *cdev)
 {
        struct thermal_cooling_device *pos = NULL;
index 0ddc77aeeca26535831bd83d2323e67d4e4dcd7a..fc3f4a09837038f12f33855277cd4f2e4191a243 100644 (file)
@@ -253,8 +253,11 @@ void thermal_zone_device_update(struct thermal_zone_device *,
 struct thermal_cooling_device *thermal_cooling_device_register(const char *,
                void *, const struct thermal_cooling_device_ops *);
 struct thermal_cooling_device *
-thermal_of_cooling_device_register(struct device_node *np, const char *, void *,
-                                  const struct thermal_cooling_device_ops *);
+devm_thermal_cooling_device_register(struct device *dev, const char *type, void *devdata,
+                                    const struct thermal_cooling_device_ops *ops);
+struct thermal_cooling_device *
+thermal_of_cooling_device_register(struct device_node *np, const char *type, void *devdata,
+                                  const struct thermal_cooling_device_ops *ops);
 struct thermal_cooling_device *
 devm_thermal_of_cooling_device_register(struct device *dev,
                                struct device_node *np,