Skip to content

Commit 879c9dc

Browse files
lukaszluba-armrafaeljw
authored andcommitted
thermal/sysfs: Update instance->weight under tz lock
User space can change the weight of a thermal instance via sysfs while the .throttle() callback is running for a governor, because weight_store() does not use the zone lock. The IPA governor uses instance weight values for power calculations and caches the sum of them as total_weight, so it gets confused when one of them changes while its .throttle() callback is running. To prevent that from happening, use thermal zone locking in weight_store(). Signed-off-by: Lukasz Luba <lukasz.luba@arm.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent e3ecd57 commit 879c9dc

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/thermal/thermal_sysfs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,11 @@ ssize_t weight_store(struct device *dev, struct device_attribute *attr,
936936
return ret;
937937

938938
instance = container_of(attr, struct thermal_instance, weight_attr);
939+
940+
/* Don't race with governors using the 'weight' value */
941+
mutex_lock(&instance->tz->lock);
939942
instance->weight = weight;
943+
mutex_unlock(&instance->tz->lock);
940944

941945
return count;
942946
}

0 commit comments

Comments
 (0)