drm/imagination: Use memdup_user() helper
authorJinjie Ruan <ruanjinjie@huawei.com>
Mon, 2 Sep 2024 02:33:00 +0000 (10:33 +0800)
committerMatt Coster <matt.coster@imgtec.com>
Mon, 2 Sep 2024 08:55:00 +0000 (09:55 +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>
Suggested-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Frank Binns <frank.binns@imgtec.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240902023300.1214753-1-ruanjinjie@huawei.com
Signed-off-by: Matt Coster <matt.coster@imgtec.com>
drivers/gpu/drm/imagination/pvr_context.c

index eded5e955cc0ac17881b88c1867b909bd62d4613..98327f9bbd9c2d6263137b8c1f9c8ef837d6aa9b 100644 (file)
@@ -69,24 +69,12 @@ 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;
-
-       kfree(stream);
-
-       return 0;
 
-err_free:
        kfree(stream);
 
        return err;