All of lore.kernel.org
 help / color / mirror / Atom feed
From: "GONG, Ruiqi" <gongruiqi1@huawei.com>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Benjamin Poirier <bpoirier@nvidia.com>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	Wang Weiyang <wangweiyang2@huawei.com>,
	"Xiu Jianfeng" <xiujianfeng@huawei.com>
Subject: [PATCH] net: mpls: fix memdup.cocci warning
Date: Wed, 23 Mar 2022 16:07:06 +0800	[thread overview]
Message-ID: <20220323080706.212531-1-gongruiqi1@huawei.com> (raw)

Simply use kmemdup instead of explicitly allocating and copying memory.

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

Fixes: 7d4741eacdef ("net: mpls: Fix notifications when deleting a device")
Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
---
 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 d6fdc5782d33..35b5f806fdda 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);
 			}
 		}
 
-- 
2.17.1


             reply	other threads:[~2022-03-23  8:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-23  8:07 GONG, Ruiqi [this message]
2022-03-23 15:48 ` [PATCH] net: mpls: fix memdup.cocci warning Jakub Kicinski
2022-04-06 11:46 GONG, Ruiqi
2022-04-08  4:20 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220323080706.212531-1-gongruiqi1@huawei.com \
    --to=gongruiqi1@huawei.com \
    --cc=bpoirier@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=wangweiyang2@huawei.com \
    --cc=xiujianfeng@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.