* [PATCH] drm/i915: Replace kmalloc() + copy_from_user() with memdup_user()
@ 2025-09-02 8:10 Thorsten Blum
2025-09-02 8:58 ` Tvrtko Ursulin
2025-09-02 16:02 ` Andi Shyti
0 siblings, 2 replies; 3+ messages in thread
From: Thorsten Blum @ 2025-09-02 8:10 UTC (permalink / raw)
To: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Nitin Gote, Mikołaj Wasiak,
Krzysztof Niemiec, Andi Shyti
Cc: Thorsten Blum, Jani Nikula, intel-gfx, dri-devel, linux-kernel
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>
---
Resending this (with updated patch subject and description) because the
CI logs [1] from my first submission [2] about a year ago are no longer
available.
[1] https://patchwork.freedesktop.org/series/139319/
[2] https://lore.kernel.org/lkml/20240925141750.51198-1-thorsten.blum@linux.dev/
---
drivers/gpu/drm/i915/gem/i915_gem_context.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
index 15835952352e..ed6599694835 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
@@ -2158,18 +2158,12 @@ static int set_context_image(struct i915_gem_context *ctx,
goto out_ce;
}
- state = kmalloc(ce->engine->context_size, GFP_KERNEL);
- if (!state) {
- ret = -ENOMEM;
+ state = memdup_user(u64_to_user_ptr(user.image), ce->engine->context_size);
+ if (IS_ERR(state)) {
+ ret = PTR_ERR(state);
goto out_ce;
}
- if (copy_from_user(state, u64_to_user_ptr(user.image),
- ce->engine->context_size)) {
- ret = -EFAULT;
- goto out_state;
- }
-
shmem_state = shmem_create_from_data(ce->engine->name,
state, ce->engine->context_size);
if (IS_ERR(shmem_state)) {
--
2.51.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/i915: Replace kmalloc() + copy_from_user() with memdup_user()
2025-09-02 8:10 [PATCH] drm/i915: Replace kmalloc() + copy_from_user() with memdup_user() Thorsten Blum
@ 2025-09-02 8:58 ` Tvrtko Ursulin
2025-09-02 16:02 ` Andi Shyti
1 sibling, 0 replies; 3+ messages in thread
From: Tvrtko Ursulin @ 2025-09-02 8:58 UTC (permalink / raw)
To: Thorsten Blum, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
David Airlie, Simona Vetter, Nitin Gote, Mikołaj Wasiak,
Krzysztof Niemiec, Andi Shyti
Cc: Jani Nikula, intel-gfx, dri-devel, linux-kernel
On 02/09/2025 09:10, Thorsten Blum wrote:
> 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>
> ---
> Resending this (with updated patch subject and description) because the
> CI logs [1] from my first submission [2] about a year ago are no longer
> available.
>
> [1] https://patchwork.freedesktop.org/series/139319/
> [2] https://lore.kernel.org/lkml/20240925141750.51198-1-thorsten.blum@linux.dev/
> ---
> drivers/gpu/drm/i915/gem/i915_gem_context.c | 12 +++---------
> 1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> index 15835952352e..ed6599694835 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> @@ -2158,18 +2158,12 @@ static int set_context_image(struct i915_gem_context *ctx,
> goto out_ce;
> }
>
> - state = kmalloc(ce->engine->context_size, GFP_KERNEL);
> - if (!state) {
> - ret = -ENOMEM;
> + state = memdup_user(u64_to_user_ptr(user.image), ce->engine->context_size);
> + if (IS_ERR(state)) {
> + ret = PTR_ERR(state);
> goto out_ce;
> }
>
> - if (copy_from_user(state, u64_to_user_ptr(user.image),
> - ce->engine->context_size)) {
> - ret = -EFAULT;
> - goto out_state;
> - }
> -
> shmem_state = shmem_create_from_data(ce->engine->name,
> state, ce->engine->context_size);
> if (IS_ERR(shmem_state)) {
LGTM.
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Note however that CI is not picking up external patches these days, so I
will need to re-send it for you. Once it passes I will merge it but if I
forget feel free to ping.
Regards,
Tvrtko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/i915: Replace kmalloc() + copy_from_user() with memdup_user()
2025-09-02 8:10 [PATCH] drm/i915: Replace kmalloc() + copy_from_user() with memdup_user() Thorsten Blum
2025-09-02 8:58 ` Tvrtko Ursulin
@ 2025-09-02 16:02 ` Andi Shyti
1 sibling, 0 replies; 3+ messages in thread
From: Andi Shyti @ 2025-09-02 16:02 UTC (permalink / raw)
To: Thorsten Blum
Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Nitin Gote, Mikołaj Wasiak,
Krzysztof Niemiec, Andi Shyti, Jani Nikula, intel-gfx, dri-devel,
linux-kernel
Hi Thorsten,
On Tue, Sep 02, 2025 at 10:10:42AM +0200, Thorsten Blum wrote:
> 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: Andi Shyti <andi.shyti@linux.intel.com>
Thanks,
Andi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-02 16:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-02 8:10 [PATCH] drm/i915: Replace kmalloc() + copy_from_user() with memdup_user() Thorsten Blum
2025-09-02 8:58 ` Tvrtko Ursulin
2025-09-02 16:02 ` Andi Shyti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).