linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/3] drm/admgpu: replace kmalloc() and memcpy() with kmemdup()
@ 2024-12-17 22:58 Mirsad Todorovac
  2024-12-17 22:58 ` [PATCH v1 2/3] xfs/libxfs: " Mirsad Todorovac
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Mirsad Todorovac @ 2024-12-17 22:58 UTC (permalink / raw)
  To: Alex Deucher, Victor Skvortsov, amd-gfx, dri-devel, linux-kernel
  Cc: Christian König, Xinhui Pan, David Airlie, Simona Vetter,
	Mirsad Todorovac, Zhigang Luo, Hawking Zhang, Lijo Lazar,
	Yunxiang Li, Jack Xiao, Vignesh Chander, Danijel Slivka

The static analyser tool gave the following advice:

./drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c:1266:7-14: WARNING opportunity for kmemdup

 → 1266         tmp = kmalloc(used_size, GFP_KERNEL);
   1267         if (!tmp)
   1268                 return -ENOMEM;
   1269
 → 1270         memcpy(tmp, &host_telemetry->body.error_count, used_size);

Replacing kmalloc() + memcpy() with kmemdump() doesn't change semantics.
Original code works without fault, so this is not a bug fix but proposed improvement.

Link: https://lwn.net/Articles/198928/
Fixes: 84a2947ecc85c ("drm/amdgpu: Implement virt req_ras_err_count")
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: "Christian König" <christian.koenig@amd.com>
Cc: Xinhui Pan <Xinhui.Pan@amd.com>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: Zhigang Luo <Zhigang.Luo@amd.com>
Cc: Victor Skvortsov <victor.skvortsov@amd.com>
Cc: Hawking Zhang <Hawking.Zhang@amd.com>
Cc: Lijo Lazar <lijo.lazar@amd.com>
Cc: Yunxiang Li <Yunxiang.Li@amd.com>
Cc: Jack Xiao <Jack.Xiao@amd.com>
Cc: Vignesh Chander <Vignesh.Chander@amd.com>
Cc: Danijel Slivka <danijel.slivka@amd.com>
Cc: amd-gfx@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mirsad Todorovac <mtodorovac69@gmail.com>
---
 v1:
	initial version.

 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index c704e9803e11..0af469ec6fcc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -1263,12 +1263,10 @@ static int amdgpu_virt_cache_host_error_counts(struct amdgpu_device *adev,
 	if (used_size > (AMD_SRIOV_RAS_TELEMETRY_SIZE_KB << 10))
 		return 0;
 
-	tmp = kmalloc(used_size, GFP_KERNEL);
+	tmp = kmemdup(&host_telemetry->body.error_count, used_size, GFP_KERNEL);
 	if (!tmp)
 		return -ENOMEM;
 
-	memcpy(tmp, &host_telemetry->body.error_count, used_size);
-
 	if (checksum != amd_sriov_msg_checksum(tmp, used_size, 0, 0))
 		goto out;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2025-01-14 15:33 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-17 22:58 [PATCH v1 1/3] drm/admgpu: replace kmalloc() and memcpy() with kmemdup() Mirsad Todorovac
2024-12-17 22:58 ` [PATCH v1 2/3] xfs/libxfs: " Mirsad Todorovac
2024-12-19  0:35   ` Darrick J. Wong
2024-12-29 12:58     ` Andrey Albershteyn
2025-01-06 19:37       ` Darrick J. Wong
2025-01-09  8:49   ` Carlos Maiolino
2025-01-14 10:28   ` Carlos Maiolino
2024-12-17 22:58 ` [PATCH v1 3/3] btrfs: " Mirsad Todorovac
2024-12-18 10:32   ` Mark Harmstone
2024-12-18 17:03     ` Mirsad Todorovac
2024-12-18  8:03 ` [PATCH v1 1/3] drm/admgpu: " Lazar, Lijo
2024-12-18 14:47   ` Alex Deucher
2025-01-14 10:30 ` Carlos Maiolino
2025-01-14 14:27   ` Alex Deucher
2025-01-14 15:33     ` Carlos Maiolino

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).