Re: [PATCH] devfreq: add error check for sscanf in userspace governor

2017-08-08 Thread Saravana Kannan

On 08/07/2017 11:56 PM, Pavan Kondeti wrote:

Hi Santosh,

On Mon, Aug 7, 2017 at 6:36 PM, Santosh Mardi  wrote:

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.

Signed-off-by: Santosh Mardi 
---
  drivers/devfreq/governor_userspace.c | 5 -
  1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/devfreq/governor_userspace.c 
b/drivers/devfreq/governor_userspace.c
index 77028c2..1d0c9cc 100644
--- a/drivers/devfreq/governor_userspace.c
+++ b/drivers/devfreq/governor_userspace.c
@@ -53,12 +53,15 @@ static ssize_t store_freq(struct device *dev, struct 
device_attribute *attr,
 mutex_lock(>lock);
 data = devfreq->data;

-   sscanf(buf, "%lu", );
+   err = sscanf(buf, "%lu", );


Also, we could just use kstroul().


+   if (err != 1)
+   goto out;


You can save this goto statement by moving this sscanf checking to
before taking the mutex.


 data->user_frequency = wanted;
 data->valid = true;
 err = update_devfreq(devfreq);
 if (err == 0)
 err = count;
+out:
 mutex_unlock(>lock);
 return err;
  }
--
1.9.1



-Saravana


--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project


Re: [PATCH] devfreq: add error check for sscanf in userspace governor

2017-08-08 Thread Saravana Kannan

On 08/07/2017 11:56 PM, Pavan Kondeti wrote:

Hi Santosh,

On Mon, Aug 7, 2017 at 6:36 PM, Santosh Mardi  wrote:

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.

Signed-off-by: Santosh Mardi 
---
  drivers/devfreq/governor_userspace.c | 5 -
  1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/devfreq/governor_userspace.c 
b/drivers/devfreq/governor_userspace.c
index 77028c2..1d0c9cc 100644
--- a/drivers/devfreq/governor_userspace.c
+++ b/drivers/devfreq/governor_userspace.c
@@ -53,12 +53,15 @@ static ssize_t store_freq(struct device *dev, struct 
device_attribute *attr,
 mutex_lock(>lock);
 data = devfreq->data;

-   sscanf(buf, "%lu", );
+   err = sscanf(buf, "%lu", );


Also, we could just use kstroul().


+   if (err != 1)
+   goto out;


You can save this goto statement by moving this sscanf checking to
before taking the mutex.


 data->user_frequency = wanted;
 data->valid = true;
 err = update_devfreq(devfreq);
 if (err == 0)
 err = count;
+out:
 mutex_unlock(>lock);
 return err;
  }
--
1.9.1



-Saravana


--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project


Re: [PATCH] devfreq: add error check for sscanf in userspace governor

2017-08-08 Thread Pavan Kondeti
Hi Santosh,

On Mon, Aug 7, 2017 at 6:36 PM, Santosh Mardi  wrote:
> 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.
>
> Signed-off-by: Santosh Mardi 
> ---
>  drivers/devfreq/governor_userspace.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/devfreq/governor_userspace.c 
> b/drivers/devfreq/governor_userspace.c
> index 77028c2..1d0c9cc 100644
> --- a/drivers/devfreq/governor_userspace.c
> +++ b/drivers/devfreq/governor_userspace.c
> @@ -53,12 +53,15 @@ static ssize_t store_freq(struct device *dev, struct 
> device_attribute *attr,
> mutex_lock(>lock);
> data = devfreq->data;
>
> -   sscanf(buf, "%lu", );
> +   err = sscanf(buf, "%lu", );
> +   if (err != 1)
> +   goto out;

You can save this goto statement by moving this sscanf checking to
before taking the mutex.

> data->user_frequency = wanted;
> data->valid = true;
> err = update_devfreq(devfreq);
> if (err == 0)
> err = count;
> +out:
> mutex_unlock(>lock);
> return err;
>  }
> --
> 1.9.1
>


-- 
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


Re: [PATCH] devfreq: add error check for sscanf in userspace governor

2017-08-08 Thread Pavan Kondeti
Hi Santosh,

On Mon, Aug 7, 2017 at 6:36 PM, Santosh Mardi  wrote:
> 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.
>
> Signed-off-by: Santosh Mardi 
> ---
>  drivers/devfreq/governor_userspace.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/devfreq/governor_userspace.c 
> b/drivers/devfreq/governor_userspace.c
> index 77028c2..1d0c9cc 100644
> --- a/drivers/devfreq/governor_userspace.c
> +++ b/drivers/devfreq/governor_userspace.c
> @@ -53,12 +53,15 @@ static ssize_t store_freq(struct device *dev, struct 
> device_attribute *attr,
> mutex_lock(>lock);
> data = devfreq->data;
>
> -   sscanf(buf, "%lu", );
> +   err = sscanf(buf, "%lu", );
> +   if (err != 1)
> +   goto out;

You can save this goto statement by moving this sscanf checking to
before taking the mutex.

> data->user_frequency = wanted;
> data->valid = true;
> err = update_devfreq(devfreq);
> if (err == 0)
> err = count;
> +out:
> mutex_unlock(>lock);
> return err;
>  }
> --
> 1.9.1
>


-- 
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


