]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - lib/checksum.c
lib/checksum.c: fix carry in csum_tcpudp_nofold
[mirror_ubuntu-bionic-kernel.git] / lib / checksum.c
index 129775eb6de63a6155cea830df17b6c2476eb024..fcf38943132c490206fe6045e7ed19eaa865d292 100644 (file)
@@ -47,6 +47,15 @@ static inline unsigned short from32to16(unsigned int x)
        return x;
 }
 
+static inline u32 from64to32(u64 x)
+{
+       /* add up 32-bit and 32-bit for 32+c bit */
+       x = (x & 0xffffffff) + (x >> 32);
+       /* add up carry.. */
+       x = (x & 0xffffffff) + (x >> 32);
+       return (u32)x;
+}
+
 static unsigned int do_csum(const unsigned char *buff, int len)
 {
        int odd;
@@ -195,8 +204,7 @@ __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
 #else
        s += (proto + len) << 8;
 #endif
-       s += (s >> 32);
-       return (__force __wsum)s;
+       return (__force __wsum)from64to32(s);
 }
 EXPORT_SYMBOL(csum_tcpudp_nofold);
 #endif