Skip to content

Commit c43198a

Browse files
committed
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 <[email protected]> Tested-by: Zhang Rui <[email protected]> Reviewed-by: Zhang Rui <[email protected]>
1 parent c0e0421 commit c43198a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

drivers/thermal/thermal_core.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,18 @@ devm_thermal_of_cooling_device_register(struct device *dev,
10451045
}
10461046
EXPORT_SYMBOL_GPL(devm_thermal_of_cooling_device_register);
10471047

1048+
static bool thermal_cooling_device_present(struct thermal_cooling_device *cdev)
1049+
{
1050+
struct thermal_cooling_device *pos = NULL;
1051+
1052+
list_for_each_entry(pos, &thermal_cdev_list, node) {
1053+
if (pos == cdev)
1054+
return true;
1055+
}
1056+
1057+
return false;
1058+
}
1059+
10481060
static void __unbind(struct thermal_zone_device *tz, int mask,
10491061
struct thermal_cooling_device *cdev)
10501062
{
@@ -1067,20 +1079,17 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
10671079
int i;
10681080
const struct thermal_zone_params *tzp;
10691081
struct thermal_zone_device *tz;
1070-
struct thermal_cooling_device *pos = NULL;
10711082

10721083
if (!cdev)
10731084
return;
10741085

10751086
mutex_lock(&thermal_list_lock);
1076-
list_for_each_entry(pos, &thermal_cdev_list, node)
1077-
if (pos == cdev)
1078-
break;
1079-
if (pos != cdev) {
1080-
/* thermal cooling device not found */
1087+
1088+
if (!thermal_cooling_device_present(cdev)) {
10811089
mutex_unlock(&thermal_list_lock);
10821090
return;
10831091
}
1092+
10841093
list_del(&cdev->node);
10851094

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

0 commit comments

Comments
 (0)