2021-12-02 08:34:19

by Jiapeng Chong

[permalink] [raw]
Subject: [PATCH] net: mpls: use kmemdup() to replace kmalloc + memcpy

Eliminate the follow coccicheck warning:

./net/mpls/af_mpls.c:1530:9-16: WARNING opportunity for kmemdup.

Reported-by: Abaci Robot <[email protected]>
Signed-off-by: Jiapeng Chong <[email protected]>
---
net/mpls/af_mpls.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
index 48f75a5..38c8a1f 100644
--- a/net/mpls/af_mpls.c
+++ b/net/mpls/af_mpls.c
@@ -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);
}
}

--
1.8.3.1