From nobody Wed May  7 07:18:49 2025
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org
 [10.30.226.201])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E504223326;
	Thu, 27 Feb 2025 08:24:00 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
 arc=none smtp.client-ip=10.30.226.201
ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1740644640; cv=none;
 b=KJPG1elKBkUbun6f779YXJeHl28CklLkhTkzy54Rwzp++PtGre3xyzjBw913jw86U6V/VP/WHF0/Dxo7BSkIEKquIiEhRHhQk/+ZKAV57nRj/FfIdl3YBZukQRcRkVycXxU80DjLWW4rmmiK7Txr7xZKuf/oY0aucReVGDmDSfU=
ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1740644640; c=relaxed/simple;
	bh=1mAnaS2dCdCIvjEob0nJo7BL3D3i6pJbL+2pXGgKftM=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version;
 b=bANHF7DrU7ZI7KfRQSEVL2hRA8WdbZG+1CG2mO61MtryzamX93KmTpntFeLuVL35brpi97zzyQLZX+Vy9ypvSVmwP66BNGIJOf9z3TLgG+58iMYpLJQMv1rZa3PeWuHIH5qGE+CyBOOLwckGrGtPpIXU3Y9iC388tqTyFmm6eVU=
ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
 dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org
 header.b=ZY9kQx1g; arc=none smtp.client-ip=10.30.226.201
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org
 header.b="ZY9kQx1g"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4620C4CEE7;
	Thu, 27 Feb 2025 08:23:54 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=k20201202; t=1740644640;
	bh=1mAnaS2dCdCIvjEob0nJo7BL3D3i6pJbL+2pXGgKftM=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
	b=ZY9kQx1gSgSg6MZiuIwNNK8JeQ8RJU9nF+Dz+K+DdzCBK5RpBVYb/cb8xR0DOzf7r
	 l/wMdoGlajmK2I6m4eULtSmPJhzzsoWngd8NfD9Ffk3w9jW13rxIKcQxmAZFwPusro
	 CCrqUzlQHhBuHLDoMMVGIgMoEzGx6C2vp+6Wn9tzTuhxYJ5T1805r+PUNfxkuWAKIw
	 1lK5iQ0dmgtEcB/AA7HR5M1CDsqSqrllaWHeXE5ek5YWGLemAmlSlJlSRkP16SzE6b
	 ft4rTuy7Crjl345/rA+GZxHIskIwujh1ZPJLNQ6ppBbwKJIDpp6HQiZ2gsV/RSp6cG
	 sMi7qajmtpz0g==
From: Geliang Tang <geliang@kernel.org>
To: Eric Dumazet <edumazet@google.com>,
	Kuniyuki Iwashima <kuniyu@amazon.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Simon Horman <horms@kernel.org>,
	Neal Cardwell <ncardwell@google.com>,
	David Ahern <dsahern@kernel.org>,
	Matthieu Baerts <matttbe@kernel.org>,
	Mat Martineau <martineau@kernel.org>,
	Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
	Xin Long <lucien.xin@gmail.com>
Cc: Geliang Tang <tanggeliang@kylinos.cn>,
	netdev@vger.kernel.org,
	mptcp@lists.linux.dev,
	linux-sctp@vger.kernel.org
Subject: [PATCH net-next 1/4] sock: add sock_kmemdup helper
Date: Thu, 27 Feb 2025 16:23:23 +0800
Message-ID: 
 <a26c04cba801be45ce01a41b6a14a871246177c5.1740643844.git.tanggeliang@kylinos.cn>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <cover.1740643844.git.tanggeliang@kylinos.cn>
References: <cover.1740643844.git.tanggeliang@kylinos.cn>
Precedence: bulk
X-Mailing-List: mptcp@lists.linux.dev
List-Id: <mptcp.lists.linux.dev>
List-Subscribe: <mailto:mptcp+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:mptcp+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"

From: Geliang Tang <tanggeliang@kylinos.cn>

This patch adds the sock version of kmemdup() helper, named sock_kmemdup(),
to duplicate the input "src" memory block using the socket's option memory
buffer.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 include/net/sock.h |  2 ++
 net/core/sock.c    | 15 +++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/include/net/sock.h b/include/net/sock.h
index efc031163c33..1416c32c4695 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1796,6 +1796,8 @@ static inline struct sk_buff *sock_alloc_send_skb(str=
uct sock *sk,
 }
