[PATCH v3 01/11] thermal/core: Use devm_add_action_or_reset() when registering a cooling device

From: Daniel Lezcano

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


Use devm_add_action_or_reset() which does the replaced code. It
results in a simpler and more concise code.

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

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 2f4e2dc46b8f..664a4cc95199 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1187,10 +1187,11 @@ thermal_of_cooling_device_register(struct device_node *np,
}
EXPORT_SYMBOL_GPL(thermal_of_cooling_device_register);

-static void thermal_cooling_device_release(struct device *dev, void *res)
+static void thermal_cooling_device_release(void *data)
{
- thermal_cooling_device_unregister(
- *(struct thermal_cooling_device **)res);
+ struct thermal_cooling_device *cdev = data;
+
+ thermal_cooling_device_unregister(cdev);
}

/**
@@ -1216,23 +1217,18 @@ devm_thermal_of_cooling_device_register(struct device *dev,
const char *type, void *devdata,
const struct thermal_cooling_device_ops *ops)
{
- struct thermal_cooling_device **ptr, *tcd;
+ struct thermal_cooling_device *cdev;
+ int ret;

- ptr = devres_alloc(thermal_cooling_device_release, sizeof(*ptr),
- GFP_KERNEL);
- if (!ptr)
- return ERR_PTR(-ENOMEM);
+ cdev = __thermal_cooling_device_register(np, type, devdata, ops);
+ if (IS_ERR(cdev))
+ return cdev;

- tcd = __thermal_cooling_device_register(np, type, devdata, ops);
- if (IS_ERR(tcd)) {
- devres_free(ptr);
- return tcd;
- }
-
- *ptr = tcd;
- devres_add(dev, ptr);
+ ret = devm_add_action_or_reset(dev, thermal_cooling_device_release, cdev);
+ if (ret)
+ return ERR_PTR(ret);

- return tcd;
+ return cdev;
}
EXPORT_SYMBOL_GPL(devm_thermal_of_cooling_device_register);

--
2.43.0