Skip to content

Commit c4cd42e

Browse files
committed
thermal: core: Update thermal zones after cooling device binding
If a new cooling device is registered and it is bound to at least one trip point in a given thermal zone, that thermal zone needs to be updated via __thermal_zone_device_update(). Instead of doing this with the help of the need_update atomic field in struct thermal_zone_device, which is not particularly straightforward, make __thermal_zone_cdev_bind() return a bool value indicating whether or not the given thermal zone needs to be updated because a new cooling device has been bound to it and update thermal_zone_cdev_bind() to call __thermal_zone_device_update() when this value is "true". 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 fa4f9c9 commit c4cd42e

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

drivers/thermal/thermal_core.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -935,13 +935,14 @@ void print_bind_err_msg(struct thermal_zone_device *tz,
935935
cdev->type, thermal_zone_trip_id(tz, trip), ret);
936936
}
937937

938-
static void __thermal_zone_cdev_bind(struct thermal_zone_device *tz,
938+
static bool __thermal_zone_cdev_bind(struct thermal_zone_device *tz,
939939
struct thermal_cooling_device *cdev)
940940
{
941941
struct thermal_trip_desc *td;
942+
bool update_tz = false;
942943

943944
if (!tz->ops.should_bind)
944-
return;
945+
return false;
945946

946947
for_each_trip_desc(tz, td) {
947948
struct thermal_trip *trip = &td->trip;
@@ -956,17 +957,24 @@ static void __thermal_zone_cdev_bind(struct thermal_zone_device *tz,
956957
continue;
957958

958959
ret = thermal_bind_cdev_to_trip(tz, trip, cdev, &c);
959-
if (ret)
960+
if (ret) {
960961
print_bind_err_msg(tz, trip, cdev, ret);
962+
continue;
963+
}
964+
965+
update_tz = true;
961966
}
967+
968+
return update_tz;
962969
}
963970

964971
static void thermal_zone_cdev_bind(struct thermal_zone_device *tz,
965972
struct thermal_cooling_device *cdev)
966973
{
967974
mutex_lock(&tz->lock);
968975

969-
__thermal_zone_cdev_bind(tz, cdev);
976+
if (__thermal_zone_cdev_bind(tz, cdev))
977+
__thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
970978

971979
mutex_unlock(&tz->lock);
972980
}
@@ -993,7 +1001,7 @@ __thermal_cooling_device_register(struct device_node *np,
9931001
const struct thermal_cooling_device_ops *ops)
9941002
{
9951003
struct thermal_cooling_device *cdev;
996-
struct thermal_zone_device *pos = NULL;
1004+
struct thermal_zone_device *pos;
9971005
unsigned long current_state;
9981006
int id, ret;
9991007

@@ -1069,11 +1077,6 @@ __thermal_cooling_device_register(struct device_node *np,
10691077
list_for_each_entry(pos, &thermal_tz_list, node)
10701078
thermal_zone_cdev_bind(pos, cdev);
10711079

1072-
list_for_each_entry(pos, &thermal_tz_list, node)
1073-
if (atomic_cmpxchg(&pos->need_update, 1, 0))
1074-
thermal_zone_device_update(pos,
1075-
THERMAL_EVENT_UNSPECIFIED);
1076-
10771080
mutex_unlock(&thermal_list_lock);
10781081

10791082
return cdev;

0 commit comments

Comments
 (0)