devfreq: add error check for sscanf in userspace governor
PATCH 1/1 devfreq: add error check for sscanf in userspace governor
What this patch does:
Current implementation of store_freq function in devfreq userspace governor executes further, even if error is returned from sscanf. This will result in setting up wrong frequency value.
This patch adds proper error check to bail out if any error is returned.
Santosh Mardi (1):
devfreq: add error check for sscanf in userspace governor
drivers/devfreq/governor_userspace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Signature · 1 line
1.9.1
PATCH 1/1 devfreq: add error check for sscanf in userspace governor
store_freq function of devfreq userspace governor executes further, even if error is returned from sscanf, this will result in setting up wrong frequency value.
Add proper error check to bail out if any error is returned.
--- drivers/devfreq/governor_userspace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/devfreq/governor_userspace.c +4 -1
@@ -53,12 +53,15 @@ static ssize_t store_freq(struct device *dev, struct device_attribute *attr,mutex_lock (&devfreq->lock); data = devfreq->data; -sscanf (buf,"%lu" , &wanted); + err =sscanf (buf,"%lu" , &wanted); +if (err !=1 ) + goto out; data->user_frequency = wanted; data->valid = true; err =update_devfreq (devfreq);if (err ==0 ) err = count; +out:mutex_unlock (&devfreq->lock);return err; }
Signature · 1 line
1.9.1
Quoted 7 lines
store_freqfunction of devfreq userspace governor executes further, even if error is returned from sscanf, this will result in setting up wrong frequency value.Add proper error check to bail out if any error is returned.
Signed-off-by Santosh Mardi <[email protected]>
Quoted 3 lines
--- drivers/devfreq/governor_userspace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Hi,
Quoted 23 lines · Santosh Mardi
store_freqfunction of devfreq userspace governor executes further, even if error is returned from sscanf, this will result in setting up wrong frequency value.Add proper error check to bail out if any error is returned.
Signed-off-by Santosh Mardi <[email protected]>--- drivers/devfreq/governor_userspace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/devfreq/governor_userspace.c +2
-1@@ -53,12 +53,15 @@ static ssize_t store_freq(struct device *dev, struct device_attribute *attr,mutex_lock (&devfreq->lock); data = devfreq->data; -sscanf (buf,"%lu" , &wanted); + err =sscanf (buf,"%lu" , &wanted); +if (err !=1 )
drivers/devfreq/governor_userspace.c static ssize_t store_freq(struct device *dev, struct device_attribute *attr, · line 67
Quoted 10 lines
drivers/devfreq/governor_userspace.c +2
-0+ goto out; data->user_frequency = wanted; data->valid = true; err =update_devfreq (devfreq);if (err ==0 ) err = count; +out:mutex_unlock (&devfreq->lock);return err; }
Looks good to me.
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics
Hi Santosh,
Quoted 16 lines · Santosh Mardi
store_freqfunction of devfreq userspace governor executes further, even if error is returned from sscanf, this will result in setting up wrong frequency value.Add proper error check to bail out if any error is returned.
Signed-off-by Santosh Mardi <[email protected]>--- drivers/devfreq/governor_userspace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/devfreq/governor_userspace.c +0
-0
drivers/devfreq/governor_userspace.c static ssize_t store_freq(struct device *dev, struct device_attribute *attr, · line 58
Quoted 7 lines
drivers/devfreq/governor_userspace.c +3
-1@@ -53,12 +53,15 @@ static ssize_t store_freq(struct device *dev, struct device_attribute *attr,mutex_lock (&devfreq->lock); data = devfreq->data; -sscanf (buf,"%lu" , &wanted); + err =sscanf (buf,"%lu" , &wanted); +if (err !=1 ) + goto out;
You can save this goto statement by moving this sscanf checking to before taking the mutex.
Quoted 12 lines
drivers/devfreq/governor_userspace.c +1
-1data->user_frequency = wanted; data->valid = true; err =update_devfreq (devfreq);if (err ==0 ) err = count; +out:mutex_unlock (&devfreq->lock);return err; } --1.9.1
Signature · 3 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Quoted 22 lines · Pavan Kondeti
Hi Santosh,
Quoted 19 lines · Santosh Mardi
store_freqfunction of devfreq userspace governor executes further, even if error is returned from sscanf, this will result in setting up wrong frequency value.Add proper error check to bail out if any error is returned.
Signed-off-by Santosh Mardi <[email protected]>--- drivers/devfreq/governor_userspace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/devfreq/governor_userspace.c +0
-0@@ -53,12 +53,15 @@ static ssize_t store_freq(struct device *dev, struct device_attribute *attr,mutex_lock (&devfreq->lock); data = devfreq->data;
Quoted 2 lines
drivers/devfreq/governor_userspace.c static ssize_t store_freq(struct device *dev, struct device_attribute *attr, · line 56
Quoted 2 lines
drivers/devfreq/governor_userspace.c +1
-1-sscanf (buf,"%lu" , &wanted); + err =sscanf (buf,"%lu" , &wanted);
Also, we could just use kstroul().
Quoted 18 lines
drivers/devfreq/governor_userspace.c static ssize_t store_freq(struct device *dev, struct device_attribute *attr, · line 58
Quoted 2 lines
drivers/devfreq/governor_userspace.c +2
-0+if (err !=1 ) + goto out;You can save this goto statement by moving this sscanf checking to before taking the mutex.
Quoted 12 lines
drivers/devfreq/governor_userspace.c +1
-1data->user_frequency = wanted; data->valid = true; err =update_devfreq (devfreq);if (err ==0 ) err = count; +out:mutex_unlock (&devfreq->lock);return err; } --1.9.1
-Saravana
Signature · 3 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project