* [PATCH -next] staging: greybus: camera: Switch to memdup_user_nul()
@ 2021-03-31 9:52 Yang Yingliang
2021-03-31 10:24 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: Yang Yingliang @ 2021-03-31 9:52 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>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH -next] staging: greybus: camera: Switch to memdup_user_nul()
2021-03-31 9:52 [PATCH -next] staging: greybus: camera: Switch to memdup_user_nul() Yang Yingliang
@ 2021-03-31 10:24 ` Dan Carpenter
2021-04-01 2:41 ` Yang Yingliang
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2021-03-31 10:24 UTC (permalink / raw)
To: Yang Yingliang; +Cc: linux-kernel, linux-staging, johan, elder, gregkh
On Wed, Mar 31, 2021 at 05:52:01PM +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>
> ---
> 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;
return PTR_ERR(kbuf);
>
> - if (copy_from_user(kbuf, buf, len)) {
> - ret = -EFAULT;
> - goto done;
> - }
> -
> - kbuf[len] = '\0';
>
^^^^^^^^
Please delete this blank line so there aren't two blank lines in a row.
> ret = op->execute(gcam, kbuf, len);
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH -next] staging: greybus: camera: Switch to memdup_user_nul()
2021-03-31 10:24 ` Dan Carpenter
@ 2021-04-01 2:41 ` Yang Yingliang
0 siblings, 0 replies; 3+ messages in thread
From: Yang Yingliang @ 2021-04-01 2:41 UTC (permalink / raw)
To: Dan Carpenter; +Cc: linux-kernel, linux-staging, johan, elder, gregkh
Hi,
On 2021/3/31 18:24, Dan Carpenter wrote:
> On Wed, Mar 31, 2021 at 05:52:01PM +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>
>> ---
>> 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;
> return PTR_ERR(kbuf);
>
>>
>> - if (copy_from_user(kbuf, buf, len)) {
>> - ret = -EFAULT;
>> - goto done;
>> - }
>> -
>> - kbuf[len] = '\0';
>>
> ^^^^^^^^
> Please delete this blank line so there aren't two blank lines in a row.
I will change it and send a v2.
Thanks,
Yang
>
>> ret = op->execute(gcam, kbuf, len);
> regards,
> dan carpenter
>
> .
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-04-01 2:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-31 9:52 [PATCH -next] staging: greybus: camera: Switch to memdup_user_nul() Yang Yingliang
2021-03-31 10:24 ` Dan Carpenter
2021-04-01 2:41 ` Yang Yingliang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).