Skip to content

Commit

Permalink
PM / devfreq: fix sscanf handling for writable sysfs entries
Browse files Browse the repository at this point in the history
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

Signed-off-by: Nishanth Menon <nm@ti.com>
Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Nishanth Menon authored and Rafael J. Wysocki committed Nov 14, 2012
1 parent c5b4a1c commit 12e2626
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions drivers/devfreq/devfreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,11 @@ static ssize_t store_polling_interval(struct device *dev,

ret = sscanf(buf, "%u", &value);
if (ret != 1)
goto out;
return -EINVAL;

df->governor->event_handler(df, DEVFREQ_GOV_INTERVAL, &value);
ret = count;

out:
return ret;
}

Expand All @@ -515,7 +514,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;
Expand All @@ -529,7 +528,6 @@ static ssize_t store_min_freq(struct device *dev, struct device_attribute *attr,
ret = count;
unlock:
mutex_unlock(&df->lock);
out:
return ret;
}

Expand All @@ -549,7 +547,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;
Expand All @@ -563,7 +561,6 @@ static ssize_t store_max_freq(struct device *dev, struct device_attribute *attr,
ret = count;
unlock:
mutex_unlock(&df->lock);
out:
return ret;
}

Expand Down

0 comments on commit 12e2626

Please sign in to comment.