Skip to content

Commit fd92b90

Browse files
Geliang Tangintel-lab-lkp
authored andcommitted
mptcp: pm: in-kernel: use kmemdup helper
Instead of using kmalloc() or kzalloc() to allocate an entry and then immediately duplicate another entry to the newly allocated one, kmemdup() helper can be used to simplify the code. Signed-off-by: Geliang Tang <[email protected]>
1 parent 443343d commit fd92b90

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

net/mptcp/pm_kernel.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,11 +710,10 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk,
710710
return ret;
711711

712712
/* address not found, add to local list */
713-
entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
713+
entry = kmemdup(skc, sizeof(*skc), GFP_ATOMIC);
714714
if (!entry)
715715
return -ENOMEM;
716716

717-
*entry = *skc;
718717
entry->addr.port = 0;
719718
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry, true, false);
720719
if (ret < 0)
@@ -817,13 +816,12 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info)
817816
return -EINVAL;
818817
}
819818

820-
entry = kzalloc(sizeof(*entry), GFP_KERNEL_ACCOUNT);
819+
entry = kmemdup(&addr, sizeof(addr), GFP_KERNEL_ACCOUNT);
821820
if (!entry) {
822821
GENL_SET_ERR_MSG(info, "can't allocate addr");
823822
return -ENOMEM;
824823
}
825824

826-
*entry = addr;
827825
if (entry->addr.port) {
828826
ret = mptcp_pm_nl_create_listen_socket(skb->sk, entry);
829827
if (ret) {

0 commit comments

Comments
 (0)