Skip to content

Commit

Permalink
wifi: rtw88: use kstrtoX_from_user() in debugfs handlers
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Ping-Ke Shih <[email protected]>
Signed-off-by: Kalle Valo <[email protected]>
Link: https://msgid.link/[email protected]
  • Loading branch information
dmantipov authored and Kalle Valo committed Jan 18, 2024
1 parent ece90a8 commit 23b8330
Showing 1 changed file with 8 additions and 36 deletions.
44 changes: 8 additions & 36 deletions drivers/net/wireless/realtek/rtw88/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 23b8330

Please sign in to comment.