staging: greybus: camera: Switch to memdup_user_nul()
PATCH v2 1/1 staging: greybus: camera: Switch to memdup_user_nul()
Use memdup_user_nul() helper instead of open-coding to simplify the code.
--- drivers/staging/greybus/camera.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/staging/greybus/camera.c +3 -10
@@ -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);
Signature · 1 line
2.25.1
Greg KH
maintainerQuoted 8 lines · Yang Yingliang
Use
memdup_user_nul()helper instead of open-coding to simplify the code.Reported-by Hulk Robot <[email protected]>Signed-off-by Yang Yingliang <[email protected]>--- drivers/staging/greybus/camera.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
What changed from v1?
Always put that below the --- line like the documentation asks you to. Please fix up and send a v3.
thanks,
greg k-h
Quoted 9 lines · Greg KH
Quoted 8 lines · Yang Yingliang
Use
memdup_user_nul()helper instead of open-coding to simplify the code.Reported-by Hulk Robot <[email protected]>Signed-off-by Yang Yingliang <[email protected]>--- drivers/staging/greybus/camera.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
Quoted 4 lines
What changed from v1?
Always put that below the --- line like the documentation asks you to. Please fix up and send a v3.
OK, I will add the changelog and send a v3 later
Thanks,
Yang
Quoted 5 lines
thanks,
greg k-h
.
Quoted 20 lines · Yang Yingliang
Use
memdup_user_nul()helper instead of open-coding to simplify the code.Reported-by Hulk Robot <[email protected]>Signed-off-by Yang Yingliang <[email protected]>--- drivers/staging/greybus/camera.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)drivers/staging/greybus/camera.c +0
-3@@ -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 ;
drivers/staging/greybus/camera.c static ssize_t gb_camera_debugfs_write(struct file *file, · line 1125
Quoted 10 lines
drivers/staging/greybus/camera.c +3
-7- -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);;
^^
There is an extra semi-colon here. Checkpatch actually catches this sort of typo.
regards,
dan carpenter
Quoted 32 lines · Dan Carpenter
Quoted 20 lines · Yang Yingliang
Use
memdup_user_nul()helper instead of open-coding to simplify the code.Reported-by Hulk Robot <[email protected]>Signed-off-by Yang Yingliang <[email protected]>--- drivers/staging/greybus/camera.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)drivers/staging/greybus/camera.c +0
-3@@ -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 ;drivers/staging/greybus/camera.c static ssize_t gb_camera_debugfs_write(struct file *file, · line 1125
Quoted 10 lines
drivers/staging/greybus/camera.c +3
-7- -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);;^^
Quoted 2 lines
There is an extra semi-colon here. Checkpatch actually catches this sort of typo.
So when someone makes a typo like this, my response is:
1) Let's add this to checkpatch (turns out it was already done)
2) Let's grep the kernel and fix the other instances. The command would be something like: git grep ';;$' | grep '\.c:'
regards,
dan carpenter
Quoted 35 lines · Dan Carpenter
Quoted 32 lines · Dan Carpenter
Quoted 20 lines · Yang Yingliang
Use
memdup_user_nul()helper instead of open-coding to simplify the code.Reported-by Hulk Robot <[email protected]>Signed-off-by Yang Yingliang <[email protected]>--- drivers/staging/greybus/camera.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)drivers/staging/greybus/camera.c +0
-3@@ -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 ;drivers/staging/greybus/camera.c static ssize_t gb_camera_debugfs_write(struct file *file, · line 1125
Quoted 10 lines
drivers/staging/greybus/camera.c +3
-7- -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);;^^Quoted 2 lines
There is an extra semi-colon here. Checkpatch actually catches this sort of typo.
Quoted 5 lines
So when someone makes a typo like this, my response is:
1) Let's add this to checkpatch (turns out it was already done)
2) Let's grep the kernel and fix the other instances. The command would be something like: git grep ';;$' | grep '\.c:'
I search it in kernel and find some other instances like this, I can send some patches to fix these.
Thanks,
Yang
Quoted 5 lines
regards,
dan carpenter.
Quoted 32 lines · Dan Carpenter
Quoted 20 lines · Yang Yingliang
Use
memdup_user_nul()helper instead of open-coding to simplify the code.Reported-by Hulk Robot <[email protected]>Signed-off-by Yang Yingliang <[email protected]>--- drivers/staging/greybus/camera.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)drivers/staging/greybus/camera.c +0
-3@@ -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 ;drivers/staging/greybus/camera.c static ssize_t gb_camera_debugfs_write(struct file *file, · line 1125
Quoted 10 lines
drivers/staging/greybus/camera.c +3
-7- -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);;^^
Quoted 2 lines
There is an extra semi-colon here. Checkpatch actually catches this sort of typo.
I will remove it, and send a v3 later.
Thanks,
Yang
Quoted 5 lines
regards,
dan carpenter.