net: microchip: vcap: use kmemdup() to allocate memory
authorYang Yingliang <yangyingliang@huawei.com>
Thu, 19 Jan 2023 09:22:10 +0000 (17:22 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sat, 21 Jan 2023 02:15:10 +0000 (18:15 -0800)
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 <yangyingliang@huawei.com>
Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Reviewed-by: Steen Hegelund <Steen.Hegelund@microchip.com>
Link: https://lore.kernel.org/r/20230119092210.3607634-1-yangyingliang@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/microchip/vcap/vcap_api.c

index 71f787a78295872379bb715eabc823e14af388ad..d9cf2cd1925a06e7c1b46231044994ed0ace7a9d 100644 (file)
@@ -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);
        }