Skip to content

Commit 3d44a50

Browse files
committed
thermal: core: Add helpers to browse the cdev, tz and governor list
The cdev, tz and governor list, as well as their respective locks are statically defined in the thermal_core.c file. In order to give a sane access to these list, like browsing all the thermal zones or all the cooling devices, let's define a set of helpers where we pass a callback as a parameter to be called for each thermal entity. We keep the self-encapsulation and ensure the locks are correctly taken when looking at the list. Acked-by: Zhang Rui <[email protected]> Reviewed-by: Amit Kucheria <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 514acd0 commit 3d44a50

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

drivers/thermal/thermal_core.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,57 @@ void thermal_zone_device_rebind_exception(struct thermal_zone_device *tz,
681681
mutex_unlock(&thermal_list_lock);
682682
}
683683

684+
int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
685+
void *data)
686+
{
687+
struct thermal_governor *gov;
688+
int ret = 0;
689+
690+
mutex_lock(&thermal_governor_lock);
691+
list_for_each_entry(gov, &thermal_governor_list, governor_list) {
692+
ret = cb(gov, data);
693+
if (ret)
694+
break;
695+
}
696+
mutex_unlock(&thermal_governor_lock);
697+
698+
return ret;
699+
}
700+
701+
int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *,
702+
void *), void *data)
703+
{
704+
struct thermal_cooling_device *cdev;
705+
int ret = 0;
706+
707+
mutex_lock(&thermal_list_lock);
708+
list_for_each_entry(cdev, &thermal_cdev_list, node) {
709+
ret = cb(cdev, data);
710+
if (ret)
711+
break;
712+
}
713+
mutex_unlock(&thermal_list_lock);
714+
715+
return ret;
716+
}
717+
718+
int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
719+
void *data)
720+
{
721+
struct thermal_zone_device *tz;
722+
int ret = 0;
723+
724+
mutex_lock(&thermal_list_lock);
725+
list_for_each_entry(tz, &thermal_tz_list, node) {
726+
ret = cb(tz, data);
727+
if (ret)
728+
break;
729+
}
730+
mutex_unlock(&thermal_list_lock);
731+
732+
return ret;
733+
}
734+
684735
void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz,
685736
const char *cdev_type, size_t size)
686737
{

drivers/thermal/thermal_core.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ extern struct thermal_governor *__governor_thermal_table_end[];
4141
__governor < __governor_thermal_table_end; \
4242
__governor++)
4343

44+
int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
45+
void *);
46+
47+
int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *,
48+
void *), void *);
49+
50+
int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
51+
void *thermal_governor);
52+
4453
struct thermal_attr {
4554
struct device_attribute attr;
4655
char name[THERMAL_NAME_LENGTH];

0 commit comments

Comments
 (0)