Commit e8db5d67 authored by Aaron Lu's avatar Aaron Lu Committed by Zhang Rui

thermal: hwmon: Make the check for critical temp valid consistent

On 05/21/2014 04:22 PM, Aaron Lu wrote:
> On 05/21/2014 01:57 PM, Kui Zhang wrote:
>> Hello,
>>
>> I get following error when rmmod thermal.
>>
>> rmmod  thermal
>> Killed

While dealing with this problem, I found another problem that also
results in a kernel crash on thermal module removal:

From: Aaron Lu <aaron.lu@intel.com>
Date: Wed, 21 May 2014 16:05:38 +0800
Subject: [PATCH] thermal: hwmon: Make the check for critical temp valid consistent

We used the tz->ops->get_crit_temp && !tz->ops->get_crit_temp(tz, temp)
to decide if we need to create the temp_crit attribute file but we just
check if tz->ops->get_crit_temp exists to decide if we need to remove
that attribute file. Some ACPI thermal zone doesn't have a valid critical
trip point and that would result in removing a non-existent device file
on thermal module unload.

Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: default avatarAaron Lu <aaron.lu@intel.com>
Signed-off-by: default avatarZhang Rui <rui.zhang@intel.com>
parent f14d1c24
...@@ -140,6 +140,12 @@ thermal_hwmon_lookup_temp(const struct thermal_hwmon_device *hwmon, ...@@ -140,6 +140,12 @@ thermal_hwmon_lookup_temp(const struct thermal_hwmon_device *hwmon,
return NULL; return NULL;
} }
static bool thermal_zone_crit_temp_valid(struct thermal_zone_device *tz)
{
unsigned long temp;
return tz->ops->get_crit_temp && !tz->ops->get_crit_temp(tz, &temp);
}
int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
{ {
struct thermal_hwmon_device *hwmon; struct thermal_hwmon_device *hwmon;
...@@ -189,9 +195,7 @@ int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) ...@@ -189,9 +195,7 @@ int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
if (result) if (result)
goto free_temp_mem; goto free_temp_mem;
if (tz->ops->get_crit_temp) { if (thermal_zone_crit_temp_valid(tz)) {
unsigned long temperature;
if (!tz->ops->get_crit_temp(tz, &temperature)) {
snprintf(temp->temp_crit.name, snprintf(temp->temp_crit.name,
sizeof(temp->temp_crit.name), sizeof(temp->temp_crit.name),
"temp%d_crit", hwmon->count); "temp%d_crit", hwmon->count);
...@@ -204,7 +208,6 @@ int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) ...@@ -204,7 +208,6 @@ int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
if (result) if (result)
goto unregister_input; goto unregister_input;
} }
}
mutex_lock(&thermal_hwmon_list_lock); mutex_lock(&thermal_hwmon_list_lock);
if (new_hwmon_device) if (new_hwmon_device)
...@@ -250,7 +253,7 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) ...@@ -250,7 +253,7 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
} }
device_remove_file(hwmon->device, &temp->temp_input.attr); device_remove_file(hwmon->device, &temp->temp_input.attr);
if (tz->ops->get_crit_temp) if (thermal_zone_crit_temp_valid(tz))
device_remove_file(hwmon->device, &temp->temp_crit.attr); device_remove_file(hwmon->device, &temp->temp_crit.attr);
mutex_lock(&thermal_hwmon_list_lock); mutex_lock(&thermal_hwmon_list_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment