summaryrefslogtreecommitdiff
path: root/drivers/thermal
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2024-10-11 01:13:50 +0300
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2024-10-23 12:56:57 +0300
commit6d153f52cc3452258415db6a202cc6d15daa3920 (patch)
treedd3e570e0fe2922d548bb30ab83c0377f2e73ce1 /drivers/thermal
parent33eab804d695dc2be1491890143a64ea4d99cd42 (diff)
downloadlinux-6d153f52cc3452258415db6a202cc6d15daa3920.tar.xz
thermal: core: Introduce thermal_instance_add()
To reduce the number of redundant result checks in thermal_bind_cdev_to_trip() and make the code in it easier to follow, move some of it to a new function called thermal_instance_add() and make thermal_bind_cdev_to_trip() invoke that function. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Link: https://patch.msgid.link/3618899.iIbC2pHGDl@rjwysocki.net Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Diffstat (limited to 'drivers/thermal')
-rw-r--r--drivers/thermal/thermal_core.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index cc1fd230b100..ae424eef4574 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -745,6 +745,28 @@ struct thermal_zone_device *thermal_zone_get_by_id(int id)
* binding, and unbinding.
*/
+static int thermal_instance_add(struct thermal_instance *new_instance,
+ struct thermal_cooling_device *cdev,
+ struct thermal_trip_desc *td)
+{
+ struct thermal_instance *instance;
+
+ list_for_each_entry(instance, &td->thermal_instances, trip_node) {
+ if (instance->cdev == cdev)
+ return -EEXIST;
+ }
+
+ list_add_tail(&new_instance->trip_node, &td->thermal_instances);
+
+ mutex_lock(&cdev->lock);
+
+ list_add_tail(&new_instance->cdev_node, &cdev->thermal_instances);
+
+ mutex_unlock(&cdev->lock);
+
+ return 0;
+}
+
/**
* thermal_bind_cdev_to_trip - bind a cooling device to a thermal zone
* @tz: pointer to struct thermal_zone_device
@@ -763,7 +785,7 @@ static int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
struct thermal_cooling_device *cdev,
struct cooling_spec *cool_spec)
{
- struct thermal_instance *dev, *instance;
+ struct thermal_instance *dev;
bool upper_no_limit;
int result;
@@ -825,23 +847,15 @@ static int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
if (result)
goto remove_trip_file;
- mutex_lock(&cdev->lock);
- list_for_each_entry(instance, &td->thermal_instances, trip_node)
- if (instance->cdev == cdev) {
- result = -EEXIST;
- break;
- }
- if (!result) {
- list_add_tail(&dev->trip_node, &td->thermal_instances);
- list_add_tail(&dev->cdev_node, &cdev->thermal_instances);
- }
- mutex_unlock(&cdev->lock);
+ result = thermal_instance_add(dev, cdev, td);
+ if (result)
+ goto remove_weight_file;
- if (!result) {
- thermal_governor_update_tz(tz, THERMAL_TZ_BIND_CDEV);
- return 0;
- }
+ thermal_governor_update_tz(tz, THERMAL_TZ_BIND_CDEV);
+
+ return 0;
+remove_weight_file:
device_remove_file(&tz->device, &dev->weight_attr);
remove_trip_file:
device_remove_file(&tz->device, &dev->attr);