From patchwork Thu Jan 19 09:22:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yingliang X-Patchwork-Id: 13107607 X-Patchwork-Delegate: kuba@kernel.org 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 76CB7C004D4 for ; Thu, 19 Jan 2023 09:04:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229606AbjASJEQ (ORCPT ); Thu, 19 Jan 2023 04:04:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229544AbjASJEP (ORCPT ); Thu, 19 Jan 2023 04:04:15 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBB7967977 for ; Thu, 19 Jan 2023 01:04:13 -0800 (PST) Received: from dggpemm100007.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NyGq63jqxz16NHr; Thu, 19 Jan 2023 17:02:26 +0800 (CST) Received: from huawei.com (10.175.103.91) by dggpemm100007.china.huawei.com (7.185.36.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 19 Jan 2023 17:04:01 +0800 From: Yang Yingliang To: CC: , , , , , , , Subject: [PATCH net-next] net: microchip: vcap: use kmemdup() to allocate memory Date: Thu, 19 Jan 2023 17:22:10 +0800 Message-ID: <20230119092210.3607634-1-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100007.china.huawei.com (7.185.36.116) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Use kmemdup() helper instead of open-coding to simplify the code when allocating newckf and newcaf. Generated by: scripts/coccinelle/api/memdup.cocci Signed-off-by: Yang Yingliang Reviewed-by: Jesse Brandeburg Reviewed-by: Steen Hegelund --- drivers/net/ethernet/microchip/vcap/vcap_api.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c index 71f787a78295..d9cf2cd1925a 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c @@ -1000,18 +1000,16 @@ static struct vcap_rule_internal *vcap_dup_rule(struct vcap_rule_internal *ri, return duprule; list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) { - newckf = kzalloc(sizeof(*newckf), GFP_KERNEL); + newckf = kmemdup(ckf, sizeof(*newckf), GFP_KERNEL); if (!newckf) return ERR_PTR(-ENOMEM); - memcpy(newckf, ckf, sizeof(*newckf)); list_add_tail(&newckf->ctrl.list, &duprule->data.keyfields); } list_for_each_entry(caf, &ri->data.actionfields, ctrl.list) { - newcaf = kzalloc(sizeof(*newcaf), GFP_KERNEL); + newcaf = kmemdup(caf, sizeof(*newcaf), GFP_KERNEL); if (!newcaf) return ERR_PTR(-ENOMEM); - memcpy(newcaf, caf, sizeof(*newcaf)); list_add_tail(&newcaf->ctrl.list, &duprule->data.actionfields); }