Re: [PATCH] thermal/core: Split __thermal_cooling_device_register() into two functions
From: Daniel Lezcano
Date: Fri May 08 2026 - 07:30:52 EST
On 5/8/26 12:35, Lukasz Luba wrote:
On 5/7/26 19:26, Daniel Lezcano wrote:
On 5/7/26 12:02, Lukasz Luba wrote:
[ ... ]
I would call them explicitly in case of 'if(ret)'
error from dev_set_name()...
Then the rest could end in case of error with that new
'put_device()' logic at the bottom.
Would you agree?
A different option would be to refactor thermal_release()
and somehow recognize the cooling device not based on name.
This mechanism is not adequate.
thermal_release should not be used this way, neither it should be needed.
We should have:
thermal_class = class_create("thermal");
if (IS_ERR(thermal_class))
...
No thermal_release needed.
But,
static void cooling_dev_release(struct device *dev)
{
thermal_cooling_device *cdev;
cdev = to_cooling_device(dev);
thermal_cooling_device_destroy_sysfs(cdev);
kfree_const(cdev->type);
ida_free(&thermal_cdev_ida, cdev->id);
kfree(cdev);
}
static void tz_dev_release(struct device *dev)
{
thermal_zone_device *tz;
tz = to_thermal_zone(dev);
thermal_zone_destroy_device_groups(tz);
thermal_set_governor(tz, NULL);
ida_destroy(&tz->ida);
mutex_destroy(&tz->lock);
complete(&tz->removal);
}
In thermal_cooling_device_add()
{
...
cdev->device.release = cooling_dev_release
...
}
In thermal_zone_device_register_with_trips()
{
...
tz->device.release = tz_dev_release
...
}