=20
 void *sock_kmalloc(struct sock *sk, int size, gfp_t priority);
+void *sock_kmemdup(struct sock *sk, const void *src,
+		   int size, gfp_t priority);
 void sock_kfree_s(struct sock *sk, void *mem, int size);
 void sock_kzfree_s(struct sock *sk, void *mem, int size);
 void sk_send_sigurg(struct sock *sk);
diff --git a/net/core/sock.c b/net/core/sock.c
index 5ac445f8244b..95e81d24f4cc 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2819,6 +2819,21 @@ void *sock_kmalloc(struct sock *sk, int size, gfp_t =
priority)
 }
 EXPORT_SYMBOL(sock_kmalloc);
=20
+/*
+ * Duplicate the input "src" memory block using the socket's
+ * option memory buffer.
+ */
+void *sock_kmemdup(struct sock *sk, const void *src,
+		   int size, gfp_t priority)
+{
+	void *mem;
+
+	mem =3D sock_kmalloc(sk, size, priority);
+	if (mem)
+		memcpy(mem, src, size);
+	return mem;
+}
+
 /* Free an option memory block. Note, we actually want the inline
  * here as this allows gcc to detect the nullify and fold away the
  * condition entirely.
--=20
2.43.0
From nobody Wed May  7 07:18:49 2025
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org
 [10.30.226.201])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 758302206BE;
	Thu, 27 Feb 2025 08:24:04 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
 arc=none smtp.client-ip=10.30.226.201
ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1740644644; cv=none;
 b=kIMYGp7zObLegRVO9l6owpd4DAB4HIe9ATvQwBfsr7T6ZfbZ4YHRci0R9dF9Zf2AE90JLEHXKw5X4Pjm6y9JzaYtfotV460qjnhJcplTjurit47DF5Wg/Cqmjc1AdgHSEO8o+QKaqUUlDD56mi+OQhZZOThS00b6sdbCbUicOE8=
ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1740644644; c=relaxed/simple;
	bh=aapUC7Cjh7EbD1HOfRjYKYZWhLoYzlc5DB+Vv2Xpk0k=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version;
 b=P3DInoufZZ5hNy2Iole2kiD5oRxudkA7EEJtcFGOJOi4qYqm9knEZg3nHEp+EMVlMJUcmTKP04B1L4urgzO1jz6/U4gHXNOYDEYDC8lJsla5iwFuj8NoH2rHYhsAmDavVRwA+H+yv3b3XMizb0KKx7R97VuK1SW8BzF/TfaZR6Q=
ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
 dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org
 header.b=Josto2Cc; arc=none smtp.client-ip=10.30.226.201
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org
 header.b="Josto2Cc"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71541C4CEDD;
	Thu, 27 Feb 2025 08:24:00 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=k20201202; t=1740644644;
	bh=aapUC7Cjh7EbD1HOfRjYKYZWhLoYzlc5DB+Vv2Xpk0k=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
	b=Josto2Ccx1mOLUsWqRO2ydXB/wxqW1InQAS2HEPcaR/tD2+B09TjDSzCXUS4cYBfg
	 Qf+kHQRkR23Tbbo93yI+Njk4FHqOj8CRwHWTbFgZBFtaXbCn3poEv6T4pbihM3Pt/p
	 kwWHJ3ntMa7OIniVfziQqPHaOlyuw0kmuYZUeFzhyxKqRsqYr7XgA8nxykKfuREnez
	 0SVTXlvymeDpWKM8mEAefhWNgtJNF/o6977VSzxiuC57qz+aZa/py4Xh6/gw471/Av
	 rYehC/tipjPcYgbL63auc/HTXAPLe+clsStpzk4PaVMeeoffWVlP0sawGhXjjipkC6
	 ZobG4gei3e9Iw==
From: Geliang Tang <geliang@kernel.org>
To: Eric Dumazet <edumazet@google.com>,
	Kuniyuki Iwashima <kuniyu@amazon.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Simon Horman <horms@kernel.org>,
	Neal Cardwell <ncardwell@google.com>,
	David Ahern <dsahern@kernel.org>,
	Matthieu Baerts <matttbe@kernel.org>,
	Mat Martineau <martineau@kernel.org>,
	Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
	Xin Long <lucien.xin@gmail.com>
Cc: Geliang Tang <tanggeliang@kylinos.cn>,
	netdev@vger.kernel.org,
	mptcp@lists.linux.dev,
	linux-sctp@vger.kernel.org
Subject: [PATCH net-next 2/4] net: use sock_kmemdup for ip_options
Date: Thu, 27 Feb 2025 16:23:24 +0800
Message-ID: 
 <d8152b5b6ef238db8acf24d3f06c0f54bb9c513f.1740643844.git.tanggeliang@kylinos.cn>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <cover.1740643844.git.tanggeliang@kylinos.cn>
References: <cover.1740643844.git.tanggeliang@kylinos.cn>
Precedence: bulk
X-Mailing-List: mptcp@lists.linux.dev
List-Id: <mptcp.lists.linux.dev>
List-Subscribe: <mailto:mptcp+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:mptcp+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"

From: Geliang Tang <tanggeliang@kylinos.cn>

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 <tanggeliang@kylinos.cn>
---
 net/ipv6/exthdrs.c   | 3 +--
 net/mptcp/protocol.c | 7 ++-----
 net/sctp/protocol.c  | 7 ++-----
 3 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
index 6789623b2b0d..457de0745a33 100644
--- a/net/ipv6/exthdrs.c
+++ b/net/ipv6/exthdrs.c
@@ -1204,10 +1204,9 @@ ipv6_dup_options(struct sock *sk, struct ipv6_txopti=
ons *opt)
 {
 	struct ipv6_txoptions *opt2;
=20
-	opt2 =3D sock_kmalloc(sk, opt->tot_len, GFP_ATOMIC);
+	opt2 =3D sock_kmemdup(sk, opt, opt->tot_len, GFP_ATOMIC);
 	if (opt2) {
 		long dif =3D (char *)opt2 - (char *)opt;
-		memcpy(opt2, opt, opt->tot_len);
 		if (opt2->hopopt)
 			*((char **)&opt2->hopopt) +=3D dif;
 		if (opt2->dst0opt)
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 =3D rcu_dereference(inet->inet_opt);
 	if (inet_opt) {
-		newopt =3D sock_kmalloc(newsk, sizeof(*inet_opt) +
+		newopt =3D 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);
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 29727ed1008e..5407a3922101 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -185,12 +185,9 @@ static void sctp_v4_copy_ip_options(struct sock *sk, s=
truct sock *newsk)
 	rcu_read_lock();
 	inet_opt =3D rcu_dereference(inet->inet_opt);
 	if (inet_opt) {
-		newopt =3D sock_kmalloc(newsk, sizeof(*inet_opt) +
+		newopt =3D 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)
 			pr_err("%s: Failed to copy ip options\n", __func__);
 	}
 	RCU_INIT_POINTER(newinet->inet_opt, newopt);
--=20
2.43.0
From nobody Wed May  7 07:18:50 2025
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org
 [10.30.226.201])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A31D222574;
	Thu, 27 Feb 2025 08:24:08 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
 arc=none smtp.client-ip=10.30.226.201
ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1740644649; cv=none;
 b=ZlFJ1ou9dSOkuiMfLPxAgbUOG3zrrWbG0c2d/NyxdteTi1pP7S7D08zniuPfhR8/Khr86HoNQzVNTZq/yKjFz7+IH2wG8vni1nu4QxRmQG1DjsTNPwNvUC0UEiKkMaeQfX4sOZjO3s7VVO1Y9rDyoMGp30tnsopiWCV0XAtRQsM=
ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1740644649; c=relaxed/simple;
	bh=74yTkQnIWdu4oYvGKAnTJbzZweABw7andTw5FBDDA0U=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version;
 b=QTuiL5G9/wwrx5lrq8KSarZvkfo9sjdRphWATO0itRSNonubW/j+Jaiq3MkkEcXKxmyyFdia/KD5WPgEGM2fxyG4IHPHsUmqFzjWcMli07ykPCRNkx/42NF69sRYfRhyodTNj/HW/10Muc/0y9J+5rPOw0rRZOcFBfVF94q4JXI=
ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
 dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org
 header.b=AWCGc4ME; arc=none smtp.client-ip=10.30.226.201
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org
 header.b="AWCGc4ME"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB090C4CEEB;
	Thu, 27 Feb 2025 08:24:04 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=k20201202; t=1740644648;
	bh=74yTkQnIWdu4oYvGKAnTJbzZweABw7andTw5FBDDA0U=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
	b=AWCGc4MEuW3QSbpqvjWpyIRZSLCIgRpIcmUbkVcTLrvHb79RnGutD4NvJibMJWYMY
	 hmu0VeZkwjMFQMYj5Jx7TAmkDpRBqphMueNXW05BJOsO6gCgxvet2l+cShtP788zDr
	 otvIaa0xJ3VWfR6y8/QGymAUPAVP2JUPIMdrSIhiKAQLrQRYoGXF0OMw/C8q3VYpyJ
	 MsytYk/r+mvx4aauv3vkSpvHTELZnwf3XbKzohE9IlsVcRz7nZ9BJSwGWHtGtVNV2S
	 BR4YnFGjMamT3id6H1NNgQSyLzMtiAUvzR/oostbCAzUUohhmL5okmQn0onp8VZkGF
	 1J7/udNDMQhwQ==
From: Geliang Tang <geliang@kernel.org>
To: Eric Dumazet <edumazet@google.com>,
	Kuniyuki Iwashima <kuniyu@amazon.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Simon Horman <horms@kernel.org>,
	Neal Cardwell <ncardwell@google.com>,
	David Ahern <dsahern@kernel.org>,
	Matthieu Baerts <matttbe@kernel.org>,
	Mat Martineau <martineau@kernel.org>,
	Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
	Xin Long <lucien.xin@gmail.com>
Cc: Geliang Tang <tanggeliang@kylinos.cn>,
	netdev@vger.kernel.org,
	mptcp@lists.linux.dev,
	linux-sctp@vger.kernel.org
Subject: [PATCH net-next 3/4] mptcp: use sock_kmemdup for address entry
Date: Thu, 27 Feb 2025 16:23:25 +0800
Message-ID: 
 <35aeccb53a34ac50abe54dcb4e4cbaec66e3ae11.1740643844.git.tanggeliang@kylinos.cn>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <cover.1740643844.git.tanggeliang@kylinos.cn>
References: <cover.1740643844.git.tanggeliang@kylinos.cn>
Precedence: bulk
X-Mailing-List: mptcp@lists.linux.dev
List-Id: <mptcp.lists.linux.dev>
List-Subscribe: <mailto:mptcp+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:mptcp+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"

From: Geliang Tang <tanggeliang@kylinos.cn>

Instead of using sock_kmalloc() to allocate an address
entry "e" and then immediately duplicate the input "entry"
to it, the newly added sock_kmemdup() helper can be used in
mptcp_userspace_pm_append_new_local_addr() to simplify the code.

More importantly, the code "*e =3D *entry;" that assigns "entry"
to "e" is not easy to implemented in BPF if we use the same code
to implement an append_new_local_addr() helper of a BFP path
manager. This patch avoids this type of memory assignment
operation.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 net/mptcp/pm_userspace.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 6bf6a20ef7f3..7e7d01bef5d4 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -71,13 +71,12 @@ static int mptcp_userspace_pm_append_new_local_addr(str=
uct mptcp_sock *msk,
 		/* Memory for the entry is allocated from the
 		 * sock option buffer.
 		 */
