aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/net/checksum.h42
-rw-r--r--include/net/ip6_checksum.h76
2 files changed, 63 insertions, 55 deletions
diff --git a/include/net/checksum.h b/include/net/checksum.h
index e3ea7cc2c728..2b3c8dc6c11d 100644
--- a/include/net/checksum.h
+++ b/include/net/checksum.h
@@ -27,8 +27,8 @@
27 27
28#ifndef _HAVE_ARCH_COPY_AND_CSUM_FROM_USER 28#ifndef _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
29static inline 29static inline
30unsigned int csum_and_copy_from_user (const unsigned char __user *src, unsigned char *dst, 30__wsum csum_and_copy_from_user (const void __user *src, void *dst,
31 int len, int sum, int *err_ptr) 31 int len, __wsum sum, int *err_ptr)
32{ 32{
33 if (access_ok(VERIFY_READ, src, len)) 33 if (access_ok(VERIFY_READ, src, len))
34 return csum_partial_copy_from_user(src, dst, len, sum, err_ptr); 34 return csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
@@ -41,8 +41,8 @@ unsigned int csum_and_copy_from_user (const unsigned char __user *src, unsigned
41#endif 41#endif
42 42
43#ifndef HAVE_CSUM_COPY_USER 43#ifndef HAVE_CSUM_COPY_USER
44static __inline__ unsigned int csum_and_copy_to_user 44static __inline__ __wsum csum_and_copy_to_user
45(const unsigned char *src, unsigned char __user *dst, int len, unsigned int sum, int *err_ptr) 45(const void *src, void __user *dst, int len, __wsum sum, int *err_ptr)
46{ 46{
47 sum = csum_partial(src, len, sum); 47 sum = csum_partial(src, len, sum);
48 48
@@ -53,35 +53,43 @@ static __inline__ unsigned int csum_and_copy_to_user
53 if (len) 53 if (len)
54 *err_ptr = -EFAULT; 54 *err_ptr = -EFAULT;
55 55
56 return -1; /* invalid checksum */ 56 return (__force __wsum)-1; /* invalid checksum */
57} 57}
58#endif 58#endif
59 59
60static inline unsigned int csum_add(unsigned int csum, unsigned int addend) 60static inline __wsum csum_add(__wsum csum, __wsum addend)
61{ 61{
62 csum += addend; 62 u32 res = (__force u32)csum;
63 return csum + (csum < addend); 63 res += (__force u32)addend;
64 return (__force __wsum)(res + (res < (__force u32)addend));
64} 65}
65 66
66static inline unsigned int csum_sub(unsigned int csum, unsigned int addend) 67static inline __wsum csum_sub(__wsum csum, __wsum addend)
67{ 68{
68 return csum_add(csum, ~addend); 69 return csum_add(csum, ~addend);
69} 70}
70 71
71static inline unsigned int 72static inline __wsum
72csum_block_add(unsigned int csum, unsigned int csum2, int offset) 73csum_block_add(__wsum csum, __wsum csum2, int offset)
73{ 74{
75 u32 sum = (__force u32)csum2;
74 if (offset&1) 76 if (offset&1)
75 csum2 = ((csum2&0xFF00FF)<<8)+((csum2>>8)&0xFF00FF); 77 sum = ((sum&0xFF00FF)<<8)+((sum>>8)&0xFF00FF);
76 return csum_add(csum, csum2); 78 return csum_add(csum, (__force __wsum)sum);
77} 79}
78 80
79static inline unsigned int 81static inline __wsum
80csum_block_sub(unsigned int csum, unsigned int csum2, int offset) 82csum_block_sub(__wsum csum, __wsum csum2, int offset)
81{ 83{
84 u32 sum = (__force u32)csum2;
82 if (offset&1) 85 if (offset&1)
83 csum2 = ((csum2&0xFF00FF)<<8)+((csum2>>8)&0xFF00FF); 86 sum = ((sum&0xFF00FF)<<8)+((sum>>8)&0xFF00FF);
84 return csum_sub(csum, csum2); 87 return csum_sub(csum, (__force __wsum)sum);
88}
89
90static inline __wsum csum_unfold(__sum16 n)
91{
92 return (__force __wsum)n;
85} 93}
86 94
87#endif 95#endif
diff --git a/include/net/ip6_checksum.h b/include/net/ip6_checksum.h
index 3dfc885bdf25..68e2b32cf1d6 100644
--- a/include/net/ip6_checksum.h
+++ b/include/net/ip6_checksum.h
@@ -34,60 +34,60 @@
34 34
35#ifndef _HAVE_ARCH_IPV6_CSUM 35#ifndef _HAVE_ARCH_IPV6_CSUM
36 36
37static __inline__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr, 37static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
38 struct in6_addr *daddr, 38 const struct in6_addr *daddr,
39 __u16 len, 39 __u32 len, unsigned short proto,
40 unsigned short proto, 40 __wsum csum)
41 unsigned int csum)
42{ 41{
43 42
44 int carry; 43 int carry;
45 __u32 ulen; 44 __u32 ulen;
46 __u32 uproto; 45 __u32 uproto;
46 __u32 sum = (__force u32)csum;
47 47
48 csum += saddr->s6_addr32[0]; 48 sum += (__force u32)saddr->s6_addr32[0];
49 carry = (csum < saddr->s6_addr32[0]); 49 carry = (sum < (__force u32)saddr->s6_addr32[0]);
50 csum += carry; 50 sum += carry;
51 51
52 csum += saddr->s6_addr32[1]; 52 sum += (__force u32)saddr->s6_addr32[1];
53 carry = (csum < saddr->s6_addr32[1]); 53 carry = (sum < (__force u32)saddr->s6_addr32[1]);
54 csum += carry; 54 sum += carry;
55 55
56 csum += saddr->s6_addr32[2]; 56 sum += (__force u32)saddr->s6_addr32[2];
57 carry = (csum < saddr->s6_addr32[2]); 57 carry = (sum < (__force u32)saddr->s6_addr32[2]);
58 csum += carry; 58 sum += carry;
59 59
60 csum += saddr->s6_addr32[3]; 60 sum += (__force u32)saddr->s6_addr32[3];
61 carry = (csum < saddr->s6_addr32[3]); 61 carry = (sum < (__force u32)saddr->s6_addr32[3]);
62 csum += carry; 62 sum += carry;
63 63
64 csum += daddr->s6_addr32[0]; 64 sum += (__force u32)daddr->s6_addr32[0];
65 carry = (csum < daddr->s6_addr32[0]); 65 carry = (sum < (__force u32)daddr->s6_addr32[0]);
66 csum += carry; 66 sum += carry;
67 67
68 csum += daddr->s6_addr32[1]; 68 sum += (__force u32)daddr->s6_addr32[1];
69 carry = (csum < daddr->s6_addr32[1]); 69 carry = (sum < (__force u32)daddr->s6_addr32[1]);
70 csum += carry; 70 sum += carry;
71 71
72 csum += daddr->s6_addr32[2]; 72 sum += (__force u32)daddr->s6_addr32[2];
73 carry = (csum < daddr->s6_addr32[2]); 73 carry = (sum < (__force u32)daddr->s6_addr32[2]);
74 csum += carry; 74 sum += carry;
75 75
76 csum += daddr->s6_addr32[3]; 76 sum += (__force u32)daddr->s6_addr32[3];
77 carry = (csum < daddr->s6_addr32[3]); 77 carry = (sum < (__force u32)daddr->s6_addr32[3]);
78 csum += carry; 78 sum += carry;
79 79
80 ulen = htonl((__u32) len); 80 ulen = (__force u32)htonl((__u32) len);
81 csum += ulen; 81 sum += ulen;
82 carry = (csum < ulen); 82 carry = (sum < ulen);
83 csum += carry; 83 sum += carry;
84 84
85 uproto = htonl(proto); 85 uproto = (__force u32)htonl(proto);
86 csum += uproto; 86 sum += uproto;
87 carry = (csum < uproto); 87 carry = (sum < uproto);
88 csum += carry; 88 sum += carry;
89 89
90 return csum_fold(csum); 90 return csum_fold((__force __wsum)csum);
91} 91}
92 92
93#endif 93#endif