* [PATCH] wifi: rtw88: use kstrtoX_from_user() in debugfs handlers
@ 2024-01-10 13:29 Dmitry Antipov
2024-01-15 0:30 ` Ping-Ke Shih
2024-01-18 9:33 ` Kalle Valo
0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Antipov @ 2024-01-10 13:29 UTC (permalink / raw)
To: Ping-Ke Shih; +Cc: Kalle Valo, linux-wireless, Dmitry Antipov
When 'sscanf()' is not needed to scan an input, prefer common
'kstrtoX_from_user()' over 'rtw_debugfs_copy_from_user()' with
following 'kstrtoX()'. Minor adjustments, compile tested only.
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
drivers/net/wireless/realtek/rtw88/debug.c | 44 ++++------------------
1 file changed, 8 insertions(+), 36 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw88/debug.c b/drivers/net/wireless/realtek/rtw88/debug.c
index 1b2ad81838be..5b2036798159 100644
--- a/drivers/net/wireless/realtek/rtw88/debug.c
+++ b/drivers/net/wireless/realtek/rtw88/debug.c
@@ -316,23 +316,13 @@ static ssize_t rtw_debugfs_set_single_input(struct file *filp,
{
struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
- struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
- char tmp[32 + 1];
u32 input;
- int num;
int ret;
- ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
+ ret = kstrtou32_from_user(buffer, count, 0, &input);
if (ret)
return ret;
- num = kstrtoint(tmp, 0, &input);
-
- if (num) {
- rtw_warn(rtwdev, "kstrtoint failed\n");
- return num;
- }
-
debugfs_priv->cb_data = input;
return count;
@@ -485,19 +475,12 @@ static ssize_t rtw_debugfs_set_fix_rate(struct file *filp,
struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
struct rtw_dm_info *dm_info = &rtwdev->dm_info;
u8 fix_rate;
- char tmp[32 + 1];
int ret;
- ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
+ ret = kstrtou8_from_user(buffer, count, 0, &fix_rate);
if (ret)
return ret;
- ret = kstrtou8(tmp, 0, &fix_rate);
- if (ret) {
- rtw_warn(rtwdev, "invalid args, [rate]\n");
- return ret;
- }
-
dm_info->fix_rate = fix_rate;
return count;
@@ -879,20 +862,13 @@ static ssize_t rtw_debugfs_set_coex_enable(struct file *filp,
struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
struct rtw_coex *coex = &rtwdev->coex;
- char tmp[32 + 1];
bool enable;
int ret;
- ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
+ ret = kstrtobool_from_user(buffer, count, &enable);
if (ret)
return ret;
- ret = kstrtobool(tmp, &enable);
- if (ret) {
- rtw_warn(rtwdev, "invalid arguments\n");
- return ret;
- }
-
mutex_lock(&rtwdev->mutex);
coex->manual_control = !enable;
mutex_unlock(&rtwdev->mutex);
@@ -951,18 +927,13 @@ static ssize_t rtw_debugfs_set_fw_crash(struct file *filp,
struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
- char tmp[32 + 1];
bool input;
int ret;
- ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 1);
+ ret = kstrtobool_from_user(buffer, count, &input);
if (ret)
return ret;
- ret = kstrtobool(tmp, &input);
- if (ret)
- return -EINVAL;
-
if (!input)
return -EINVAL;
@@ -1030,11 +1001,12 @@ static ssize_t rtw_debugfs_set_dm_cap(struct file *filp,
struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
struct rtw_dm_info *dm_info = &rtwdev->dm_info;
- int bit;
+ int ret, bit;
bool en;
- if (kstrtoint_from_user(buffer, count, 10, &bit))
- return -EINVAL;
+ ret = kstrtoint_from_user(buffer, count, 10, &bit);
+ if (ret)
+ return ret;
en = bit > 0;
bit = abs(bit);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH] wifi: rtw88: use kstrtoX_from_user() in debugfs handlers
2024-01-10 13:29 [PATCH] wifi: rtw88: use kstrtoX_from_user() in debugfs handlers Dmitry Antipov
@ 2024-01-15 0:30 ` Ping-Ke Shih
2024-01-18 9:33 ` Kalle Valo
1 sibling, 0 replies; 3+ messages in thread
From: Ping-Ke Shih @ 2024-01-15 0:30 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: Kalle Valo, linux-wireless@vger.kernel.org
> -----Original Message-----
> From: Dmitry Antipov <dmantipov@yandex.ru>
> Sent: Wednesday, January 10, 2024 9:29 PM
> To: Ping-Ke Shih <pkshih@realtek.com>
> Cc: Kalle Valo <kvalo@kernel.org>; linux-wireless@vger.kernel.org; Dmitry Antipov <dmantipov@yandex.ru>
> Subject: [PATCH] wifi: rtw88: use kstrtoX_from_user() in debugfs handlers
>
> When 'sscanf()' is not needed to scan an input, prefer common
> 'kstrtoX_from_user()' over 'rtw_debugfs_copy_from_user()' with
> following 'kstrtoX()'. Minor adjustments, compile tested only.
>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] wifi: rtw88: use kstrtoX_from_user() in debugfs handlers
2024-01-10 13:29 [PATCH] wifi: rtw88: use kstrtoX_from_user() in debugfs handlers Dmitry Antipov
2024-01-15 0:30 ` Ping-Ke Shih
@ 2024-01-18 9:33 ` Kalle Valo
1 sibling, 0 replies; 3+ messages in thread
From: Kalle Valo @ 2024-01-18 9:33 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: Ping-Ke Shih, linux-wireless, Dmitry Antipov
Dmitry Antipov <dmantipov@yandex.ru> wrote:
> When 'sscanf()' is not needed to scan an input, prefer common
> 'kstrtoX_from_user()' over 'rtw_debugfs_copy_from_user()' with
> following 'kstrtoX()'. Minor adjustments, compile tested only.
>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> Acked-by: Ping-Ke Shih <pkshih@realtek.com>
Patch applied to wireless-next.git, thanks.
23b8330156e5 wifi: rtw88: use kstrtoX_from_user() in debugfs handlers
--
https://patchwork.kernel.org/project/linux-wireless/patch/20240110132930.438828-1-dmantipov@yandex.ru/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-18 9:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-10 13:29 [PATCH] wifi: rtw88: use kstrtoX_from_user() in debugfs handlers Dmitry Antipov
2024-01-15 0:30 ` Ping-Ke Shih
2024-01-18 9:33 ` Kalle Valo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).