mirror of
https://github.com/torvalds/linux.git
synced 2026-06-03 12:03:54 +02:00
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:
parent
c3dde0ee71
commit
20fd4f421c
|
|
@ -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';
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user