Skip to contentSkip to conversation

rtw88: Fix an error code in rtw_debugfs_set_rsvd_page()

PATCH Superseded Dan Carpenter 2 participants 3 messages Feb 16, 2021 – Mar 15, 2021 1 message not in the archive

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtw88: Fix an error code in rtw_debugfs_set_rsvd_page()

The sscanf() function returns either 0 or 1 here. It doesn't return error codes. We should return -EINVAL if the string is invalid.

Fixes c376c1fc87b7 ("rtw88: add h2c command in debugfs")
---
 drivers/net/wireless/realtek/rtw88/debug.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/wireless/realtek/rtw88/debug.c +2 -5
index 948cb79050ea..99be7fcb5d71 100644
@@ -262,15 +262,12 @@ static ssize_t rtw_debugfs_set_rsvd_page(struct file *filp,
 	struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
 	char tmp[32 + 1];
 	u32 offset, page_num;
-	int num;
 
 	rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 2);
 
-	num = sscanf(tmp, "%d %d", &offset, &page_num);
-
-	if (num != 2) {
+	if (sscanf(tmp, "%d %d", &offset, &page_num) != 2) {
 		rtw_warn(rtwdev, "invalid arguments\n");
-		return num;
+		return -EINVAL;
 	}
 
 	debugfs_priv->rsvd_page.page_offset = offset;
Signature · 1 line
2.30.0
#1 lore raw
Quoted 5 lines · Dan Carpenter

The sscanf() function returns either 0 or 1 here. It doesn't return error codes. We should return -EINVAL if the string is invalid.

Fixes c376c1fc87b7 ("rtw88: add h2c command in debugfs")

Why do you remove the num variable? I think the code is more readable with it.

(Sorry, I'm not able to quote the code as I'm replying from patchwork script and it doesn't support that yet.)

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/YCwgb/4F4Y+tyE56@mwanda/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 10 lines · Kalle Valo
Quoted 5 lines · Dan Carpenter

The sscanf() function returns either 0 or 1 here. It doesn't return error codes. We should return -EINVAL if the string is invalid.

Fixes c376c1fc87b7 ("rtw88: add h2c command in debugfs")

Why do you remove the num variable? I think the code is more readable with it.

The way I wrote it is slightly more normal (457 vs 333) and we don't use "num" except for the one if statement. But I can write the other way. I'll resend.

regards,
dan carpenter