thermal: lock the thermal zone when switching governors
authorJavi Merino <javi.merino@arm.com>
Tue, 25 Nov 2014 16:00:33 +0000 (16:00 +0000)
committerZhang Rui <rui.zhang@intel.com>
Mon, 8 Dec 2014 04:10:44 +0000 (12:10 +0800)
Currently, userspace can request a governor change while the governor
itself is running.  Grab the thermal zone lock when changing the
governor to prevent this race.

Signed-off-by: Javi Merino <javi.merino@arm.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
drivers/thermal/thermal_core.c

index 5aa57736fa9e7011b10a8618847635f26d593401..7b723c7c4cae3d949f205f2b6a3d9215f50118d4 100644 (file)
@@ -757,6 +757,7 @@ policy_store(struct device *dev, struct device_attribute *attr,
        snprintf(name, sizeof(name), "%s", buf);
 
        mutex_lock(&thermal_governor_lock);
+       mutex_lock(&tz->lock);
 
        gov = __find_governor(strim(name));
        if (!gov)
@@ -766,6 +767,7 @@ policy_store(struct device *dev, struct device_attribute *attr,
        ret = count;
 
 exit:
+       mutex_unlock(&tz->lock);
        mutex_unlock(&thermal_governor_lock);
        return ret;
 }