From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5E5532DC328; Tue, 11 Nov 2025 01:31:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762824674; cv=none; b=hVv4iPpbtlx4eJRDBFmY2sVIzqTTK7Ipvt4omg+QJrtVE2jfPpjUmibH0wI+/TJ4L2lSFhY/QJab+e0amqLkQaeBaUPQiw7aqobBk8bWYAFFj5Q6fS92YRqWXkDcRBCvt/FSDUX1DakBg1TwU44b0/3tG9XwC+fykQSQ7OxcsZk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762824674; c=relaxed/simple; bh=VYC1RVqkIVwwae6u0JZ6gdMmAUb5LbidN8zcCEWgrEQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qQXLBfd5N2JgRPko7KZEJaQXv+4D1HL3wJt8CBkdg6mmkC8PTtqdYLrYi068P2Ih/YJfThOP0H+i8UbXrW9R5l5cXCAP2cnZyk4ALXfPVkHgnOHiv5QL2PapGYB5yerRHCeq4kZeblNfOqALt4JJe2yUbly1ocjSiVM5GP2ELik= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qkbe1L0u; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="qkbe1L0u" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE4CAC4CEF5; Tue, 11 Nov 2025 01:31:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1762824674; bh=VYC1RVqkIVwwae6u0JZ6gdMmAUb5LbidN8zcCEWgrEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qkbe1L0u5EepmlIKulWjirJOTgTZvFjAN6enHD7Ij3aswnC9qz/VVjkdZplWeKeXb qcj9IVY2HgpQiGgjWwb7lCJ5FND9ayP+/YCpyzbGSg7zWr0qcuDnPnb5lRzESGYBYu EcvDYnbapwHM00QLW10sWjVHTxmGlRvgwLWd8lhI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tvrtko Ursulin , Alex Deucher , Sasha Levin Subject: [PATCH 6.17 548/849] drm/amdgpu: Use memdup_array_user in amdgpu_cs_wait_fences_ioctl Date: Tue, 11 Nov 2025 09:41:58 +0900 Message-ID: <20251111004549.654274584@linuxfoundation.org> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20251111004536.460310036@linuxfoundation.org> References: <20251111004536.460310036@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tvrtko Ursulin [ Upstream commit dea75df7afe14d6217576dbc28cc3ec1d1f712fb ] Replace kmalloc_array() + copy_from_user() with memdup_array_user(). This shrinks the source code and improves separation between the kernel and userspace slabs. Signed-off-by: Tvrtko Ursulin Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index d3f220be2ef9a..d541e214a18c8 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -1767,30 +1767,21 @@ int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data, { struct amdgpu_device *adev = drm_to_adev(dev); union drm_amdgpu_wait_fences *wait = data; - uint32_t fence_count = wait->in.fence_count; - struct drm_amdgpu_fence *fences_user; struct drm_amdgpu_fence *fences; int r; /* Get the fences from userspace */ - fences = kmalloc_array(fence_count, sizeof(struct drm_amdgpu_fence), - GFP_KERNEL); - if (fences == NULL) - return -ENOMEM; - - fences_user = u64_to_user_ptr(wait->in.fences); - if (copy_from_user(fences, fences_user, - sizeof(struct drm_amdgpu_fence) * fence_count)) { - r = -EFAULT; - goto err_free_fences; - } + fences = memdup_array_user(u64_to_user_ptr(wait->in.fences), + wait->in.fence_count, + sizeof(struct drm_amdgpu_fence)); + if (IS_ERR(fences)) + return PTR_ERR(fences); if (wait->in.wait_all) r = amdgpu_cs_wait_all_fences(adev, filp, wait, fences); else r = amdgpu_cs_wait_any_fence(adev, filp, wait, fences); -err_free_fences: kfree(fences); return r; -- 2.51.0