Skip to content

Commit 82b13dd

Browse files
tobluxtursulin
authored andcommitted
drm/i915: Replace kmalloc() + copy_from_user() with memdup_user()
Replace kmalloc() followed by copy_from_user() with memdup_user() to improve and simplify set_context_image(), and to silence the following Coccinelle/coccicheck warning reported by memdup_user.cocci: WARNING opportunity for memdup_user No functional changes intended. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> Signed-off-by: Tvrtko Ursulin <tursulin@ursulin.net> Link: https://lore.kernel.org/r/20250902081046.35463-2-thorsten.blum@linux.dev
1 parent b7a855f commit 82b13dd

1 file changed

Lines changed: 3 additions & 9 deletions

File tree

drivers/gpu/drm/i915/gem/i915_gem_context.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,18 +2158,12 @@ static int set_context_image(struct i915_gem_context *ctx,
21582158
goto out_ce;
21592159
}
21602160

2161-
state = kmalloc(ce->engine->context_size, GFP_KERNEL);
2162-
if (!state) {
2163-
ret = -ENOMEM;
2161+
state = memdup_user(u64_to_user_ptr(user.image), ce->engine->context_size);
2162+
if (IS_ERR(state)) {
2163+
ret = PTR_ERR(state);
21642164
goto out_ce;
21652165
}
21662166

2167-
if (copy_from_user(state, u64_to_user_ptr(user.image),
2168-
ce->engine->context_size)) {
2169-
ret = -EFAULT;
2170-
goto out_state;
2171-
}
2172-
21732167
shmem_state = shmem_create_from_data(ce->engine->name,
21742168
state, ce->engine->context_size);
21752169
if (IS_ERR(shmem_state)) {

0 commit comments

Comments
 (0)