All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next v3] staging: greybus: camera: Switch to memdup_user_nul()
@ 2021-04-01 10:36 Yang Yingliang
  2021-04-01 11:00 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Yingliang @ 2021-04-01 10:36 UTC (permalink / raw)
  To: linux-kernel, linux-staging; +Cc: johan, elder, gregkh

Use memdup_user_nul() helper instead of open-coding to
simplify the code.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
v3:
  remove duplicate ';'
v2:
  delete unnecessary blank line
  use return PTR_ERR(kbuf) instead
---
 drivers/staging/greybus/camera.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/greybus/camera.c b/drivers/staging/greybus/camera.c
index b570e13394ac..2ecdc1bc5092 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);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH -next v3] staging: greybus: camera: Switch to memdup_user_nul()
  2021-04-01 10:36 [PATCH -next v3] staging: greybus: camera: Switch to memdup_user_nul() Yang Yingliang
@ 2021-04-01 11:00 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2021-04-01 11:00 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: linux-kernel, linux-staging, johan, elder, gregkh

On Thu, Apr 01, 2021 at 06:36:45PM +0800, Yang Yingliang wrote:
> Use memdup_user_nul() helper instead of open-coding to
> simplify the code.
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>

Thanks!

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-01 11:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-01 10:36 [PATCH -next v3] staging: greybus: camera: Switch to memdup_user_nul() Yang Yingliang
2021-04-01 11:00 ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.