Skip to content

Commit 82aa68a

Browse files
thierryredingdlezcano
authored andcommitted
thermal: core: Fix thermal zone lookup by ID
When a thermal zone is looked up by an ID and no zone is found matching that ID, the thermal_zone_get_by_id() function will return a pointer to the thermal zone list head which isn't actually a valid thermal zone. This can lead to a subsequent crash because a valid pointer is returned to the called, but dereferencing that pointer as struct thermal_zone is not safe. Fixes: 329b064 ("thermal: core: Get thermal zone by id") Signed-off-by: Thierry Reding <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 287d959 commit 82aa68a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/thermal/thermal_core.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,16 +751,18 @@ int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
751751

752752
struct thermal_zone_device *thermal_zone_get_by_id(int id)
753753
{
754-
struct thermal_zone_device *tz = NULL;
754+
struct thermal_zone_device *tz, *match = NULL;
755755

756756
mutex_lock(&thermal_list_lock);
757757
list_for_each_entry(tz, &thermal_tz_list, node) {
758-
if (tz->id == id)
758+
if (tz->id == id) {
759+
match = tz;
759760
break;
761+
}
760762
}
761763
mutex_unlock(&thermal_list_lock);
762764

763-
return tz;
765+
return match;
764766
}
765767

766768
void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz,

0 commit comments

Comments
 (0)