[PATCH] thermal: Can't set policy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Setting policy results in invalid value error.
	>echo "step_wise" > policy
	>echo: write error: Invalid argument

Need clean up of the buffer which "echo" may add based on the
arguments, before comparing aganist list of governor names.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@xxxxxxxxxxxxxxx>
---
 drivers/thermal/thermal_core.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 4cdc3e3..ed6904f 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -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;
 
-- 
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux