diff mbox series

[net-next] inet_ecn: Use csum16_add() helper for IP_ECN_set_* helpers

Message ID 20201210105455.122471-1-toke@redhat.com
State Superseded
Headers show
Series [net-next] inet_ecn: Use csum16_add() helper for IP_ECN_set_* helpers | expand

Commit Message

Toke Høiland-Jørgensen Dec. 10, 2020, 10:54 a.m. UTC
Jakub pointed out that the IP_ECN_set* helpers basically open-code
csum16_add(), so let's switch them over to using the helper instead.

Reported-by: Jakub Kicinski <kuba@kernel.org>
Tested-by: Jonathan Morton <chromatix99@gmail.com>
Tested-by: Pete Heist <pete@heistp.net>
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 include/net/inet_ecn.h | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Comments

kernel test robot Dec. 10, 2020, 3:43 p.m. UTC | #1
Hi "Toke,

I love your patch! Perhaps something to improve:

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

url:    https://github.com/0day-ci/linux/commits/Toke-H-iland-J-rgensen/inet_ecn-Use-csum16_add-helper-for-IP_ECN_set_-helpers/20201210-190846
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git a7105e3472bf6bb3099d1293ea7d70e7783aa582
config: i386-randconfig-s001-20201209 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.3-179-ga00755aa-dirty
        # https://github.com/0day-ci/linux/commit/fbed6705f871b8eb4e522c874927ac8e57c8889b
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Toke-H-iland-J-rgensen/inet_ecn-Use-csum16_add-helper-for-IP_ECN_set_-helpers/20201210-190846
        git checkout fbed6705f871b8eb4e522c874927ac8e57c8889b
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


"sparse warnings: (new ones prefixed by >>)"
   net/sched/sch_choke.c: note: in included file:
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
--
   net/sched/sch_sfb.c: note: in included file:
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
--
   net/sched/sch_codel.c: note: in included file (through include/net/codel.h):
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
--
   net/sched/sch_red.c: note: in included file:
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
--
   net/sched/sch_fq.c: note: in included file (through include/net/tcp.h):
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
--
   net/sched/sch_fq_codel.c: note: in included file (through include/net/codel.h):
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
--
   net/sched/sch_netem.c: note: in included file:
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
--
   net/sched/sch_sfq.c: note: in included file (through include/net/red.h):
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add
>> include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:99:45: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be16 [usertype] addend @@     got unsigned short [assigned] [usertype] check_add @@
   include/net/inet_ecn.h:99:45: sparse:     expected restricted __be16 [usertype] addend
   include/net/inet_ecn.h:99:45: sparse:     got unsigned short [assigned] [usertype] check_add

vim +97 include/net/inet_ecn.h

    67	
    68	#define IP6_ECN_flow_init(label) do {		\
    69	      (label) &= ~htonl(INET_ECN_MASK << 20);	\
    70	    } while (0)
    71	
    72	#define	IP6_ECN_flow_xmit(sk, label) do {				\
    73		if (INET_ECN_is_capable(inet6_sk(sk)->tclass))			\
    74			(label) |= htonl(INET_ECN_ECT_0 << 20);			\
    75	    } while (0)
    76	
    77	static inline int IP_ECN_set_ce(struct iphdr *iph)
    78	{
    79		u32 ecn = (iph->tos + 1) & INET_ECN_MASK;
    80		u16 check_add;
    81	
    82		/*
    83		 * After the last operation we have (in binary):
    84		 * INET_ECN_NOT_ECT => 01
    85		 * INET_ECN_ECT_1   => 10
    86		 * INET_ECN_ECT_0   => 11
    87		 * INET_ECN_CE      => 00
    88		 */
    89		if (!(ecn & 2))
    90			return !ecn;
    91	
    92		/*
    93		 * The following gives us:
    94		 * INET_ECN_ECT_1 => check += htons(0xFFFD)
    95		 * INET_ECN_ECT_0 => check += htons(0xFFFE)
    96		 */
  > 97		check_add = htons(0xFFFB) + htons(ecn);
    98	
  > 99		iph->check = csum16_add(iph->check, check_add);
   100		iph->tos |= INET_ECN_CE;
   101		return 1;
   102	}
   103	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/include/net/inet_ecn.h b/include/net/inet_ecn.h
index 563457fec557..fad1bc596c29 100644
--- a/include/net/inet_ecn.h
+++ b/include/net/inet_ecn.h
@@ -8,6 +8,7 @@ 
 
 #include <net/inet_sock.h>
 #include <net/dsfield.h>
+#include <net/checksum.h>
 
 enum {
 	INET_ECN_NOT_ECT = 0,
@@ -75,8 +76,8 @@  static inline void INET_ECN_dontxmit(struct sock *sk)
 
 static inline int IP_ECN_set_ce(struct iphdr *iph)
 {
-	u32 check = (__force u32)iph->check;
 	u32 ecn = (iph->tos + 1) & INET_ECN_MASK;
+	u16 check_add;
 
 	/*
 	 * After the last operation we have (in binary):
@@ -93,23 +94,19 @@  static inline int IP_ECN_set_ce(struct iphdr *iph)
 	 * INET_ECN_ECT_1 => check += htons(0xFFFD)
 	 * INET_ECN_ECT_0 => check += htons(0xFFFE)
 	 */
-	check += (__force u16)htons(0xFFFB) + (__force u16)htons(ecn);
+	check_add = htons(0xFFFB) + htons(ecn);
 
-	iph->check = (__force __sum16)(check + (check>=0xFFFF));
+	iph->check = csum16_add(iph->check, check_add);
 	iph->tos |= INET_ECN_CE;
 	return 1;
 }
 
 static inline int IP_ECN_set_ect1(struct iphdr *iph)
 {
-	u32 check = (__force u32)iph->check;
-
 	if ((iph->tos & INET_ECN_MASK) != INET_ECN_ECT_0)
 		return 0;
 
-	check += (__force u16)htons(0x1);
-
-	iph->check = (__force __sum16)(check + (check>=0xFFFF));
+	iph->check = csum16_add(iph->check, htons(0x1));
 	iph->tos ^= INET_ECN_MASK;
 	return 1;
 }