-		e =3D sock_kmalloc(sk, sizeof(*e), GFP_ATOMIC);
+		e =3D sock_kmemdup(sk, entry, sizeof(*entry), GFP_ATOMIC);
 		if (!e) {
 			ret =3D -ENOMEM;
 			goto append_err;
 		}
=20
-		*e =3D *entry;
 		if (!e->addr.id && needs_id)
 			e->addr.id =3D find_next_zero_bit(id_bitmap,
 							MPTCP_PM_MAX_ADDR_ID + 1,
--=20
2.43.0
From nobody Wed May  7 07:18:50 2025
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org
 [10.30.226.201])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id E41CD222574;
	Thu, 27 Feb 2025 08:24:13 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
 arc=none smtp.client-ip=10.30.226.201
ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1740644654; cv=none;
 b=Jwr6J/cPmJ8plAQwnRpTJdEr5cWwZnXqdyTB7wF47oC1j2R9gphv8qsII6I10z1aziyILqLS570Fb71d7klV+y270REywhJY9xQ6P0R8KbLIX/IfgzmEO/ErqBdOhsPmDiQrpwXNb3SjV+ifEm9yTmZDzkvIbY7nbuzcaC/qiJs=
ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1740644654; c=relaxed/simple;
	bh=0GwyfvPZJn3bBvAUj0HXY0BKgt3S89HLTvK3DfNGxcE=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version;
 b=FTuALEZjGabE2zIHdTw+V1OhjoXOu94MrCDbiAQgWi1ITAHrMboy1nPlMo+6myT9SSkXJnlwGYdBLvM46QHkpxjMheM4Jl+JRIt5It8YpaIwYn8rXA5/w+Rkpvwi8kfNKn5gjoh0AsLryM8o/TYSU4FEbiQtr63ilTcSirguh9E=
ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
 dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org
 header.b=LcyepKSc; arc=none smtp.client-ip=10.30.226.201
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org
 header.b="LcyepKSc"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36156C4CEDD;
	Thu, 27 Feb 2025 08:24:09 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=k20201202; t=1740644653;
	bh=0GwyfvPZJn3bBvAUj0HXY0BKgt3S89HLTvK3DfNGxcE=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
	b=LcyepKScv7I2bZPHYPxlwHmowLkAnN16Fj8SK3XrS5Me9awpoqjYNXNQDvx4wBFqV
	 Gp0C2SaH3ekRyfWLDkYv2/iXzdBdlvGwn8o+HPlp0ijQJEMOx2/irJUWm/D4qtCR1B
	 1OkzG+8zABhUZtKroj1QL5IIkC84fYvx6cYoHBDBQFmwg7VV8tuIO7fGZQxg+z1Fwu
	 Z2HUc6/m4on+Fn6aiA4ph1LWTSQ3zdz9SIzPOPUB4BJah48NLiThtOcz4haRc1KMjD
	 rWi4BWIB1T/G7Iu8lLOWriq14JOh5SkNsAWoVLAeaUJ7B0mtDGRD1UN7kAqHbZgdTO
	 TKuanVKvAbgww==
