Skip to contentSkip to conversation

PM / devfreq: fix sscanf handling for writable sysfs entries

PATCH New Nishanth Menon 1 participant 1 message Oct 15, 2012 Device frequency (devfreq)

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 PM / devfreq: fix sscanf handling for writable sysfs entries

sscanf returns 0 when an invalid parameter like:
echo -n "a">min_freq
is attempted. Returning back the return result(0) will cause the command not to return back to command prompt.

Instead, just return -EINVAL when sscanf does not return 1.

This is done for min_freq, max_freq and polling_interval

Cc MyungJoo Ham <[email protected]>
Cc Kyungmin Park <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Kevin Hilman <[email protected]>
---
 drivers/devfreq/devfreq.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/devfreq/devfreq.c +3 -5
index b146d76..9f562ae 100644
@@ -488,7 +488,7 @@ static ssize_t store_polling_interval(struct device *dev,
 
 	ret = sscanf(buf, "%u", &value);
 	if (ret != 1)
-		goto out;
+		return -EINVAL;
 
 	mutex_lock(&df->lock);
 	df->profile->polling_ms = value;
@@ -529,7 +529,7 @@ static ssize_t store_min_freq(struct device *dev, struct device_attribute *attr,
 
 	ret = sscanf(buf, "%lu", &value);
 	if (ret != 1)
-		goto out;
+		return -EINVAL;
 
 	mutex_lock(&df->lock);
 	max = df->max_freq;
@@ -543,7 +543,6 @@ static ssize_t store_min_freq(struct device *dev, struct device_attribute *attr,
 	ret = count;
 unlock:
 	mutex_unlock(&df->lock);
-out:
 	return ret;
 }
 
@@ -563,7 +562,7 @@ static ssize_t store_max_freq(struct device *dev, struct device_attribute *attr,
 
 	ret = sscanf(buf, "%lu", &value);
 	if (ret != 1)
-		goto out;
+		return -EINVAL;
 
 	mutex_lock(&df->lock);
 	min = df->min_freq;
@@ -577,7 +576,6 @@ static ssize_t store_max_freq(struct device *dev, struct device_attribute *attr,
 	ret = count;
 unlock:
 	mutex_unlock(&df->lock);
-out:
 	return ret;
 }
 
Signature · 1 line
1.7.9.5