diff options
| author | Geliang Tang <[email protected]> | 2025-02-28 10:01:32 +0000 |
|---|---|---|
| committer | Jakub Kicinski <[email protected]> | 2025-03-04 01:16:34 +0000 |
| commit | 483cec55c1ccb9deeefb515fbeb181f736c41736 (patch) | |
| tree | 3316a845f6d562b1cc0de86f585e802227faedae /net/mptcp/protocol.c | |
| parent | sock: add sock_kmemdup helper (diff) | |
| download | kernel-483cec55c1ccb9deeefb515fbeb181f736c41736.tar.gz kernel-483cec55c1ccb9deeefb515fbeb181f736c41736.zip | |
net: use sock_kmemdup for ip_options
Instead of using sock_kmalloc() to allocate an ip_options and then
immediately duplicate another ip_options to the newly allocated one in
ipv6_dup_options(), mptcp_copy_ip_options() and sctp_v4_copy_ip_options(),
the newly added sock_kmemdup() helper can be used to simplify the code.
Signed-off-by: Geliang Tang <[email protected]>
Reviewed-by: Kuniyuki Iwashima <[email protected]>
Acked-by: Matthieu Baerts (NGI0) <[email protected]>
Link: https://patch.msgid.link/91ae749d66600ec6fb679e0e518fda6acb5c3e6f.1740735165.git.tanggeliang@kylinos.cn
Signed-off-by: Jakub Kicinski <[email protected]>
Diffstat (limited to 'net/mptcp/protocol.c')
| -rw-r--r-- | net/mptcp/protocol.c | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 6b61b7dee33b..ec23e65ef0f1 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3178,12 +3178,9 @@ static void mptcp_copy_ip_options(struct sock *newsk, const struct sock *sk) rcu_read_lock(); inet_opt = rcu_dereference(inet->inet_opt); if (inet_opt) { - newopt = sock_kmalloc(newsk, sizeof(*inet_opt) + + newopt = sock_kmemdup(newsk, inet_opt, sizeof(*inet_opt) + inet_opt->opt.optlen, GFP_ATOMIC); - if (newopt) - memcpy(newopt, inet_opt, sizeof(*inet_opt) + - inet_opt->opt.optlen); - else + if (!newopt) net_warn_ratelimited("%s: Failed to copy ip options\n", __func__); } RCU_INIT_POINTER(newinet->inet_opt, newopt); |
