drm/imagination: Use memdup_user() rather than duplicating its implementation
Subsystems (4)
PATCH 1/1 drm/imagination: Use memdup_user() rather than duplicating its implementation
From: Markus Elfring <[email protected]>
Date: Sun, 28 Jan 2024 20:50:36 +0100
* Reuse existing functionality from memdup_user() instead of keeping duplicate source code.
Generated by: scripts/coccinelle/api/memdup_user.cocci
* Delete labels and statements which became unnecessary with this refactoring.
Signed-off-by Markus Elfring <[email protected]>
--- drivers/gpu/drm/imagination/pvr_context.c | 21 +++------------------ drivers/gpu/drm/imagination/pvr_job.c | 15 +++------------ 2 files changed, 6 insertions(+), 30 deletions(-)
drivers/gpu/drm/imagination/pvr_context.c +3 -18
@@ -66,29 +66,14 @@ static int process_static_context_state(struct pvr_device *pvr_dev, const struct pvr_stream_cmd_defs *cmd_defs, u64 stream_user_ptr, u32 stream_size, void *dest) { - void *stream; int err; +void *stream =memdup_user (u64_to_user_ptr (stream_user_ptr), stream_size); - 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; - } +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; -kfree (stream); - -return 0 ; - -err_free: -kfree (stream); -return err; }
drivers/gpu/drm/imagination/pvr_job.c +3 -12
@@ -87,23 +87,14 @@ static int pvr_fw_cmd_init(struct pvr_device *pvr_dev, struct pvr_job *job,const struct pvr_stream_cmd_defs *stream_def, u64 stream_userptr, u32 stream_len) { - void *stream; int err; +void *stream =memdup_user (u64_to_user_ptr (stream_userptr), stream_len); - stream =kzalloc (stream_len,GFP_KERNEL ); -if (!stream) -return -ENOMEM ; - -if (copy_from_user (stream,u64_to_user_ptr (stream_userptr), stream_len)) { - err = -EFAULT ; - goto err_free_stream; - } +if (IS_ERR (stream)) +return PTR_ERR (stream); err =pvr_job_process_stream (pvr_dev, stream_def, stream, stream_len, job); - -err_free_stream:kfree (stream); -return err; }
--
2.43.0