Re: [PATCH] devfreq: add error check for sscanf in userspace governor

2017-08-07 Thread Chanwoo Choi
Hi,

On 2017년 08월 07일 22:06, Santosh Mardi wrote:
> 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.
> 
> Signed-off-by: Santosh Mardi 
> ---
>  drivers/devfreq/governor_userspace.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/devfreq/governor_userspace.c 
> b/drivers/devfreq/governor_userspace.c
> index 77028c2..1d0c9cc 100644
> --- a/drivers/devfreq/governor_userspace.c
> +++ b/drivers/devfreq/governor_userspace.c
> @@ -53,12 +53,15 @@ static ssize_t store_freq(struct device *dev, struct 
> device_attribute *attr,
>   mutex_lock(>lock);
>   data = devfreq->data;
>  
> - sscanf(buf, "%lu", );
> + err = sscanf(buf, "%lu", );
> + if (err != 1)
> + goto out;
>   data->user_frequency = wanted;
>   data->valid = true;
>   err = update_devfreq(devfreq);
>   if (err == 0)
>   err = count;
> +out:
>   mutex_unlock(>lock);
>   return err;
>  }
> 

Looks good to me.
Reviewed-by: Chanwoo Choi 

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics


Re: [PATCH] devfreq: add error check for sscanf in userspace governor

2017-08-07 Thread Chanwoo Choi
Hi,

On 2017년 08월 07일 22:06, Santosh Mardi wrote:
> 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.
> 
> Signed-off-by: Santosh Mardi 
> ---
>  drivers/devfreq/governor_userspace.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/devfreq/governor_userspace.c 
> b/drivers/devfreq/governor_userspace.c
> index 77028c2..1d0c9cc 100644
> --- a/drivers/devfreq/governor_userspace.c
> +++ b/drivers/devfreq/governor_userspace.c
> @@ -53,12 +53,15 @@ static ssize_t store_freq(struct device *dev, struct 
> device_attribute *attr,
>   mutex_lock(>lock);
>   data = devfreq->data;
>  
> - sscanf(buf, "%lu", );
> + err = sscanf(buf, "%lu", );
> + if (err != 1)
> + goto out;
>   data->user_frequency = wanted;
>   data->valid = true;
>   err = update_devfreq(devfreq);
>   if (err == 0)
>   err = count;
> +out:
>   mutex_unlock(>lock);
>   return err;
>  }
> 

Looks good to me.
Reviewed-by: Chanwoo Choi 

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics


RE: [PATCH] devfreq: add error check for sscanf in userspace governor

2017-08-07 Thread MyungJoo Ham
> 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.
> 
> Signed-off-by: Santosh Mardi 

Acked-by: MyungJoo Ham 

> ---
>  drivers/devfreq/governor_userspace.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)


RE: [PATCH] devfreq: add error check for sscanf in userspace governor

2017-08-07 Thread MyungJoo Ham
> 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.
> 
> Signed-off-by: Santosh Mardi 

Acked-by: MyungJoo Ham 

> ---
>  drivers/devfreq/governor_userspace.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)


[PATCH] devfreq: add error check for sscanf in userspace governor

2017-08-07 Thread Santosh Mardi
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.

Signed-off-by: Santosh Mardi 
---
 drivers/devfreq/governor_userspace.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/devfreq/governor_userspace.c 
b/drivers/devfreq/governor_userspace.c
index 77028c2..1d0c9cc 100644
--- a/drivers/devfreq/governor_userspace.c
+++ b/drivers/devfreq/governor_userspace.c
@@ -53,12 +53,15 @@ static ssize_t store_freq(struct device *dev, struct 
device_attribute *attr,
mutex_lock(>lock);
data = devfreq->data;
 
-   sscanf(buf, "%lu", );
+   err = sscanf(buf, "%lu", );
+   if (err != 1)
+   goto out;
data->user_frequency = wanted;
data->valid = true;
err = update_devfreq(devfreq);
if (err == 0)
err = count;
+out:
mutex_unlock(>lock);
return err;
 }
-- 
1.9.1



[PATCH] devfreq: add error check for sscanf in userspace governor

2017-08-07 Thread Santosh Mardi
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.

Signed-off-by: Santosh Mardi 
---
 drivers/devfreq/governor_userspace.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/devfreq/governor_userspace.c 
b/drivers/devfreq/governor_userspace.c
index 77028c2..1d0c9cc 100644
--- a/drivers/devfreq/governor_userspace.c
+++ b/drivers/devfreq/governor_userspace.c
@@ -53,12 +53,15 @@ static ssize_t store_freq(struct device *dev, struct 
device_attribute *attr,
mutex_lock(>lock);
data = devfreq->data;
 
-   sscanf(buf, "%lu", );
+   err = sscanf(buf, "%lu", );
+   if (err != 1)
+   goto out;
data->user_frequency = wanted;
data->valid = true;
err = update_devfreq(devfreq);
if (err == 0)
err = count;
+out:
mutex_unlock(>lock);
return err;
 }
-- 
1.9.1



[PATCH] devfreq: add error check for sscanf in userspace governor

2017-08-07 Thread Santosh Mardi
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(-)

-- 
1.9.1



[PATCH] devfreq: add error check for sscanf in userspace governor

2017-08-07 Thread Santosh Mardi
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(-)

-- 
1.9.1