From: Geliang Tang <geliang@kernel.org>
To: Eric Dumazet <edumazet@google.com>,
	Kuniyuki Iwashima <kuniyu@amazon.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Simon Horman <horms@kernel.org>,
	Neal Cardwell <ncardwell@google.com>,
	David Ahern <dsahern@kernel.org>,
	Matthieu Baerts <matttbe@kernel.org>,
	Mat Martineau <martineau@kernel.org>,
	Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
	Xin Long <lucien.xin@gmail.com>
Cc: Geliang Tang <tanggeliang@kylinos.cn>,
	netdev@vger.kernel.org,
	mptcp@lists.linux.dev,
	linux-sctp@vger.kernel.org
Subject: [PATCH net-next 4/4] net/tcp_ao: use sock_kmemdup for tcp_ao_key
Date: Thu, 27 Feb 2025 16:23:26 +0800
Message-ID: 
 <38054b456a54cc5c7628c81a42816a770f0bff27.1740643844.git.tanggeliang@kylinos.cn>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <cover.1740643844.git.tanggeliang@kylinos.cn>
References: <cover.1740643844.git.tanggeliang@kylinos.cn>
Precedence: bulk
X-Mailing-List: mptcp@lists.linux.dev
List-Id: <mptcp.lists.linux.dev>
List-Subscribe: <mailto:mptcp+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:mptcp+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"

