aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/netdevsim
diff options
context:
space:
mode:
authorWei Yongjun <weiyongjun1@huawei.com>2021-03-24 14:42:20 +0000
committerDavid S. Miller <davem@davemloft.net>2021-03-24 16:26:58 -0700
commit20fd4f421cf4c21ab37a8bf31db50c69f1b49355 (patch)
tree2a962f1200f5d0bc2838137e9c82bc6f91eee6a2 /drivers/net/netdevsim
parentnet: decnet: Fixed multiple Coding Style issues (diff)
downloadlinux-dev-20fd4f421cf4c21ab37a8bf31db50c69f1b49355.tar.xz
linux-dev-20fd4f421cf4c21ab37a8bf31db50c69f1b49355.zip
netdevsim: switch to memdup_user_nul()
Use memdup_user_nul() helper instead of open-coding to simplify the code. Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/netdevsim')
-rw-r--r--drivers/net/netdevsim/health.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/drivers/net/netdevsim/health.c b/drivers/net/netdevsim/health.c
index 21e2974660e7..04aebdf85747 100644
--- a/drivers/net/netdevsim/health.c
+++ b/drivers/net/netdevsim/health.c
@@ -235,15 +235,10 @@ static ssize_t nsim_dev_health_break_write(struct file *file,
char *break_msg;
int err;
- break_msg = kmalloc(count + 1, GFP_KERNEL);
- if (!break_msg)
- return -ENOMEM;
+ break_msg = memdup_user_nul(data, count);
+ if (IS_ERR(break_msg))
+ return PTR_ERR(break_msg);
- if (copy_from_user(break_msg, data, count)) {
- err = -EFAULT;
- goto out;
- }
- break_msg[count] = '\0';
if (break_msg[count - 1] == '\n')
break_msg[count - 1] = '\0';