Replace kzalloc() + copy_from_user() with memdup_user().

This shrinks the source code and improves separation between the kernel
and userspace slabs.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursu...@igalia.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
index 38face981c3e..e0a604b6c633 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
@@ -141,7 +141,7 @@ static const struct file_operations ta_invoke_debugfs_fops 
= {
  *    - TA ID (4bytes)
  */
 
-static ssize_t ta_if_load_debugfs_write(struct file *fp, const char *buf, 
size_t len, loff_t *off)
+static ssize_t ta_if_load_debugfs_write(struct file *fp, const char __user 
*buf, size_t len, loff_t *off)
 {
        uint32_t ta_type    = 0;
        uint32_t ta_bin_len = 0;
@@ -171,13 +171,9 @@ static ssize_t ta_if_load_debugfs_write(struct file *fp, 
const char *buf, size_t
 
        copy_pos += sizeof(uint32_t);
 
-       ta_bin = kzalloc(ta_bin_len, GFP_KERNEL);
-       if (!ta_bin)
-               return -ENOMEM;
-       if (copy_from_user((void *)ta_bin, &buf[copy_pos], ta_bin_len)) {
-               ret = -EFAULT;
-               goto err_free_bin;
-       }
+       ta_bin = memdup_user(&buf[copy_pos], ta_bin_len);
+       if (IS_ERR(ta_bin))
+               return PTR_ERR(ta_bin);
 
        /* Set TA context and functions */
        set_ta_context_funcs(psp, ta_type, &context);
@@ -231,7 +227,7 @@ static ssize_t ta_if_load_debugfs_write(struct file *fp, 
const char *buf, size_t
                goto err_free_ta_shared_buf;
        }
 
-       if (copy_to_user((char *)buf, (void *)&context->session_id, 
sizeof(uint32_t)))
+       if (copy_to_user((char __user *)buf, (void *)&context->session_id, 
sizeof(uint32_t)))
                ret = -EFAULT;
 
 err_free_ta_shared_buf:
-- 
2.48.0

Reply via email to