Skip to content

Commit

Permalink
netdevsim: switch to memdup_user_nul()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Wei Yongjun authored and David S. Miller committed Mar 24, 2021
1 parent c3dde0e commit 20fd4f4
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions drivers/net/netdevsim/health.c
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down

0 comments on commit 20fd4f4

Please sign in to comment.