Skip to content

Commit 329b064

Browse files
committed
thermal: core: Get thermal zone by id
The next patch will introduce the generic netlink protocol to handle events, sampling and command from the thermal framework. In order to deal with the thermal zone, it uses its unique identifier to characterize it in the message. Passing an integer is more efficient than passing an entire string. This change provides a function returning back a thermal zone pointer corresponding to the identifier passed as parameter. Signed-off-by: Daniel Lezcano <[email protected]> Reviewed-by: Amit Kucheria <[email protected]> Acked-by: Zhang Rui <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3d44a50 commit 329b064

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

drivers/thermal/thermal_core.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,20 @@ int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
732732
return ret;
733733
}
734734

735+
struct thermal_zone_device *thermal_zone_get_by_id(int id)
736+
{
737+
struct thermal_zone_device *tz = NULL;
738+
739+
mutex_lock(&thermal_list_lock);
740+
list_for_each_entry(tz, &thermal_tz_list, node) {
741+
if (tz->id == id)
742+
break;
743+
}
744+
mutex_unlock(&thermal_list_lock);
745+
746+
return tz;
747+
}
748+
735749
void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz,
736750
const char *cdev_type, size_t size)
737751
{

drivers/thermal/thermal_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *,
5050
int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
5151
void *thermal_governor);
5252

53+
struct thermal_zone_device *thermal_zone_get_by_id(int id);
54+
5355
struct thermal_attr {
5456
struct device_attribute attr;
5557
char name[THERMAL_NAME_LENGTH];

0 commit comments

Comments
 (0)