From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C94E1CA0FFE for ; Tue, 2 Sep 2025 08:19:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3C5CE10E5D6; Tue, 2 Sep 2025 08:19:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="lpSpWKkO"; dkim-atps=neutral X-Greylist: delayed 369 seconds by postgrey-1.36 at gabe; Tue, 02 Sep 2025 08:19:32 UTC Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) by gabe.freedesktop.org (Postfix) with ESMTPS id 957CF10E5D7 for ; Tue, 2 Sep 2025 08:19:32 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1756800800; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=29lL7/RHKWS3+5nqR/m2P+13Padj37R/bQqCAmj2wno=; b=lpSpWKkOVo6I3i2IWYM4ucRCzxS+xMDCyEX5rpF0h/xecKuBGPx12EVLeSu2CvgGa+LKlt sr7PRhEPDcA+4QKrb/zBqpE2HvYJwAmzDh1iTmGr42/7GIu0yyuvHaSvMYRgl42ctfXjnl mrK0dVzEeJdcC6zf6j4y9M1aCdp2tnY= From: Thorsten Blum To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Nitin Gote , =?UTF-8?q?Miko=C5=82aj=20Wasiak?= , Krzysztof Niemiec , Andi Shyti Cc: Thorsten Blum , Jani Nikula , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/i915: Replace kmalloc() + copy_from_user() with memdup_user() Date: Tue, 2 Sep 2025 10:10:42 +0200 Message-ID: <20250902081046.35463-2-thorsten.blum@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 --- 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