From nobody Fri Nov 29 02:39:12 2024 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B2791862BB for ; Wed, 25 Sep 2024 14:18:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727273928; cv=none; b=o+S5/9SDLGNOh1Scnz7sXjLPyE1iktUl1z0mT02wfsHIcKNyXfZ1+Hqd1PUOKNcTxal1GojUR2MkUnw23pRg1mureNELZ1aSnomrlGFDIixPvdc4ZXAPW7OoHWYg1UPhIisAms23E/mtljGQVTFsVwGgBQhIs7x4vngf5nLenXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727273928; c=relaxed/simple; bh=ZXsHY/N0ib9u2Hl5cFK5B5Evj32BWfZwfPIFrSdPOWc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=A/piNkJApOa1o/UpERk1PZSB3OJb0Buvk7WDGpB1Z4Ahi6n+vYrb/dHFyadIdFOnCHWRryXZzVh3WSToDbBaxVRHGaq8iyujtPCx9vpJkaiWLXz2zcR5OARdQ5ROEWgr7xoGzPNG4Tk7DKbTz0AnXzEXvUSqiiuk9KCTP8SSPA0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=qGeYFcQg; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="qGeYFcQg" 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=1727273923; 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=j1jLzGsVDLJpvcx9eHuYorQp4QLT+Mz2rR2lkvgJUBc=; b=qGeYFcQguJyat4m0Y6rli6DTb6lVeOVti6hvTMdkragSAjHgxBhjwN6/6LrJA5+6dgNiCk hAOU41BfwGN7U4syOz+hI6Vh/s1cKJQCsvE1hsqJPBGsLDvf+V2Ay3fDgpuTI383qbRVR5 2+E/pcY3JoBLr04nrI3JspsG8fCFsrM= From: Thorsten Blum To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Kunwu Chan , Vinay Belgaumkar , Aravind Iddamsetty Cc: Thorsten Blum , Ivan Briano , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/i915: Use memdup_user() instead of kmalloc() and copy_from_user() Date: Wed, 25 Sep 2024 16:17:46 +0200 Message-ID: <20240925141750.51198-1-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Use memdup_user() instead of kmalloc() followed by copy_from_user() to simplify set_context_image(). Fixes the following Coccinelle/coccicheck warning reported by memdup_user.cocci: WARNING opportunity for memdup_user Signed-off-by: Thorsten Blum --- 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 c0543c35cd6a..c1cc41e90502 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -2159,18 +2159,12 @@ static int set_context_image(struct i915_gem_contex= t *ctx, goto out_ce; } =20 - state =3D kmalloc(ce->engine->context_size, GFP_KERNEL); - if (!state) { - ret =3D -ENOMEM; + state =3D memdup_user(u64_to_user_ptr(user.image), ce->engine->context_si= ze); + if (IS_ERR(state)) { + ret =3D PTR_ERR(state); goto out_ce; } =20 - if (copy_from_user(state, u64_to_user_ptr(user.image), - ce->engine->context_size)) { - ret =3D -EFAULT; - goto out_state; - } - shmem_state =3D shmem_create_from_data(ce->engine->name, state, ce->engine->context_size); if (IS_ERR(shmem_state)) { --=20 2.46.1