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

Christophe Leroy posted 1 patch 1 month, 3 weeks ago
There is a newer version of this series
net/netfilter/nft_payload.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH net-next] netfilter: nft_payload: Use csum_replace4() instead of opencoding
Posted by Christophe Leroy 1 month, 3 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>
---
 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 7dfc5343dae46..e279b54ed7116 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, fsum, tsum);
 	if (*sum == 0)
 		*sum = CSUM_MANGLED_0;
 }
-- 
2.49.0
Re: [PATCH net-next] netfilter: nft_payload: Use csum_replace4() instead of opencoding
Posted by kernel test robot 1 month, 3 weeks ago
Hi Christophe,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Christophe-Leroy/netfilter-nft_payload-Use-csum_replace4-instead-of-opencoding/20250812-183440
base:   net-next/main
patch link:    https://lore.kernel.org/r/e98467a942d65d2dc45dcf8ff809b43d4a3769eb.1754992552.git.christophe.leroy%40csgroup.eu
patch subject: [PATCH net-next] netfilter: nft_payload: Use csum_replace4() instead of opencoding
config: x86_64-randconfig-122-20250814 (https://download.01.org/0day-ci/archive/20250814/202508141336.K6vIBjy1-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14+deb12u1) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250814/202508141336.K6vIBjy1-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508141336.K6vIBjy1-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> net/netfilter/nft_payload.c:687:28: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be32 [usertype] from @@     got restricted __wsum [usertype] fsum @@
   net/netfilter/nft_payload.c:687:28: sparse:     expected restricted __be32 [usertype] from
   net/netfilter/nft_payload.c:687:28: sparse:     got restricted __wsum [usertype] fsum
>> net/netfilter/nft_payload.c:687:34: sparse: sparse: incorrect type in argument 3 (different base types) @@     expected restricted __be32 [usertype] to @@     got restricted __wsum [usertype] tsum @@
   net/netfilter/nft_payload.c:687:34: sparse:     expected restricted __be32 [usertype] to
   net/netfilter/nft_payload.c:687:34: sparse:     got restricted __wsum [usertype] tsum
>> net/netfilter/nft_payload.c:687:28: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be32 [usertype] from @@     got restricted __wsum [usertype] fsum @@
   net/netfilter/nft_payload.c:687:28: sparse:     expected restricted __be32 [usertype] from
   net/netfilter/nft_payload.c:687:28: sparse:     got restricted __wsum [usertype] fsum
>> net/netfilter/nft_payload.c:687:34: sparse: sparse: incorrect type in argument 3 (different base types) @@     expected restricted __be32 [usertype] to @@     got restricted __wsum [usertype] tsum @@
   net/netfilter/nft_payload.c:687:34: sparse:     expected restricted __be32 [usertype] to
   net/netfilter/nft_payload.c:687:34: sparse:     got restricted __wsum [usertype] tsum

vim +687 net/netfilter/nft_payload.c

   684	
   685	static inline void nft_csum_replace(__sum16 *sum, __wsum fsum, __wsum tsum)
   686	{
 > 687		csum_replace4(sum, fsum, tsum);
   688		if (*sum == 0)
   689			*sum = CSUM_MANGLED_0;
   690	}
   691	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki