PM / QoS: Improve sysfs pm_qos_latency_tolerance validation
authorAndrew Lutomirski <luto@kernel.org>
Wed, 30 Nov 2016 01:11:50 +0000 (17:11 -0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 30 Nov 2016 21:34:23 +0000 (22:34 +0100)
Negative values are special.  Don't let users write them directly.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/sysfs.c

index a7b46798c81d0452149907e153ae149830fdbceb..33b4b902741aa3933a72afb7cb49252d65289911 100644 (file)
@@ -263,7 +263,11 @@ static ssize_t pm_qos_latency_tolerance_store(struct device *dev,
        s32 value;
        int ret;
 
-       if (kstrtos32(buf, 0, &value)) {
+       if (kstrtos32(buf, 0, &value) == 0) {
+               /* Users can't write negative values directly */
+               if (value < 0)
+                       return -EINVAL;
+       } else {
                if (!strcmp(buf, "auto") || !strcmp(buf, "auto\n"))
                        value = PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT;
                else if (!strcmp(buf, "any") || !strcmp(buf, "any\n"))