Skip to content

Commit 6d153f5

Browse files
committed
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Lukasz Luba <[email protected]>
1 parent 33eab80 commit 6d153f5

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

drivers/thermal/thermal_core.c

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,28 @@ struct thermal_zone_device *thermal_zone_get_by_id(int id)
745745
* binding, and unbinding.
746746
*/
747747

748+
static int thermal_instance_add(struct thermal_instance *new_instance,
749+
struct thermal_cooling_device *cdev,
750+
struct thermal_trip_desc *td)
751+
{
752+
struct thermal_instance *instance;
753+
754+
list_for_each_entry(instance, &td->thermal_instances, trip_node) {
755+
if (instance->cdev == cdev)
756+
return -EEXIST;
757+
}
758+
759+
list_add_tail(&new_instance->trip_node, &td->thermal_instances);
760+
761+
mutex_lock(&cdev->lock);
762+
763+
list_add_tail(&new_instance->cdev_node, &cdev->thermal_instances);
764+
765+
mutex_unlock(&cdev->lock);
766+
767+
return 0;
768+
}
769+
748770
/**
749771
* thermal_bind_cdev_to_trip - bind a cooling device to a thermal zone
750772
* @tz: pointer to struct thermal_zone_device
@@ -763,7 +785,7 @@ static int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
763785
struct thermal_cooling_device *cdev,
764786
struct cooling_spec *cool_spec)
765787
{
766-
struct thermal_instance *dev, *instance;
788+
struct thermal_instance *dev;
767789
bool upper_no_limit;
768790
int result;
769791

@@ -825,23 +847,15 @@ static int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
825847
if (result)
826848
goto remove_trip_file;
827849

828-
mutex_lock(&cdev->lock);
829-
list_for_each_entry(instance, &td->thermal_instances, trip_node)
830-
if (instance->cdev == cdev) {
831-
result = -EEXIST;
832-
break;
833-
}
834-
if (!result) {
835-
list_add_tail(&dev->trip_node, &td->thermal_instances);
836-
list_add_tail(&dev->cdev_node, &cdev->thermal_instances);
837-
}
838-
mutex_unlock(&cdev->lock);
850+
result = thermal_instance_add(dev, cdev, td);
851+
if (result)
852+
goto remove_weight_file;
839853

840-
if (!result) {
841-
thermal_governor_update_tz(tz, THERMAL_TZ_BIND_CDEV);
842-
return 0;
843-
}
854+
thermal_governor_update_tz(tz, THERMAL_TZ_BIND_CDEV);
855+
856+
return 0;
844857

858+
remove_weight_file:
845859
device_remove_file(&tz->device, &dev->weight_attr);
846860
remove_trip_file:
847861
device_remove_file(&tz->device, &dev->attr);

0 commit comments

Comments
 (0)