diff mbox

[1/3] dev_pm_qos: Improve sysfs pm_qos_latency_tolerance validation

Message ID 9f642daf2787251258336c4ce93b1d3090afd590.1480468027.git.luto@kernel.org (mailing list archive)
State Accepted, archived
Delegated to: Rafael Wysocki
Headers show

Commit Message

Andy Lutomirski Nov. 30, 2016, 1:11 a.m. UTC
Negative values are special.  Don't let users write them directly.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 drivers/base/power/sysfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Pavel Machek Dec. 5, 2016, 11:19 a.m. UTC | #1
On Tue 2016-11-29 17:11:50, Andy Lutomirski wrote:
> Negative values are special.  Don't let users write them directly.
> 
> Signed-off-by: Andy Lutomirski <luto@kernel.org>

Acked-by: Pavel Machek <pavel@ucw.cz>

> --- a/drivers/base/power/sysfs.c
> +++ b/drivers/base/power/sysfs.c
> @@ -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"))
diff mbox

Patch

diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index a7b46798c81d..33b4b902741a 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -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"))