drm/amdgpu: Replace kzalloc + copy_from_user with memdup_user
Subsystems (2)
PATCH 1/1 drm/amdgpu: Replace kzalloc + copy_from_user with memdup_user
Replace kzalloc() followed by copy_from_user() with memdup_user() to improve and simplify ta_if_load_debugfs_write() and ta_if_invoke_debugfs_write().
No functional changes intended.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c +6 -14
@@ -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);
@@ -327,13 +323,9 @@ static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf, sizereturn -EFAULT ; copy_pos +=sizeof (uint32_t ); - shared_buf =kzalloc (shared_buf_len,GFP_KERNEL ); -if (!shared_buf) -return -ENOMEM ; -if (copy_from_user ((void *)shared_buf, &buf[copy_pos], shared_buf_len)) { - ret = -EFAULT ; - goto err_free_shared_buf; - } + shared_buf =memdup_user (&buf[copy_pos], shared_buf_len); +if (IS_ERR (shared_buf)) +return PTR_ERR (shared_buf);set_ta_context_funcs (psp, ta_type, &context);
Signature · 1 line
2.51.0
Quoted 39 lines · Thorsten Blum
Replace
kzalloc()followed bycopy_from_user()withmemdup_user()to improve and simplifyta_if_load_debugfs_write()andta_if_invoke_debugfs_write().No functional changes intended.
Signed-off-by Thorsten Blum <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c +3
-10@@ -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);@@ -327,13 +323,9 @@ static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf, sizereturn -EFAULT ; copy_pos +=sizeof (uint32_t ); - shared_buf =kzalloc (shared_buf_len,GFP_KERNEL ); -if (!shared_buf) -return -ENOMEM ;
drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf, size · line 331
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c +3
-4-if (copy_from_user ((void *)shared_buf, &buf[copy_pos], shared_buf_len)) { - ret = -EFAULT ; - goto err_free_shared_buf; - } + shared_buf =memdup_user (&buf[copy_pos], shared_buf_len); +if (IS_ERR (shared_buf)) +return PTR_ERR (shared_buf);set_ta_context_funcs (psp, ta_type, &context);
More complete than the one I sent in June^1.
I had some other in that series, not sure if you caught those.
Regards,
Tvrtko
Alex Deucher
AppliedQuoted 50 lines · Tvrtko Ursulin
Quoted 47 lines · Thorsten Blum
Replace
kzalloc()followed bycopy_from_user()withmemdup_user()to improve and simplifyta_if_load_debugfs_write()andta_if_invoke_debugfs_write().No functional changes intended.
Signed-off-by Thorsten Blum <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c +6
-14@@ -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);@@ -327,13 +323,9 @@ static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf, sizereturn -EFAULT ; copy_pos +=sizeof (uint32_t ); - shared_buf =kzalloc (shared_buf_len,GFP_KERNEL ); -if (!shared_buf) -return -ENOMEM ; -if (copy_from_user ((void *)shared_buf, &buf[copy_pos], shared_buf_len)) { - ret = -EFAULT ; - goto err_free_shared_buf; - } + shared_buf =memdup_user (&buf[copy_pos], shared_buf_len); +if (IS_ERR (shared_buf)) +return PTR_ERR (shared_buf);
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf, size · line 331
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c +0
-0set_ta_context_funcs (psp, ta_type, &context);More complete than the one I sent in June^1.
I never received this series. I didn't see it in patchwork either. Seems it never made it to amd-gfx. Sorry I missed it. I've applied the applicable patches now.
Quoted 2 lines
Reviewed-by Tvrtko Ursulin <[email protected]>
Applied. Thanks!
Alex
Quoted 10 lines
I had some other in that series, not sure if you caught those.
Regards,
Tvrtko
Quoted 51 lines · Alex Deucher
Quoted 50 lines · Tvrtko Ursulin
Quoted 47 lines · Thorsten Blum
Replace
kzalloc()followed bycopy_from_user()withmemdup_user()to improve and simplifyta_if_load_debugfs_write()andta_if_invoke_debugfs_write().No functional changes intended.
Signed-off-by Thorsten Blum <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c +6
-14@@ -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);@@ -327,13 +323,9 @@ static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf, sizereturn -EFAULT ; copy_pos +=sizeof (uint32_t ); - shared_buf =kzalloc (shared_buf_len,GFP_KERNEL ); -if (!shared_buf) -return -ENOMEM ; -if (copy_from_user ((void *)shared_buf, &buf[copy_pos], shared_buf_len)) { - ret = -EFAULT ; - goto err_free_shared_buf; - } + shared_buf =memdup_user (&buf[copy_pos], shared_buf_len); +if (IS_ERR (shared_buf)) +return PTR_ERR (shared_buf);
Quoted 8 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf, size · line 331
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c +0
-0set_ta_context_funcs (psp, ta_type, &context);More complete than the one I sent in June^1.
I never received this series. I didn't see it in patchwork either. Seems it never made it to amd-gfx. Sorry I missed it. I've applied the applicable patches now.
Thank you and no worries, it wasn't anything urgent.
Regards,
Tvrtko