diff mbox series

[-next] drm/imagination: Use memdup_user() helper to simplify code

Message ID 20240831102930.97502-1-ruanjinjie@huawei.com (mailing list archive)
State New, archived
Headers show
Series [-next] drm/imagination: Use memdup_user() helper to simplify code | expand

Commit Message

Jinjie Ruan Aug. 31, 2024, 10:29 a.m. UTC
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_job.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

Comments

Frank Binns Sept. 2, 2024, 7:59 a.m. UTC | #1
On Sat, 2024-08-31 at 18:29 +0800, Jinjie Ruan wrote:
> Switching to memdup_user(), which combines kmalloc() and copy_from_user(),
> and it can simplfy code.
> 

Reviewed-by: Frank Binns <frank.binns@imgtec.com>

> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
>  drivers/gpu/drm/imagination/pvr_job.c | 13 +++----------
>  1 file changed, 3 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/imagination/pvr_job.c b/drivers/gpu/drm/imagination/pvr_job.c
> index 78c2f3c6dce0..618503a212a7 100644
> --- a/drivers/gpu/drm/imagination/pvr_job.c
> +++ b/drivers/gpu/drm/imagination/pvr_job.c
> @@ -90,20 +90,13 @@ static int pvr_fw_cmd_init(struct pvr_device *pvr_dev, struct pvr_job *job,
>  	void *stream;
>  	int err;
>  
> -	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;
> -	}
> +	stream = memdup_user(u64_to_user_ptr(stream_userptr), stream_len);
> +	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;
>  }
>
Matt Coster Sept. 2, 2024, 9:20 a.m. UTC | #2
On 31/08/2024 11:29, Jinjie Ruan wrote:
> Switching to memdup_user(), which combines kmalloc() and copy_from_user(),
> and it can simplfy code.

Applied, thanks!

[1/1] drm/imagination: Use memdup_user() helper to simplify code
      commit: 3742c20958a5b02ecba08d71036bae3e7b9d21b3

Cheers,
Matt
diff mbox series

Patch

diff --git a/drivers/gpu/drm/imagination/pvr_job.c b/drivers/gpu/drm/imagination/pvr_job.c
index 78c2f3c6dce0..618503a212a7 100644
--- a/drivers/gpu/drm/imagination/pvr_job.c
+++ b/drivers/gpu/drm/imagination/pvr_job.c
@@ -90,20 +90,13 @@  static int pvr_fw_cmd_init(struct pvr_device *pvr_dev, struct pvr_job *job,
 	void *stream;
 	int err;
 
-	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;
-	}
+	stream = memdup_user(u64_to_user_ptr(stream_userptr), stream_len);
+	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;
 }