Skip to content

Commit 9025adf

Browse files
Stefan Mavrodievgregkh
authored andcommitted
thermal_hwmon: Sanitize thermal_zone type
[ Upstream commit 8c7aa18 ] When calling thermal_add_hwmon_sysfs(), the device type is sanitized by replacing '-' with '_'. However tz->type remains unsanitized. Thus calling thermal_hwmon_lookup_by_type() returns no device. And if there is no device, thermal_remove_hwmon_sysfs() fails with "hwmon device lookup failed!". The result is unregisted hwmon devices in the sysfs. Fixes: 409ef0b ("thermal_hwmon: Sanitize attribute name passed to hwmon") Signed-off-by: Stefan Mavrodiev <stefan@olimex.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c01a9db commit 9025adf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/thermal/thermal_hwmon.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,17 @@ static struct thermal_hwmon_device *
8787
thermal_hwmon_lookup_by_type(const struct thermal_zone_device *tz)
8888
{
8989
struct thermal_hwmon_device *hwmon;
90+
char type[THERMAL_NAME_LENGTH];
9091

9192
mutex_lock(&thermal_hwmon_list_lock);
92-
list_for_each_entry(hwmon, &thermal_hwmon_list, node)
93-
if (!strcmp(hwmon->type, tz->type)) {
93+
list_for_each_entry(hwmon, &thermal_hwmon_list, node) {
94+
strcpy(type, tz->type);
95+
strreplace(type, '-', '_');
96+
if (!strcmp(hwmon->type, type)) {
9497
mutex_unlock(&thermal_hwmon_list_lock);
9598
return hwmon;
9699
}
100+
}
97101
mutex_unlock(&thermal_hwmon_list_lock);
98102

99103
return NULL;

0 commit comments

Comments
 (0)