summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeliang Tang <tanggeliang@kylinos.cn>2025-03-13 11:20:51 +0100
committerPaolo Abeni <pabeni@redhat.com>2025-03-20 10:14:48 +0100
commitfa123489e7ef5c5c26d530bc4d7411bca7253c69 (patch)
tree862c44b68d628005e1866f10bb9d875cba04fe56
parentb97d6b6820279c84d67d5e870d87ce45e8e348a5 (diff)
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 <tanggeliang@kylinos.cn> Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/20250313-net-next-mptcp-pm-ops-intro-v1-2-f4e4a88efc50@kernel.org Signed-off-by: Paolo Abeni <pabeni@redhat.com>
-rw-r--r--net/mptcp/pm_kernel.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c
index 62ae68abb2cb..806a9b5b3c07 100644
--- a/net/mptcp/pm_kernel.c
+++ b/net/mptcp/pm_kernel.c
@@ -710,11 +710,10 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk,
return ret;
/* address not found, add to local list */
- entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
+ entry = kmemdup(skc, sizeof(*skc), GFP_ATOMIC);
if (!entry)
return -ENOMEM;
- *entry = *skc;
entry->addr.port = 0;
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry, true, false);
if (ret < 0)
@@ -817,13 +816,12 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info)
return -EINVAL;
}
- entry = kzalloc(sizeof(*entry), GFP_KERNEL_ACCOUNT);
+ entry = kmemdup(&addr, sizeof(addr), GFP_KERNEL_ACCOUNT);
if (!entry) {
GENL_SET_ERR_MSG(info, "can't allocate addr");
return -ENOMEM;
}
- *entry = addr;
if (entry->addr.port) {
ret = mptcp_pm_nl_create_listen_socket(skb->sk, entry);
if (ret) {