]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/imagination: Use memdup_user() helper to simplify code
authorJinjie Ruan <ruanjinjie@huawei.com>
Sat, 31 Aug 2024 10:29:30 +0000 (18:29 +0800)
committerMatt Coster <matt.coster@imgtec.com>
Mon, 2 Sep 2024 08:54:13 +0000 (09:54 +0100)
Switching to memdup_user(), which combines kmalloc() and copy_from_user(),
and it can simplfy code.

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Reviewed-by: Frank Binns <frank.binns@imgtec.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240831102930.97502-1-ruanjinjie@huawei.com
Signed-off-by: Matt Coster <matt.coster@imgtec.com>
drivers/gpu/drm/imagination/pvr_job.c

index 78c2f3c6dce019c6ede3342a0e30783ffd0aa959..618503a212a7d34a17a2cb241231e38f83eb9cff 100644 (file)
@@ -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;
 }