[PATCH net-next v2] netfilter: nft_payload: Use csum_replace4() instead of opencoding

Christophe Leroy posted 1 patch 1 month, 2 weeks ago
net/netfilter/nft_payload.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH net-next v2] netfilter: nft_payload: Use csum_replace4() instead of opencoding
Posted by Christophe Leroy 1 month, 2 weeks ago
Open coded calculation can be avoided and replaced by the
equivalent csum_replace4() in nft_csum_replace().

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
v2: Add cast to __be32 to match csum_replace4() expected param types
---
 net/netfilter/nft_payload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index 7dfc5343dae4..059b28ffad0e 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -684,7 +684,7 @@ static const struct nft_expr_ops nft_payload_inner_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, (__force __be32)fsum, (__force __be32)tsum);
 	if (*sum == 0)
 		*sum = CSUM_MANGLED_0;
 }
-- 
2.49.0
Re: [PATCH net-next v2] netfilter: nft_payload: Use csum_replace4() instead of opencoding
Posted by Simon Horman 1 month, 1 week ago
On Mon, Aug 18, 2025 at 11:48:30AM +0200, Christophe Leroy wrote:
> Open coded calculation can be avoided and replaced by the
> equivalent csum_replace4() in nft_csum_replace().
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>

Reviewed-by: Simon Horman <horms@kernel.org>