staging: greybus: camera: 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>
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20210401103645.1558813-1-yangyingliang@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Yang Yingliang 2021-04-01 18:36:45 +08:00 committed by Greg Kroah-Hartman
parent 0778f04b0b
commit f032e2cdf9

View file

@ -1120,16 +1120,9 @@ static ssize_t gb_camera_debugfs_write(struct file *file,
if (len > 1024)
return -EINVAL;
kbuf = kmalloc(len + 1, GFP_KERNEL);
if (!kbuf)
return -ENOMEM;
if (copy_from_user(kbuf, buf, len)) {
ret = -EFAULT;
goto done;
}
kbuf[len] = '\0';
kbuf = memdup_user_nul(buf, len);
if (IS_ERR(kbuf))
return PTR_ERR(kbuf);
ret = op->execute(gcam, kbuf, len);