wifi: ath10k: consistently use kstrtoX_from_user() functions
authorDmitry Antipov <dmantipov@yandex.ru>
Sat, 30 Sep 2023 04:54:47 +0000 (07:54 +0300)
committerKalle Valo <quic_kvalo@quicinc.com>
Mon, 2 Oct 2023 16:54:51 +0000 (19:54 +0300)
Use 'kstrtoul_from_user()', 'kstrtobool_from_user()' and
'kstrtoint_from_user()' where appropriate and thus avoid
some code duplication.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Acked-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>
Link: https://lore.kernel.org/r/20230920154018.48314-1-dmantipov@yandex.ru
drivers/net/wireless/ath/ath10k/debug.c
drivers/net/wireless/ath/ath10k/spectral.c

index fe89bc61e5317dab9fb473322a046c4e660df310..ad9cf953a2fcf2448ae6722bfdb68b073be0876c 100644 (file)
@@ -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;
@@ -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;
                }
@@ -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);
 
@@ -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 = {
index 68254a967ccbfe2086ed7ad724aa3eb48ee10b06..2240994390ed634afcd095e44003a3213da035c0 100644 (file)
@@ -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;
@@ -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;