@@ -696,16 +696,27 @@ static ssize_t
policy_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
- int ret = -EINVAL;
+ int ret;
struct thermal_zone_device *tz = to_thermal_zone(dev);
struct thermal_governor *gov;
+ char str_gov[THERMAL_NAME_LENGTH];
+ char format[6]; /* enough for 3 digit format width */
+
+ ret = snprintf(format, sizeof(format), "%%%ds",
+ THERMAL_NAME_LENGTH - 1);
+ if (ret < 0)
+ return ret;
+ ret = sscanf(buf, format, str_gov);
+ if (ret <= 0)
+ return -EINVAL;
mutex_lock(&thermal_governor_lock);
- gov = __find_governor(buf);
- if (!gov)
+ gov = __find_governor(str_gov);
+ if (!gov) {
+ ret = -EINVAL;
goto exit;
-
+ }
tz->governor = gov;
ret = count;