Skip to content

Commit 68dd28e

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 8254aa4 commit 68dd28e

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

net/mptcp/pm_netlink.c

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

11581158
/* address not found, add to local list */
1159-
entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
1159+
entry = kmemdup(skc, sizeof(*skc), GFP_ATOMIC);
11601160
if (!entry)
11611161
return -ENOMEM;
11621162

1163-
*entry = *skc;
11641163
entry->addr.port = 0;
11651164
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry, true);
11661165
if (ret < 0)
@@ -1422,13 +1421,12 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info)
14221421
return -EINVAL;
14231422
}
14241423

1425-
entry = kzalloc(sizeof(*entry), GFP_KERNEL_ACCOUNT);
1424+
entry = kmemdup(&addr, sizeof(addr), GFP_KERNEL_ACCOUNT);
14261425
if (!entry) {
14271426
GENL_SET_ERR_MSG(info, "can't allocate addr");
14281427
return -ENOMEM;
14291428
}
14301429

1431-
*entry = addr;
14321430
if (entry->addr.port) {
14331431
ret = mptcp_pm_nl_create_listen_socket(skb->sk, entry);
14341432
if (ret) {

0 commit comments

Comments
 (0)