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>
This commit is contained in:
Wei Yongjun 2021-03-24 14:42:20 +00:00 committed by David S. Miller
parent c3dde0ee71
commit 20fd4f421c

View file

@ -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';