net: mpls: fix memdup.cocci warning
authorGONG, Ruiqi <gongruiqi1@huawei.com>
Wed, 6 Apr 2022 11:46:29 +0000 (19:46 +0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 8 Apr 2022 04:06:41 +0000 (21:06 -0700)
Simply use kmemdup instead of explicitly allocating and copying memory.

Generated by: scripts/coccinelle/api/memdup.cocci

Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
Link: https://lore.kernel.org/r/20220406114629.182833-1-gongruiqi1@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/mpls/af_mpls.c

index d6fdc57..35b5f80 100644 (file)
@@ -1527,10 +1527,9 @@ static int mpls_ifdown(struct net_device *dev, int event)
                                        rt->rt_nh_size;
                                struct mpls_route *orig = rt;
 
-                               rt = kmalloc(size, GFP_KERNEL);
+                               rt = kmemdup(orig, size, GFP_KERNEL);
                                if (!rt)
                                        return -ENOMEM;
-                               memcpy(rt, orig, size);
                        }
                }