Skip to content

Commit a75517f

Browse files
rafaeljwjamieNguyenNVIDIA
authored andcommitted
thermal: core: Introduce thermal_cooling_device_present()
Introduce a helper function, thermal_cooling_device_present(), for checking if the given cooling device is in the list of registered cooling devices to avoid some code duplication in a subsequent patch. No expected functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Tested-by: Zhang Rui <rui.zhang@intel.com> Reviewed-by: Zhang Rui <rui.zhang@intel.com> Acked-by: Nathan Hartman <nhartman@nvidia.com> Acked-by: Jamie Nguyen <jamien@nvidia.com>
1 parent 5e019b4 commit a75517f

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

drivers/thermal/thermal_core.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,18 @@ devm_thermal_of_cooling_device_register(struct device *dev,
10521052
}
10531053
EXPORT_SYMBOL_GPL(devm_thermal_of_cooling_device_register);
10541054

1055+
static bool thermal_cooling_device_present(struct thermal_cooling_device *cdev)
1056+
{
1057+
struct thermal_cooling_device *pos = NULL;
1058+
1059+
list_for_each_entry(pos, &thermal_cdev_list, node) {
1060+
if (pos == cdev)
1061+
return true;
1062+
}
1063+
1064+
return false;
1065+
}
1066+
10551067
static void __unbind(struct thermal_zone_device *tz, int mask,
10561068
struct thermal_cooling_device *cdev)
10571069
{
@@ -1074,20 +1086,17 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
10741086
int i;
10751087
const struct thermal_zone_params *tzp;
10761088
struct thermal_zone_device *tz;
1077-
struct thermal_cooling_device *pos = NULL;
10781089

10791090
if (!cdev)
10801091
return;
10811092

10821093
mutex_lock(&thermal_list_lock);
1083-
list_for_each_entry(pos, &thermal_cdev_list, node)
1084-
if (pos == cdev)
1085-
break;
1086-
if (pos != cdev) {
1087-
/* thermal cooling device not found */
1094+
1095+
if (!thermal_cooling_device_present(cdev)) {
10881096
mutex_unlock(&thermal_list_lock);
10891097
return;
10901098
}
1099+
10911100
list_del(&cdev->node);
10921101

10931102
/* Unbind all thermal zones associated with 'this' cdev */

0 commit comments

Comments
 (0)