* [PATCH] wifi: ath10k: consistently use kstrtoX_from_user() functions
@ 2023-09-20 11:52 Dmitry Antipov
2023-09-20 14:20 ` kernel test robot
0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Antipov @ 2023-09-20 11:52 UTC (permalink / raw)
To: Jeff Johnson; +Cc: Kalle Valo, ath10k, linux-wireless, Dmitry Antipov
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>
---
Hopefully this doesn't violate "if it isn't broke, don't fix
it" rule (the same thing was recently accepted for ath9k).
---
drivers/net/wireless/ath/ath10k/debug.c | 47 +++++++---------------
drivers/net/wireless/ath/ath10k/spectral.c | 26 ++++--------
2 files changed, 22 insertions(+), 51 deletions(-)
diff --git a/drivers/net/wireless/ath/ath10k/debug.c b/drivers/net/wireless/ath/ath10k/debug.c
index f9518e1c9903..ea6e0d50e933 100644
--- a/drivers/net/wireless/ath/ath10k/debug.c
+++ b/drivers/net/wireless/ath/ath10k/debug.c
@@ -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: %ld\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 = {
diff --git a/drivers/net/wireless/ath/ath10k/spectral.c b/drivers/net/wireless/ath/ath10k/spectral.c
index 68254a967ccb..2240994390ed 100644
--- a/drivers/net/wireless/ath/ath10k/spectral.c
+++ b/drivers/net/wireless/ath/ath10k/spectral.c
@@ -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;
--
2.41.0
_______________________________________________
ath10k mailing list
ath10k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath10k
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] wifi: ath10k: consistently use kstrtoX_from_user() functions
2023-09-20 11:52 [PATCH] wifi: ath10k: consistently use kstrtoX_from_user() functions Dmitry Antipov
@ 2023-09-20 14:20 ` kernel test robot
2023-09-20 15:39 ` [PATCH] [v2] " Dmitry Antipov
0 siblings, 1 reply; 5+ messages in thread
From: kernel test robot @ 2023-09-20 14:20 UTC (permalink / raw)
To: Dmitry Antipov, Jeff Johnson
Cc: oe-kbuild-all, Kalle Valo, ath10k, linux-wireless, Dmitry Antipov
Hi Dmitry,
kernel test robot noticed the following build warnings:
[auto build test WARNING on kvalo-ath/ath-next]
[also build test WARNING on wireless-next/main wireless/main linus/master v6.6-rc2 next-20230920]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Dmitry-Antipov/wifi-ath10k-consistently-use-kstrtoX_from_user-functions/20230920-195625
base: https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git ath-next
patch link: https://lore.kernel.org/r/20230920115249.38296-1-dmantipov%40yandex.ru
patch subject: [PATCH] wifi: ath10k: consistently use kstrtoX_from_user() functions
config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20230920/202309202242.GlXozks6-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230920/202309202242.GlXozks6-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202309202242.GlXozks6-lkp@intel.com/
All warnings (new ones prefixed by >>):
drivers/net/wireless/ath/ath10k/debug.c: In function 'ath10k_write_btcoex':
>> drivers/net/wireless/ath/ath10k/debug.c:1996:69: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'ssize_t' {aka 'int'} [-Wformat=]
1996 | ath10k_warn(ar, "failed to enable btcoex: %ld\n", ret);
| ~~^ ~~~
| | |
| | ssize_t {aka int}
| long int
| %d
vim +1996 drivers/net/wireless/ath/ath10k/debug.c
1961
1962 static ssize_t ath10k_write_btcoex(struct file *file,
1963 const char __user *ubuf,
1964 size_t count, loff_t *ppos)
1965 {
1966 struct ath10k *ar = file->private_data;
1967 ssize_t ret;
1968 bool val;
1969 u32 pdev_param;
1970
1971 ret = kstrtobool_from_user(ubuf, count, &val);
1972 if (ret)
1973 return ret;
1974
1975 if (!ar->coex_support)
1976 return -EOPNOTSUPP;
1977
1978 mutex_lock(&ar->conf_mutex);
1979
1980 if (ar->state != ATH10K_STATE_ON &&
1981 ar->state != ATH10K_STATE_RESTARTED) {
1982 ret = -ENETDOWN;
1983 goto exit;
1984 }
1985
1986 if (!(test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags) ^ val)) {
1987 ret = count;
1988 goto exit;
1989 }
1990
1991 pdev_param = ar->wmi.pdev_param->enable_btcoex;
1992 if (test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
1993 ar->running_fw->fw_file.fw_features)) {
1994 ret = ath10k_wmi_pdev_set_param(ar, pdev_param, val);
1995 if (ret) {
> 1996 ath10k_warn(ar, "failed to enable btcoex: %ld\n", ret);
1997 ret = count;
1998 goto exit;
1999 }
2000 } else {
2001 ath10k_info(ar, "restarting firmware due to btcoex change");
2002 ath10k_core_start_recovery(ar);
2003 }
2004
2005 if (val)
2006 set_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
2007 else
2008 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
2009
2010 ret = count;
2011
2012 exit:
2013 mutex_unlock(&ar->conf_mutex);
2014
2015 return ret;
2016 }
2017
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
_______________________________________________
ath10k mailing list
ath10k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath10k
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] [v2] wifi: ath10k: consistently use kstrtoX_from_user() functions
2023-09-20 14:20 ` kernel test robot
@ 2023-09-20 15:39 ` Dmitry Antipov
2023-09-20 19:20 ` Jeff Johnson
2023-10-02 16:54 ` Kalle Valo
0 siblings, 2 replies; 5+ messages in thread
From: Dmitry Antipov @ 2023-09-20 15:39 UTC (permalink / raw)
To: Jeff Johnson; +Cc: Kalle Valo, ath10k, linux-wireless, Dmitry Antipov
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>
---
v2: fix ath10k_warn() format specifier (kernel test robot)
---
drivers/net/wireless/ath/ath10k/debug.c | 47 +++++++---------------
drivers/net/wireless/ath/ath10k/spectral.c | 26 ++++--------
2 files changed, 22 insertions(+), 51 deletions(-)
diff --git a/drivers/net/wireless/ath/ath10k/debug.c b/drivers/net/wireless/ath/ath10k/debug.c
index f9518e1c9903..5a8c74db974d 100644
--- a/drivers/net/wireless/ath/ath10k/debug.c
+++ b/drivers/net/wireless/ath/ath10k/debug.c
@@ -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 = {
diff --git a/drivers/net/wireless/ath/ath10k/spectral.c b/drivers/net/wireless/ath/ath10k/spectral.c
index 68254a967ccb..2240994390ed 100644
--- a/drivers/net/wireless/ath/ath10k/spectral.c
+++ b/drivers/net/wireless/ath/ath10k/spectral.c
@@ -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;
--
2.41.0
_______________________________________________
ath10k mailing list
ath10k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath10k
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] [v2] wifi: ath10k: consistently use kstrtoX_from_user() functions
2023-09-20 15:39 ` [PATCH] [v2] " Dmitry Antipov
@ 2023-09-20 19:20 ` Jeff Johnson
2023-10-02 16:54 ` Kalle Valo
1 sibling, 0 replies; 5+ messages in thread
From: Jeff Johnson @ 2023-09-20 19:20 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: Kalle Valo, ath10k, linux-wireless
On 9/20/2023 8:39 AM, Dmitry Antipov wrote:
> 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>
...
> + ssize_t ret;
curious why you changed this, especially given that you were bitten by
the format change required. I would have left this as int and just let
it promote to size_t or ssize_t as needed.
That said:
Acked-by: Jeff Johnson <quic_jjohnson@quicinc.com>
P.S.:
> Hopefully this doesn't violate "if it isn't broke, don't fix
> it" rule (the same thing was recently accepted for ath9k).
Patches that are very self-contained are more likely to be reviewed and
accepted. But the maintainers don't have infinite bandwidth...
/jeff
_______________________________________________
ath10k mailing list
ath10k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath10k
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] [v2] wifi: ath10k: consistently use kstrtoX_from_user() functions
2023-09-20 15:39 ` [PATCH] [v2] " Dmitry Antipov
2023-09-20 19:20 ` Jeff Johnson
@ 2023-10-02 16:54 ` Kalle Valo
1 sibling, 0 replies; 5+ messages in thread
From: Kalle Valo @ 2023-10-02 16:54 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: Jeff Johnson, ath10k, linux-wireless, Dmitry Antipov
Dmitry Antipov <dmantipov@yandex.ru> wrote:
> 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>
Patch applied to ath-next branch of ath.git, thanks.
3fcb81420aca wifi: ath10k: consistently use kstrtoX_from_user() functions
--
https://patchwork.kernel.org/project/linux-wireless/patch/20230920154018.48314-1-dmantipov@yandex.ru/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
_______________________________________________
ath10k mailing list
ath10k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath10k
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-10-02 16:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-20 11:52 [PATCH] wifi: ath10k: consistently use kstrtoX_from_user() functions Dmitry Antipov
2023-09-20 14:20 ` kernel test robot
2023-09-20 15:39 ` [PATCH] [v2] " Dmitry Antipov
2023-09-20 19:20 ` Jeff Johnson
2023-10-02 16:54 ` 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).