Skip to content

Commit 54219ee

Browse files
dlezcanorafaeljw
authored andcommitted
thermal: thresholds: Fix thermal lock annotation issue
When the thermal zone is unregistered (thermal sensor module being unloaded), no lock is held when flushing the thresholds. That results in a WARN when the lockdep validation is set in the kernel config. This has been reported by syzbot. As the thermal zone is in the process of being destroyed, there is no need to send a notification about purging the thresholds to the userspace as this one will receive a thermal zone deletion notification which imply the deletion of all the associated resources like the trip points or the user thresholds. Split the function thermal_thresholds_flush() into a lockless one without notification and its call with the lock annotation followed with the thresholds flushing notification. Please note this scenario is unlikely to happen, as the sensor drivers are usually compiled-in in order to have the thermal framework to be able to kick in at boot time if needed. Fixes: 445936f ("thermal: core: Add user thresholds support") Link: https://lore.kernel.org/all/[email protected] Reported-by: [email protected] Signed-off-by: Daniel Lezcano <[email protected]> Link: https://patch.msgid.link/[email protected] [ rjw: Subject edit, added Fixes tag ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 41b89db commit 54219ee

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/thermal/thermal_thresholds.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@ int thermal_thresholds_init(struct thermal_zone_device *tz)
2020
return 0;
2121
}
2222

23-
void thermal_thresholds_flush(struct thermal_zone_device *tz)
23+
static void __thermal_thresholds_flush(struct thermal_zone_device *tz)
2424
{
2525
struct list_head *thresholds = &tz->user_thresholds;
2626
struct user_threshold *entry, *tmp;
2727

28-
lockdep_assert_held(&tz->lock);
29-
3028
list_for_each_entry_safe(entry, tmp, thresholds, list_node) {
3129
list_del(&entry->list_node);
3230
kfree(entry);
3331
}
32+
}
33+
34+
void thermal_thresholds_flush(struct thermal_zone_device *tz)
35+
{
36+
lockdep_assert_held(&tz->lock);
37+
38+
__thermal_thresholds_flush(tz);
3439

3540
thermal_notify_threshold_flush(tz);
3641

@@ -39,7 +44,7 @@ void thermal_thresholds_flush(struct thermal_zone_device *tz)
3944

4045
void thermal_thresholds_exit(struct thermal_zone_device *tz)
4146
{
42-
thermal_thresholds_flush(tz);
47+
__thermal_thresholds_flush(tz);
4348
}
4449

4550
static int __thermal_thresholds_cmp(void *data,

0 commit comments

Comments
 (0)