Skip to contentSkip to conversation

Staging: rtl8723bs: Use kstrto<type> instead of single variable sscanf

PATCH New Georgiana Chelu 1 participant 1 message Oct 17, 2017 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v2 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. The return value on SUCCESS is 0.

Issue found by checkpatch.pl script:
* Prefer kstrto<type> to single variable sscanf

---

Changes in v2:
* used the right value to check the return value of kstrto<type>
* adjusted the commit message

 drivers/staging/rtl8723bs/os_dep/rtw_proc.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/staging/rtl8723bs/os_dep/rtw_proc.c +11 -7
index ce1dd6f9036f..13cddc1dbcc0 100644
@@ -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 != 0)
+			return count;
+
 		if (log_level >= _drv_always_ && log_level <= _drv_debug_)
 		{
 			GlobalDebugLevel = log_level;
@@ -478,9 +482,9 @@ ssize_t proc_set_odm_dbg_comp(struct file *file, const char __user *buffer, size
 
 	if (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)
+		if (num != 0)
 			return count;
 
 		rtw_odm_dbg_comp_set(adapter, dbg_comp);
@@ -512,9 +516,9 @@ ssize_t proc_set_odm_dbg_level(struct file *file, const char __user *buffer, siz
 
 	if (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)
+		if (num != 0)
 			return count;
 
 		rtw_odm_dbg_level_set(adapter, dbg_level);
@@ -546,9 +550,9 @@ static ssize_t proc_set_odm_ability(struct file *file, const char __user *buffer
 
 	if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
 
-		int num = sscanf(tmp, "%x", &ability);
+		int num = kstrtouint(tmp, 16, &ability);
 
-		if (num != 1)
+		if (num != 0)
 			return count;
 
 		rtw_odm_ability_set(adapter, ability);
Signature · 1 line
2.11.0