* [PATCH -next] drm/imagination: Use memdup_user() helper
@ 2024-08-31 10:30 Jinjie Ruan
2024-08-31 10:48 ` Christophe JAILLET
0 siblings, 1 reply; 3+ messages in thread
From: Jinjie Ruan @ 2024-08-31 10:30 UTC (permalink / raw)
To: frank.binns, matt.coster, maarten.lankhorst, mripard,
tzimmermann, airlied, daniel, dri-devel, linux-kernel
Cc: ruanjinjie
Switching to memdup_user(), which combines kmalloc() and copy_from_user(),
and it can simplfy code.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/gpu/drm/imagination/pvr_context.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)
diff --git a/drivers/gpu/drm/imagination/pvr_context.c b/drivers/gpu/drm/imagination/pvr_context.c
index eded5e955cc0..e75fd50a4d9f 100644
--- a/drivers/gpu/drm/imagination/pvr_context.c
+++ b/drivers/gpu/drm/imagination/pvr_context.c
@@ -69,27 +69,19 @@ process_static_context_state(struct pvr_device *pvr_dev, const struct pvr_stream
void *stream;
int err;
- stream = kzalloc(stream_size, GFP_KERNEL);
- if (!stream)
- return -ENOMEM;
-
- if (copy_from_user(stream, u64_to_user_ptr(stream_user_ptr), stream_size)) {
- err = -EFAULT;
- goto err_free;
- }
+ stream = memdup_user(u64_to_user_ptr(stream_user_ptr), stream_size);
+ if (IS_ERR(stream))
+ return PTR_ERR(stream);
err = pvr_stream_process(pvr_dev, cmd_defs, stream, stream_size, dest);
- if (err)
- goto err_free;
+ if (err) {
+ kfree(stream);
+ return err;
+ }
kfree(stream);
return 0;
-
-err_free:
- kfree(stream);
-
- return err;
}
static int init_render_fw_objs(struct pvr_context *ctx,
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH -next] drm/imagination: Use memdup_user() helper
2024-08-31 10:30 [PATCH -next] drm/imagination: Use memdup_user() helper Jinjie Ruan
@ 2024-08-31 10:48 ` Christophe JAILLET
2024-09-02 2:17 ` Jinjie Ruan
0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2024-08-31 10:48 UTC (permalink / raw)
To: Jinjie Ruan, frank.binns, matt.coster, maarten.lankhorst,
mripard, tzimmermann, airlied, daniel, dri-devel, linux-kernel
Le 31/08/2024 à 12:30, Jinjie Ruan a écrit :
> Switching to memdup_user(), which combines kmalloc() and copy_from_user(),
> and it can simplfy code.
>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
> drivers/gpu/drm/imagination/pvr_context.c | 22 +++++++---------------
> 1 file changed, 7 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/gpu/drm/imagination/pvr_context.c b/drivers/gpu/drm/imagination/pvr_context.c
> index eded5e955cc0..e75fd50a4d9f 100644
> --- a/drivers/gpu/drm/imagination/pvr_context.c
> +++ b/drivers/gpu/drm/imagination/pvr_context.c
> @@ -69,27 +69,19 @@ process_static_context_state(struct pvr_device *pvr_dev, const struct pvr_stream
> void *stream;
> int err;
>
> - stream = kzalloc(stream_size, GFP_KERNEL);
> - if (!stream)
> - return -ENOMEM;
> -
> - if (copy_from_user(stream, u64_to_user_ptr(stream_user_ptr), stream_size)) {
> - err = -EFAULT;
> - goto err_free;
> - }
> + stream = memdup_user(u64_to_user_ptr(stream_user_ptr), stream_size);
> + if (IS_ERR(stream))
> + return PTR_ERR(stream);
>
> err = pvr_stream_process(pvr_dev, cmd_defs, stream, stream_size, dest);
> - if (err)
> - goto err_free;
> + if (err) {
> + kfree(stream);
> + return err;
> + }
>
> kfree(stream);
>
> return 0;
> -
> -err_free:
> - kfree(stream);
> -
> - return err;
> }
It could also be:
err = pvr_stream_process(...);
kfree(stream);
return err;
as you did for drivers/gpu/drm/imagination/pvr_job.c.
CJ
>
> static int init_render_fw_objs(struct pvr_context *ctx,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH -next] drm/imagination: Use memdup_user() helper
2024-08-31 10:48 ` Christophe JAILLET
@ 2024-09-02 2:17 ` Jinjie Ruan
0 siblings, 0 replies; 3+ messages in thread
From: Jinjie Ruan @ 2024-09-02 2:17 UTC (permalink / raw)
To: Christophe JAILLET, frank.binns, matt.coster, maarten.lankhorst,
mripard, tzimmermann, airlied, daniel, dri-devel, linux-kernel
On 2024/8/31 18:48, Christophe JAILLET wrote:
> Le 31/08/2024 à 12:30, Jinjie Ruan a écrit :
>> Switching to memdup_user(), which combines kmalloc() and
>> copy_from_user(),
>> and it can simplfy code.
>>
>> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
>> ---
>> drivers/gpu/drm/imagination/pvr_context.c | 22 +++++++---------------
>> 1 file changed, 7 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/imagination/pvr_context.c
>> b/drivers/gpu/drm/imagination/pvr_context.c
>> index eded5e955cc0..e75fd50a4d9f 100644
>> --- a/drivers/gpu/drm/imagination/pvr_context.c
>> +++ b/drivers/gpu/drm/imagination/pvr_context.c
>> @@ -69,27 +69,19 @@ process_static_context_state(struct pvr_device
>> *pvr_dev, const struct pvr_stream
>> void *stream;
>> int err;
>> - stream = kzalloc(stream_size, GFP_KERNEL);
>> - if (!stream)
>> - return -ENOMEM;
>> -
>> - if (copy_from_user(stream, u64_to_user_ptr(stream_user_ptr),
>> stream_size)) {
>> - err = -EFAULT;
>> - goto err_free;
>> - }
>> + stream = memdup_user(u64_to_user_ptr(stream_user_ptr), stream_size);
>> + if (IS_ERR(stream))
>> + return PTR_ERR(stream);
>> err = pvr_stream_process(pvr_dev, cmd_defs, stream,
>> stream_size, dest);
>> - if (err)
>> - goto err_free;
>> + if (err) {
>> + kfree(stream);
>> + return err;
>> + }
>> kfree(stream);
>> return 0;
>> -
>> -err_free:
>> - kfree(stream);
>> -
>> - return err;
>> }
>
> It could also be:
> err = pvr_stream_process(...);
>
> kfree(stream);
>
> return err;
>
> as you did for drivers/gpu/drm/imagination/pvr_job.c.
You are right! that will be more clean.
>
> CJ
>
>> static int init_render_fw_objs(struct pvr_context *ctx,
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-02 2:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-31 10:30 [PATCH -next] drm/imagination: Use memdup_user() helper Jinjie Ruan
2024-08-31 10:48 ` Christophe JAILLET
2024-09-02 2:17 ` Jinjie Ruan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®