Skip to content

Commit

Permalink
wifi: rtlwifi: fix error codes in rtl_debugfs_set_write_h2c()
Browse files Browse the repository at this point in the history
[ Upstream commit b88d281 ]

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: 610247f ("rtlwifi: Improve debugging by using debugfs")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/YoOLnDkHgVltyXK7@kili
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Dan Carpenter authored and gregkh committed Aug 17, 2022
1 parent 438ac9f commit 90b4ec8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/net/wireless/realtek/rtlwifi/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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];
Expand Down

0 comments on commit 90b4ec8

Please sign in to comment.