Use memdup_user_nul() helper instead of open-coding to simplify the code. Reported-by: Hulk Robot <hul...@huawei.com> Signed-off-by: Yang Yingliang <yangyingli...@huawei.com> --- drivers/staging/greybus/camera.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/greybus/camera.c b/drivers/staging/greybus/camera.c index b570e13394ac..0f005facffbc 100644 --- a/drivers/staging/greybus/camera.c +++ b/drivers/staging/greybus/camera.c @@ -1120,16 +1120,10 @@ static ssize_t gb_camera_debugfs_write(struct file *file, if (len > 1024) return -EINVAL; - kbuf = kmalloc(len + 1, GFP_KERNEL); - if (!kbuf) + kbuf = memdup_user_nul(buf, len); + if (IS_ERR(kbuf)) return -ENOMEM; - if (copy_from_user(kbuf, buf, len)) { - ret = -EFAULT; - goto done; - } - - kbuf[len] = '\0'; ret = op->execute(gcam, kbuf, len); -- 2.25.1