linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v1] net: Use csum_replace_... and csum_sub() helpers instead of opencoding
@ 2022-02-17 15:43 Christophe Leroy
  2022-02-17 17:24 ` Jakub Kicinski
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Christophe Leroy @ 2022-02-17 15:43 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, Pablo Neira Ayuso,
	Jozsef Kadlecsik, Florian Westphal
  Cc: Christophe Leroy, linux-kernel, netdev, netfilter-devel, coreteam

In a couple places, open coded calculation can be avoided
and replaced by the equivalent csum_replace4() and
csum_replace_by_diff().

There's also one place where csum_sub() should be used instead of
csum_add().

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 net/core/utils.c            | 4 ++--
 net/netfilter/nft_payload.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/core/utils.c b/net/core/utils.c
index 1f31a39236d5..938495bc1d34 100644
--- a/net/core/utils.c
+++ b/net/core/utils.c
@@ -476,9 +476,9 @@ void inet_proto_csum_replace_by_diff(__sum16 *sum, struct sk_buff *skb,
 				     __wsum diff, bool pseudohdr)
 {
 	if (skb->ip_summed != CHECKSUM_PARTIAL) {
-		*sum = csum_fold(csum_add(diff, ~csum_unfold(*sum)));
+		csum_replace_by_diff(sum, diff);
 		if (skb->ip_summed == CHECKSUM_COMPLETE && pseudohdr)
-			skb->csum = ~csum_add(diff, ~skb->csum);
+			skb->csum = ~csum_sub(diff, skb->csum);
 	} else if (pseudohdr) {
 		*sum = ~csum_fold(csum_add(diff, csum_unfold(*sum)));
 	}
diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index 5cc06aef4345..b6cfd0759bc5 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -557,7 +557,7 @@ const struct nft_expr_ops nft_payload_fast_ops = {
 
 static inline void nft_csum_replace(__sum16 *sum, __wsum fsum, __wsum tsum)
 {
-	*sum = csum_fold(csum_add(csum_sub(~csum_unfold(*sum), fsum), tsum));
+	csum_replace4(sum, fsum, tsum);
 	if (*sum == 0)
 		*sum = CSUM_MANGLED_0;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-04-22 11:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-17 15:43 [PATCH net-next v1] net: Use csum_replace_... and csum_sub() helpers instead of opencoding Christophe Leroy
2022-02-17 17:24 ` Jakub Kicinski
2022-02-17 18:11   ` Christophe Leroy
2022-02-17 18:14     ` Jakub Kicinski
2022-02-17 18:39       ` Christophe Leroy
2022-02-17 18:54         ` Jakub Kicinski
2022-02-18  7:43 ` kernel test robot
2022-04-22 11:48 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).