Staging: rtl8723bs: Use kstrto<type> instead of single variable sscanf
PATCH 1/1 Staging: rtl8723bs: Use kstrto<type> instead of single variable sscanf
Use kstro<type> instead of single variable sscanf to convert a string to the appropriate integer type. Also, check the return value.
Issue found by checkpatch.pl script:
Prefer kstrto<type> to single variable sscanf
--- drivers/staging/rtl8723bs/os_dep/rtw_proc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/staging/rtl8723bs/os_dep/rtw_proc.c +8 -4
@@ -70,7 +70,11 @@ static ssize_t proc_set_log_level(struct file *file, const char __user *buffer,return -EINVAL ;if (buffer && !copy_from_user (tmp, buffer,sizeof (tmp))) { -sscanf (tmp,"%d " , &log_level); +int num =kstrtoint (tmp,10 , &log_level); + +if (num !=1 ) +return count; +if (log_level >= _drv_always_ && log_level <= _drv_debug_) { GlobalDebugLevel = log_level;
@@ -476,7 +480,7 @@ ssize_t proc_set_odm_dbg_comp(struct file *file, const char __user *buffer, sizeif (buffer && !copy_from_user (tmp, buffer,sizeof (tmp))) { -int num =sscanf (tmp,"%llx" , &dbg_comp); +int num =kstrtoull (tmp,16 , &dbg_comp);if (num !=1 )return count;
@@ -510,7 +514,7 @@ ssize_t proc_set_odm_dbg_level(struct file *file, const char __user *buffer, sizif (buffer && !copy_from_user (tmp, buffer,sizeof (tmp))) { -int num =sscanf (tmp,"%u" , &dbg_level); +int num =kstrtouint (tmp,10 , &dbg_level);if (num !=1 )return count;
@@ -544,7 +548,7 @@ static ssize_t proc_set_odm_ability(struct file *file, const char __user *bufferif (buffer && !copy_from_user (tmp, buffer,sizeof (tmp))) { -int num =sscanf (tmp,"%x" , &ability); +int num =kstrtouint (tmp,16 , &ability);if (num !=1 )return count;
Signature · 1 line
2.11.0
Greg Kroah-Hartman
maintainerQuoted 17 lines · Georgiana Chelu
Use kstro<type> instead of single variable sscanf to convert a string to the appropriate integer type. Also, check the return value.
Issue found by checkpatch.pl script:
Prefer kstrto<type> to single variable sscanfSigned-off-by Georgiana Chelu <[email protected]>--- drivers/staging/rtl8723bs/os_dep/rtw_proc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)drivers/staging/rtl8723bs/os_dep/rtw_proc.c +0
-0
drivers/staging/rtl8723bs/os_dep/rtw_proc.c static ssize_t proc_set_log_level(struct file *file, const char __user *buffer, · line 76
Quoted 8 lines
drivers/staging/rtl8723bs/os_dep/rtw_proc.c +4
-1@@ -70,7 +70,11 @@ static ssize_t proc_set_log_level(struct file *file, const char __user *buffer,return -EINVAL ;if (buffer && !copy_from_user (tmp, buffer,sizeof (tmp))) { -sscanf (tmp,"%d " , &log_level); +int num =kstrtoint (tmp,10 , &log_level); + +if (num !=1 ) +return count;
How would num ever be 1 here? Did you test this?
Look at the documentation for kstrtoint() please, I think this just broke things :(
thanks,
greg k-h
Quoted 29 lines · Greg Kroah-Hartman
Quoted 17 lines · Georgiana Chelu
Use kstro<type> instead of single variable sscanf to convert a string to the appropriate integer type. Also, check the return value.
Issue found by checkpatch.pl script:
Prefer kstrto<type> to single variable sscanfSigned-off-by Georgiana Chelu <[email protected]>--- drivers/staging/rtl8723bs/os_dep/rtw_proc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)drivers/staging/rtl8723bs/os_dep/rtw_proc.c +0
-0drivers/staging/rtl8723bs/os_dep/rtw_proc.c static ssize_t proc_set_log_level(struct file *file, const char __user *buffer, · line 76
Quoted 8 lines
drivers/staging/rtl8723bs/os_dep/rtw_proc.c +4
-1@@ -70,7 +70,11 @@ static ssize_t proc_set_log_level(struct file *file, const char __user *buffer,return -EINVAL ;if (buffer && !copy_from_user (tmp, buffer,sizeof (tmp))) { -sscanf (tmp,"%d " , &log_level); +int num =kstrtoint (tmp,10 , &log_level); + +if (num !=1 ) +return count;How would num ever be 1 here? Did you test this?
Quoted 3 lines
Look at the documentation for
kstrtoint()please, I think this just broke things :(
I missed that kstrtoint and sscanf have different output on SUCCESS. The return value should be 0 in case of success. I will send the second version of the patch. Thank you!
Georgiana
Quoted 3 lines
thanks,
greg k-h