Re: [PATCH] drm/amdkfd: Replace kmalloc + copy_from_user with memdup_user
From: Alex Deucher
Date: Tue Sep 09 2025 - 11:39:04 EST
Applied. Thanks!
Alex
On Tue, Sep 9, 2025 at 11:29 AM Thorsten Blum <thorsten.blum@xxxxxxxxx> wrote:
>
> Replace kmalloc() followed by copy_from_user() with memdup_user() to
> improve and simplify kfd_criu_restore_queue().
>
> No functional changes intended.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@xxxxxxxxx>
> ---
> .../amd/amdkfd/kfd_process_queue_manager.c | 22 +++++--------------
> 1 file changed, 6 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> index 7fbb5c274ccc..70c17a12cadf 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> @@ -1004,13 +1004,9 @@ int kfd_criu_restore_queue(struct kfd_process *p,
> if (*priv_data_offset + sizeof(*q_data) > max_priv_data_size)
> return -EINVAL;
>
> - q_data = kmalloc(sizeof(*q_data), GFP_KERNEL);
> - if (!q_data)
> - return -ENOMEM;
> -
> - ret = copy_from_user(q_data, user_priv_ptr + *priv_data_offset, sizeof(*q_data));
> - if (ret) {
> - ret = -EFAULT;
> + q_data = memdup_user(user_priv_ptr + *priv_data_offset, sizeof(*q_data));
> + if (IS_ERR(q_data)) {
> + ret = PTR_ERR(q_data);
> goto exit;
> }
>
> @@ -1022,15 +1018,9 @@ int kfd_criu_restore_queue(struct kfd_process *p,
> goto exit;
> }
>
> - q_extra_data = kmalloc(q_extra_data_size, GFP_KERNEL);
> - if (!q_extra_data) {
> - ret = -ENOMEM;
> - goto exit;
> - }
> -
> - ret = copy_from_user(q_extra_data, user_priv_ptr + *priv_data_offset, q_extra_data_size);
> - if (ret) {
> - ret = -EFAULT;
> + q_extra_data = memdup_user(user_priv_ptr + *priv_data_offset, q_extra_data_size);
> + if (IS_ERR(q_extra_data)) {
> + ret = PTR_ERR(q_extra_data);
> goto exit;
> }
>
> --
> 2.51.0
>