From nobody Sun May 19 02:26:48 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E985C433F5 for ; Tue, 24 May 2022 03:42:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233270AbiEXDme (ORCPT ); Mon, 23 May 2022 23:42:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231338AbiEXDmc (ORCPT ); Mon, 23 May 2022 23:42:32 -0400 Received: from mail.meizu.com (unknown [14.29.68.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 089BB62BEB; Mon, 23 May 2022 20:42:28 -0700 (PDT) Received: from IT-EXMB-1-125.meizu.com (172.16.1.125) by mz-mail04.meizu.com (172.16.1.16) with Microsoft SMTP Server (TLS) id 14.3.487.0; Tue, 24 May 2022 11:42:28 +0800 Received: from meizu.meizu.com (172.16.137.70) by IT-EXMB-1-125.meizu.com (172.16.1.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Tue, 24 May 2022 11:42:27 +0800 From: Haowen Bai To: Tiffany Lin , Andrew-CT Chen , Mauro Carvalho Chehab , Matthias Brugger CC: Haowen Bai , , , , Subject: [PATCH] media: mediatek: vcodec: Use kmemdup rather than kmalloc/memcpy Date: Tue, 24 May 2022 11:42:21 +0800 Message-ID: <1653363745-13988-1-git-send-email-baihaowen@meizu.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [172.16.137.70] X-ClientProxiedBy: IT-EXMB-1-126.meizu.com (172.16.1.126) To IT-EXMB-1-125.meizu.com (172.16.1.125) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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_i= f.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(stru= ct vdec_vp9_slice_instance if (vdec_vp9_slice_default_frame_ctx) goto out; =20 - frame_ctx =3D kmalloc(sizeof(*frame_ctx), GFP_KERNEL); + frame_ctx =3D kmemdup(remote_frame_ctx, sizeof(*frame_ctx), GFP_KERNEL); if (!frame_ctx) { ret =3D -ENOMEM; goto out; } =20 - memcpy(frame_ctx, remote_frame_ctx, sizeof(*frame_ctx)); vdec_vp9_slice_default_frame_ctx =3D frame_ctx; =20 out: --=20 2.7.4