From: Geliang Tang <tanggeliang@kylinos.cn>

Instead of using sock_kmalloc() to allocate a tcp_ao_key "new_key" and
then immediately duplicate the input "key" to it in tcp_ao_copy_key(),
the newly added sock_kmemdup() helper can be used to simplify the code.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 net/ipv4/tcp_ao.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/ipv4/tcp_ao.c b/net/ipv4/tcp_ao.c
index bbb8d5f0eae7..d21412d469cc 100644
--- a/net/ipv4/tcp_ao.c
+++ b/net/ipv4/tcp_ao.c
@@ -246,12 +246,11 @@ static struct tcp_ao_key *tcp_ao_copy_key(struct sock=
 *sk,
 {
 	struct tcp_ao_key *new_key;
=20
-	new_key =3D sock_kmalloc(sk, tcp_ao_sizeof_key(key),
+	new_key =3D sock_kmemdup(sk, key, tcp_ao_sizeof_key(key),
 			       GFP_ATOMIC);
 	if (!new_key)
 		return NULL;
=20
-	*new_key =3D *key;
 	INIT_HLIST_NODE(&new_key->node);
 	tcp_sigpool_get(new_key->tcp_sigpool_id);
 	atomic64_set(&new_key->pkt_good, 0);
--=20
2.43.0