]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
[NET]: Generic checksum annotations and cleanups.
authorAl Viro <viro@zeniv.linux.org.uk>
Wed, 15 Nov 2006 05:23:59 +0000 (21:23 -0800)
committerDavid S. Miller <davem@sunset.davemloft.net>
Sun, 3 Dec 2006 05:23:25 +0000 (21:23 -0800)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/checksum.h
include/net/ip6_checksum.h

index e3ea7cc2c7283958c27034298c29cc58059cc800..2b3c8dc6c11d5f1ac03314a637addda67370c22d 100644 (file)
@@ -27,8 +27,8 @@
 
 #ifndef _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
 static inline
-unsigned int csum_and_copy_from_user (const unsigned char __user *src, unsigned char *dst,
-                                     int len, int sum, int *err_ptr)
+__wsum csum_and_copy_from_user (const void __user *src, void *dst,
+                                     int len, __wsum sum, int *err_ptr)
 {
        if (access_ok(VERIFY_READ, src, len))
                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
 #endif
 
 #ifndef HAVE_CSUM_COPY_USER
-static __inline__ unsigned int csum_and_copy_to_user
-(const unsigned char *src, unsigned char __user *dst, int len, unsigned int sum, int *err_ptr)
+static __inline__ __wsum csum_and_copy_to_user
+(const void *src, void __user *dst, int len, __wsum sum, int *err_ptr)
 {
        sum = csum_partial(src, len, sum);
 
@@ -53,35 +53,43 @@ static __inline__ unsigned int csum_and_copy_to_user
        if (len)
                *err_ptr = -EFAULT;
 
-       return -1; /* invalid checksum */
+       return (__force __wsum)-1; /* invalid checksum */
 }
 #endif
 
-static inline unsigned int csum_add(unsigned int csum, unsigned int addend)
+static inline __wsum csum_add(__wsum csum, __wsum addend)
 {
-       csum += addend;
-       return csum + (csum < addend);
+       u32 res = (__force u32)csum;
+       res += (__force u32)addend;
+       return (__force __wsum)(res + (res < (__force u32)addend));
 }
 
-static inline unsigned int csum_sub(unsigned int csum, unsigned int addend)
+static inline __wsum csum_sub(__wsum csum, __wsum addend)
 {
        return csum_add(csum, ~addend);
 }
 
-static inline unsigned int
-csum_block_add(unsigned int csum, unsigned int csum2, int offset)
+static inline __wsum
+csum_block_add(__wsum csum, __wsum csum2, int offset)
 {
+       u32 sum = (__force u32)csum2;
        if (offset&1)
-               csum2 = ((csum2&0xFF00FF)<<8)+((csum2>>8)&0xFF00FF);
-       return csum_add(csum, csum2);
+               sum = ((sum&0xFF00FF)<<8)+((sum>>8)&0xFF00FF);
+       return csum_add(csum, (__force __wsum)sum);
 }
 
-static inline unsigned int
-csum_block_sub(unsigned int csum, unsigned int csum2, int offset)
+static inline __wsum
+csum_block_sub(__wsum csum, __wsum csum2, int offset)
 {
+       u32 sum = (__force u32)csum2;
        if (offset&1)
-               csum2 = ((csum2&0xFF00FF)<<8)+((csum2>>8)&0xFF00FF);
-       return csum_sub(csum, csum2);
+               sum = ((sum&0xFF00FF)<<8)+((sum>>8)&0xFF00FF);
+       return csum_sub(csum, (__force __wsum)sum);
+}
+
+static inline __wsum csum_unfold(__sum16 n)
+{
+       return (__force __wsum)n;
 }
 
 #endif
index 3dfc885bdf255c10f3355c1a61a80596fb1905c8..68e2b32cf1d6f1ed421a579c1cd19e707b3df80d 100644 (file)
 
 #ifndef _HAVE_ARCH_IPV6_CSUM
 
-static __inline__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr,
-                                                    struct in6_addr *daddr,
-                                                    __u16 len,
-                                                    unsigned short proto,
-                                                    unsigned int csum) 
+static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
+                                         const struct in6_addr *daddr,
+                                         __u32 len, unsigned short proto,
+                                         __wsum csum)
 {
 
        int carry;
        __u32 ulen;
        __u32 uproto;
+       __u32 sum = (__force u32)csum;
 
-       csum += saddr->s6_addr32[0];
-       carry = (csum < saddr->s6_addr32[0]);
-       csum += carry;
+       sum += (__force u32)saddr->s6_addr32[0];
+       carry = (sum < (__force u32)saddr->s6_addr32[0]);
+       sum += carry;
 
-       csum += saddr->s6_addr32[1];
-       carry = (csum < saddr->s6_addr32[1]);
-       csum += carry;
+       sum += (__force u32)saddr->s6_addr32[1];
+       carry = (sum < (__force u32)saddr->s6_addr32[1]);
+       sum += carry;
 
-       csum += saddr->s6_addr32[2];
-       carry = (csum < saddr->s6_addr32[2]);
-       csum += carry;
+       sum += (__force u32)saddr->s6_addr32[2];
+       carry = (sum < (__force u32)saddr->s6_addr32[2]);
+       sum += carry;
 
-       csum += saddr->s6_addr32[3];
-       carry = (csum < saddr->s6_addr32[3]);
-       csum += carry;
+       sum += (__force u32)saddr->s6_addr32[3];
+       carry = (sum < (__force u32)saddr->s6_addr32[3]);
+       sum += carry;
 
-       csum += daddr->s6_addr32[0];
-       carry = (csum < daddr->s6_addr32[0]);
-       csum += carry;
+       sum += (__force u32)daddr->s6_addr32[0];
+       carry = (sum < (__force u32)daddr->s6_addr32[0]);
+       sum += carry;
 
-       csum += daddr->s6_addr32[1];
-       carry = (csum < daddr->s6_addr32[1]);
-       csum += carry;
+       sum += (__force u32)daddr->s6_addr32[1];
+       carry = (sum < (__force u32)daddr->s6_addr32[1]);
+       sum += carry;
 
-       csum += daddr->s6_addr32[2];
-       carry = (csum < daddr->s6_addr32[2]);
-       csum += carry;
+       sum += (__force u32)daddr->s6_addr32[2];
+       carry = (sum < (__force u32)daddr->s6_addr32[2]);
+       sum += carry;
 
-       csum += daddr->s6_addr32[3];
-       carry = (csum < daddr->s6_addr32[3]);
-       csum += carry;
+       sum += (__force u32)daddr->s6_addr32[3];
+       carry = (sum < (__force u32)daddr->s6_addr32[3]);
+       sum += carry;
 
-       ulen = htonl((__u32) len);
-       csum += ulen;
-       carry = (csum < ulen);
-       csum += carry;
+       ulen = (__force u32)htonl((__u32) len);
+       sum += ulen;
+       carry = (sum < ulen);
+       sum += carry;
 
-       uproto = htonl(proto);
-       csum += uproto;
-       carry = (csum < uproto);
-       csum += carry;
+       uproto = (__force u32)htonl(proto);
+       sum += uproto;
+       carry = (sum < uproto);
+       sum += carry;
 
-       return csum_fold(csum);
+       return csum_fold((__force __wsum)csum);
 }
 
 #endif