PM / QoS: return -EINVAL for bogus strings
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 10 Jul 2017 07:21:40 +0000 (10:21 +0300)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 12 Jul 2017 12:42:37 +0000 (14:42 +0200)
In the current code, if the user accidentally writes a bogus command to
this sysfs file, then we set the latency tolerance to an uninitialized
variable.

Fixes: 2d984ad132a8 (PM / QoS: Introcuce latency tolerance device PM QoS type)
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
Cc: 3.15+ <stable@vger.kernel.org> # 3.15+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/sysfs.c

index 185a52581cfae3294f92bcb94a7de5277bbec751..156ab57bca7715238571165b14e23d54ebbbd23a 100644 (file)
@@ -272,6 +272,8 @@ static ssize_t pm_qos_latency_tolerance_store(struct device *dev,
                        value = PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT;
                else if (!strcmp(buf, "any") || !strcmp(buf, "any\n"))
                        value = PM_QOS_LATENCY_ANY;
+               else
+                       return -EINVAL;
        }
        ret = dev_pm_qos_update_user_latency_tolerance(dev, value);
        return ret < 0 ? ret : n;