mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tursulin@ursulin.net>
To: "Thorsten Blum" <thorsten.blum@linux.dev>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Nitin Gote" <nitin.r.gote@intel.com>,
	"Mikołaj Wasiak" <mikolaj.wasiak@intel.com>,
	"Krzysztof Niemiec" <krzysztof.niemiec@intel.com>,
	"Andi Shyti" <andi.shyti@linux.intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>,
	intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/i915: Replace kmalloc() + copy_from_user() with memdup_user()
Date: Tue, 2 Sep 2025 09:58:42 +0100	[thread overview]
Message-ID: <5f6c7541-93ca-4b67-b4e4-33ff60e99c7d@ursulin.net> (raw)
In-Reply-To: <20250902081046.35463-2-thorsten.blum@linux.dev>


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


  reply	other threads:[~2025-09-02  8:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02  8:10 Thorsten Blum
2025-09-02  8:58 ` Tvrtko Ursulin [this message]
2025-09-02 16:02 ` Andi Shyti

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=5f6c7541-93ca-4b67-b4e4-33ff60e99c7d@ursulin.net \
    --to=tursulin@ursulin.net \
    --cc=airlied@gmail.com \
    --cc=andi.shyti@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@intel.com \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=krzysztof.niemiec@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikolaj.wasiak@intel.com \
    --cc=nitin.r.gote@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=simona@ffwll.ch \
    --cc=thorsten.blum@linux.dev \
    /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®