linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: mediatek: vcodec: Use kmemdup rather than kmalloc/memcpy
@ 2022-05-24  3:42 Haowen Bai
  0 siblings, 0 replies; only message in thread
From: Haowen Bai @ 2022-05-24  3:42 UTC (permalink / raw)
  To: Tiffany Lin, Andrew-CT Chen, Mauro Carvalho Chehab, Matthias Brugger
  Cc: Haowen Bai, linux-media, linux-kernel, linux-arm-kernel, linux-mediatek

kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Haowen Bai <baihaowen@meizu.com>
---
 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
index 023aba4ec2c4..67949bcedb58 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
@@ -523,13 +523,12 @@ static int vdec_vp9_slice_init_default_frame_ctx(struct vdec_vp9_slice_instance
 	if (vdec_vp9_slice_default_frame_ctx)
 		goto out;
 
-	frame_ctx = kmalloc(sizeof(*frame_ctx), GFP_KERNEL);
+	frame_ctx = kmemdup(remote_frame_ctx, sizeof(*frame_ctx), GFP_KERNEL);
 	if (!frame_ctx) {
 		ret = -ENOMEM;
 		goto out;
 	}
 
-	memcpy(frame_ctx, remote_frame_ctx, sizeof(*frame_ctx));
 	vdec_vp9_slice_default_frame_ctx = frame_ctx;
 
 out:
-- 
2.7.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-24  3:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-24  3:42 [PATCH] media: mediatek: vcodec: Use kmemdup rather than kmalloc/memcpy Haowen Bai

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