summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorYang Yingliang <yangyingliang@huawei.com>2021-04-01 18:36:45 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-04-02 14:56:38 +0200
commitf032e2cdf9003ed076c8866a2e7f5003eeabcff8 (patch)
treecf74a9bea7ecbeede3ca7e1bd7d499a634dab9cb /drivers
parent0778f04b0b36dcd51c1dfcaf77a326eacff73329 (diff)
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/greybus/camera.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/drivers/staging/greybus/camera.c b/drivers/staging/greybus/camera.c
index b570e13394ac..cdbb42cd413b 100644
--- a/drivers/staging/greybus/camera.c
+++ b/drivers/staging/greybus/camera.c
@@ -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);