Using a helper shrinks the code and separating the user and kernel slabs
is more secure.

Signed-off-by: Tvrtko Ursulin <[email protected]>
---
 drivers/gpu/drm/drm_syncobj.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index e1b0fa4000cd..1333ef0ea03b 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -1294,15 +1294,10 @@ static int drm_syncobj_array_find(struct drm_file 
*file_private,
        struct drm_syncobj **syncobjs;
        int ret;
 
-       handles = kmalloc_array(count_handles, sizeof(*handles), GFP_KERNEL);
-       if (handles == NULL)
-               return -ENOMEM;
-
-       if (copy_from_user(handles, user_handles,
-                          sizeof(uint32_t) * count_handles)) {
-               ret = -EFAULT;
-               goto err_free_handles;
-       }
+       handles = memdup_array_user(user_handles, count_handles,
+                                   sizeof(*handles));
+       if (IS_ERR(handles))
+               return PTR_ERR(handles);
 
        syncobjs = kmalloc_array(count_handles, sizeof(*syncobjs), GFP_KERNEL);
        if (syncobjs == NULL) {
-- 
2.48.0

Reply via email to