* [PATCH] rtlwifi: fix error codes in rtl_debugfs_set_write_h2c()
@ 2022-05-17 11:48 Dan Carpenter
2022-05-30 11:17 ` wifi: " Kalle Valo
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2022-05-17 11:48 UTC (permalink / raw)
To: Ping-Ke Shih; +Cc: Kalle Valo, Paolo Abeni, linux-wireless, kernel-janitors
If the copy_from_user() fails or the user gives invalid date then the
correct thing to do is to return a negative error code. (Currently it
returns success).
I made a copy additional related cleanups:
1) There is no need to check "buffer" for NULL. That's handled by
copy_from_user().
2) The "h2c_len" variable cannot be negative because it is unsigned
and because sscanf() does not return negative error codes.
Fixes: 610247f46feb ("rtlwifi: Improve debugging by using debugfs")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/net/wireless/realtek/rtlwifi/debug.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtlwifi/debug.c b/drivers/net/wireless/realtek/rtlwifi/debug.c
index 901cdfe3723c..0b1bc04cb6ad 100644
--- a/drivers/net/wireless/realtek/rtlwifi/debug.c
+++ b/drivers/net/wireless/realtek/rtlwifi/debug.c
@@ -329,8 +329,8 @@ static ssize_t rtl_debugfs_set_write_h2c(struct file *filp,
tmp_len = (count > sizeof(tmp) - 1 ? sizeof(tmp) - 1 : count);
- if (!buffer || copy_from_user(tmp, buffer, tmp_len))
- return count;
+ if (copy_from_user(tmp, buffer, tmp_len))
+ return -EFAULT;
tmp[tmp_len] = '\0';
@@ -340,8 +340,8 @@ static ssize_t rtl_debugfs_set_write_h2c(struct file *filp,
&h2c_data[4], &h2c_data[5],
&h2c_data[6], &h2c_data[7]);
- if (h2c_len <= 0)
- return count;
+ if (h2c_len == 0)
+ return -EINVAL;
for (i = 0; i < h2c_len; i++)
h2c_data_packed[i] = (u8)h2c_data[i];
--
2.35.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: wifi: rtlwifi: fix error codes in rtl_debugfs_set_write_h2c()
2022-05-17 11:48 [PATCH] rtlwifi: fix error codes in rtl_debugfs_set_write_h2c() Dan Carpenter
@ 2022-05-30 11:17 ` Kalle Valo
0 siblings, 0 replies; 2+ messages in thread
From: Kalle Valo @ 2022-05-30 11:17 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Ping-Ke Shih, Paolo Abeni, linux-wireless, kernel-janitors
Dan Carpenter <dan.carpenter@oracle.com> wrote:
> If the copy_from_user() fails or the user gives invalid date then the
> correct thing to do is to return a negative error code. (Currently it
> returns success).
>
> I made a copy additional related cleanups:
> 1) There is no need to check "buffer" for NULL. That's handled by
> copy_from_user().
> 2) The "h2c_len" variable cannot be negative because it is unsigned
> and because sscanf() does not return negative error codes.
>
> Fixes: 610247f46feb ("rtlwifi: Improve debugging by using debugfs")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Patch applied to wireless-next.git, thanks.
b88d28146c30 wifi: rtlwifi: fix error codes in rtl_debugfs_set_write_h2c()
--
https://patchwork.kernel.org/project/linux-wireless/patch/YoOLnDkHgVltyXK7@kili/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-30 11:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-17 11:48 [PATCH] rtlwifi: fix error codes in rtl_debugfs_set_write_h2c() Dan Carpenter
2022-05-30 11:17 ` wifi: " Kalle Valo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.