From: Thorsten Blum <thorsten.blum@linux.dev>
To: "Felix Kuehling" <Felix.Kuehling@amd.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] drm/amdkfd: Replace kmalloc + copy_from_user with memdup_user
Date: Tue, 9 Sep 2025 17:11:46 +0200 [thread overview]
Message-ID: <20250909151146.760450-2-thorsten.blum@linux.dev> (raw)
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@linux.dev>
---
.../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
next reply other threads:[~2025-09-09 15:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 15:11 Thorsten Blum [this message]
2025-09-09 15:35 ` Alex Deucher
2025-09-12 12:48 ` Thorsten Blum
2025-09-12 13:06 ` Alex Deucher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250909151146.760450-2-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=Felix.Kuehling@amd.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®