Skip to content

Commit

Permalink
wifi: ath10k: consistently use kstrtoX_from_user() functions
Browse files Browse the repository at this point in the history
Use 'kstrtoul_from_user()', 'kstrtobool_from_user()' and
'kstrtoint_from_user()' where appropriate and thus avoid
some code duplication.

Signed-off-by: Dmitry Antipov <[email protected]>
Acked-by: Jeff Johnson <[email protected]>
Signed-off-by: Kalle Valo <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
dmantipov authored and kvalo committed Oct 2, 2023
1 parent 972754b commit 3fcb814
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 51 deletions.
47 changes: 14 additions & 33 deletions drivers/net/wireless/ath/ath10k/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1964,20 +1964,13 @@ static ssize_t ath10k_write_btcoex(struct file *file,
size_t count, loff_t *ppos)
{
struct ath10k *ar = file->private_data;
char buf[32];
size_t buf_size;
int ret;
ssize_t ret;
bool val;
u32 pdev_param;

buf_size = min(count, (sizeof(buf) - 1));
if (copy_from_user(buf, ubuf, buf_size))
return -EFAULT;

buf[buf_size] = '\0';

if (kstrtobool(buf, &val) != 0)
return -EINVAL;
ret = kstrtobool_from_user(ubuf, count, &val);
if (ret)
return ret;

if (!ar->coex_support)
return -EOPNOTSUPP;
Expand All @@ -2000,7 +1993,7 @@ static ssize_t ath10k_write_btcoex(struct file *file,
ar->running_fw->fw_file.fw_features)) {
ret = ath10k_wmi_pdev_set_param(ar, pdev_param, val);
if (ret) {
ath10k_warn(ar, "failed to enable btcoex: %d\n", ret);
ath10k_warn(ar, "failed to enable btcoex: %zd\n", ret);
ret = count;
goto exit;
}
Expand Down Expand Up @@ -2103,19 +2096,12 @@ static ssize_t ath10k_write_peer_stats(struct file *file,
size_t count, loff_t *ppos)
{
struct ath10k *ar = file->private_data;
char buf[32];
size_t buf_size;
int ret;
ssize_t ret;
bool val;

buf_size = min(count, (sizeof(buf) - 1));
if (copy_from_user(buf, ubuf, buf_size))
return -EFAULT;

buf[buf_size] = '\0';

if (kstrtobool(buf, &val) != 0)
return -EINVAL;
ret = kstrtobool_from_user(ubuf, count, &val);
if (ret)
return ret;

mutex_lock(&ar->conf_mutex);

Expand Down Expand Up @@ -2239,21 +2225,16 @@ static ssize_t ath10k_sta_tid_stats_mask_write(struct file *file,
size_t count, loff_t *ppos)
{
struct ath10k *ar = file->private_data;
char buf[32];
ssize_t len;
ssize_t ret;
u32 mask;

len = min(count, sizeof(buf) - 1);
if (copy_from_user(buf, user_buf, len))
return -EFAULT;

buf[len] = '\0';
if (kstrtoint(buf, 0, &mask))
return -EINVAL;
ret = kstrtoint_from_user(user_buf, count, 0, &mask);
if (ret)
return ret;

ar->sta_tid_stats_mask = mask;

return len;
return count;
}

static const struct file_operations fops_sta_tid_stats_mask = {
Expand Down
26 changes: 8 additions & 18 deletions drivers/net/wireless/ath/ath10k/spectral.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,16 +384,11 @@ static ssize_t write_file_spectral_count(struct file *file,
{
struct ath10k *ar = file->private_data;
unsigned long val;
char buf[32];
ssize_t len;

len = min(count, sizeof(buf) - 1);
if (copy_from_user(buf, user_buf, len))
return -EFAULT;
ssize_t ret;

buf[len] = '\0';
if (kstrtoul(buf, 0, &val))
return -EINVAL;
ret = kstrtoul_from_user(user_buf, count, 0, &val);
if (ret)
return ret;

if (val > 255)
return -EINVAL;
Expand Down Expand Up @@ -440,16 +435,11 @@ static ssize_t write_file_spectral_bins(struct file *file,
{
struct ath10k *ar = file->private_data;
unsigned long val;
char buf[32];
ssize_t len;

len = min(count, sizeof(buf) - 1);
if (copy_from_user(buf, user_buf, len))
return -EFAULT;
ssize_t ret;

buf[len] = '\0';
if (kstrtoul(buf, 0, &val))
return -EINVAL;
ret = kstrtoul_from_user(user_buf, count, 0, &val);
if (ret)
return ret;

if (val < 64 || val > SPECTRAL_ATH10K_MAX_NUM_BINS)
return -EINVAL;
Expand Down

0 comments on commit 3fcb814

Please sign in to comment.