Commit 56649d5d authored by Al Viro's avatar Al Viro Committed by David S. Miller

[NET]: Generic checksum annotations and cleanups.

Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b8e4e01d
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
#ifndef _HAVE_ARCH_COPY_AND_CSUM_FROM_USER #ifndef _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
static inline static inline
unsigned int csum_and_copy_from_user (const unsigned char __user *src, unsigned char *dst, __wsum csum_and_copy_from_user (const void __user *src, void *dst,
int len, int sum, int *err_ptr) int len, __wsum sum, int *err_ptr)
{ {
if (access_ok(VERIFY_READ, src, len)) if (access_ok(VERIFY_READ, src, len))
return csum_partial_copy_from_user(src, dst, len, sum, err_ptr); 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,8 +41,8 @@ unsigned int csum_and_copy_from_user (const unsigned char __user *src, unsigned
#endif #endif
#ifndef HAVE_CSUM_COPY_USER #ifndef HAVE_CSUM_COPY_USER
static __inline__ unsigned int csum_and_copy_to_user static __inline__ __wsum csum_and_copy_to_user
(const unsigned char *src, unsigned char __user *dst, int len, unsigned int sum, int *err_ptr) (const void *src, void __user *dst, int len, __wsum sum, int *err_ptr)
{ {
sum = csum_partial(src, len, sum); sum = csum_partial(src, len, sum);
...@@ -53,35 +53,43 @@ static __inline__ unsigned int csum_and_copy_to_user ...@@ -53,35 +53,43 @@ static __inline__ unsigned int csum_and_copy_to_user
if (len) if (len)
*err_ptr = -EFAULT; *err_ptr = -EFAULT;
return -1; /* invalid checksum */ return (__force __wsum)-1; /* invalid checksum */
} }
#endif #endif
static inline unsigned int csum_add(unsigned int csum, unsigned int addend) static inline __wsum csum_add(__wsum csum, __wsum addend)
{ {
csum += addend; u32 res = (__force u32)csum;
return csum + (csum < addend); 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); return csum_add(csum, ~addend);
} }
static inline unsigned int static inline __wsum
csum_block_add(unsigned int csum, unsigned int csum2, int offset) csum_block_add(__wsum csum, __wsum csum2, int offset)
{ {
u32 sum = (__force u32)csum2;
if (offset&1) if (offset&1)
csum2 = ((csum2&0xFF00FF)<<8)+((csum2>>8)&0xFF00FF); sum = ((sum&0xFF00FF)<<8)+((sum>>8)&0xFF00FF);
return csum_add(csum, csum2); return csum_add(csum, (__force __wsum)sum);
} }
static inline unsigned int static inline __wsum
csum_block_sub(unsigned int csum, unsigned int csum2, int offset) csum_block_sub(__wsum csum, __wsum csum2, int offset)
{ {
u32 sum = (__force u32)csum2;
if (offset&1) if (offset&1)
csum2 = ((csum2&0xFF00FF)<<8)+((csum2>>8)&0xFF00FF); sum = ((sum&0xFF00FF)<<8)+((sum>>8)&0xFF00FF);
return csum_sub(csum, csum2); return csum_sub(csum, (__force __wsum)sum);
}
static inline __wsum csum_unfold(__sum16 n)
{
return (__force __wsum)n;
} }
#endif #endif
...@@ -34,60 +34,60 @@ ...@@ -34,60 +34,60 @@
#ifndef _HAVE_ARCH_IPV6_CSUM #ifndef _HAVE_ARCH_IPV6_CSUM
static __inline__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr, static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
struct in6_addr *daddr, const struct in6_addr *daddr,
__u16 len, __u32 len, unsigned short proto,
unsigned short proto, __wsum csum)
unsigned int csum)
{ {
int carry; int carry;
__u32 ulen; __u32 ulen;
__u32 uproto; __u32 uproto;
__u32 sum = (__force u32)csum;
csum += saddr->s6_addr32[0]; sum += (__force u32)saddr->s6_addr32[0];
carry = (csum < saddr->s6_addr32[0]); carry = (sum < (__force u32)saddr->s6_addr32[0]);
csum += carry; sum += carry;
csum += saddr->s6_addr32[1]; sum += (__force u32)saddr->s6_addr32[1];
carry = (csum < saddr->s6_addr32[1]); carry = (sum < (__force u32)saddr->s6_addr32[1]);
csum += carry; sum += carry;
csum += saddr->s6_addr32[2]; sum += (__force u32)saddr->s6_addr32[2];
carry = (csum < saddr->s6_addr32[2]); carry = (sum < (__force u32)saddr->s6_addr32[2]);
csum += carry; sum += carry;
csum += saddr->s6_addr32[3]; sum += (__force u32)saddr->s6_addr32[3];
carry = (csum < saddr->s6_addr32[3]); carry = (sum < (__force u32)saddr->s6_addr32[3]);
csum += carry; sum += carry;
csum += daddr->s6_addr32[0]; sum += (__force u32)daddr->s6_addr32[0];
carry = (csum < daddr->s6_addr32[0]); carry = (sum < (__force u32)daddr->s6_addr32[0]);
csum += carry; sum += carry;
csum += daddr->s6_addr32[1]; sum += (__force u32)daddr->s6_addr32[1];
carry = (csum < daddr->s6_addr32[1]); carry = (sum < (__force u32)daddr->s6_addr32[1]);
csum += carry; sum += carry;
csum += daddr->s6_addr32[2]; sum += (__force u32)daddr->s6_addr32[2];
carry = (csum < daddr->s6_addr32[2]); carry = (sum < (__force u32)daddr->s6_addr32[2]);
csum += carry; sum += carry;
csum += daddr->s6_addr32[3]; sum += (__force u32)daddr->s6_addr32[3];
carry = (csum < daddr->s6_addr32[3]); carry = (sum < (__force u32)daddr->s6_addr32[3]);
csum += carry; sum += carry;
ulen = htonl((__u32) len); ulen = (__force u32)htonl((__u32) len);
csum += ulen; sum += ulen;
carry = (csum < ulen); carry = (sum < ulen);
csum += carry; sum += carry;
uproto = htonl(proto); uproto = (__force u32)htonl(proto);
csum += uproto; sum += uproto;
carry = (csum < uproto); carry = (sum < uproto);
csum += carry; sum += carry;
return csum_fold(csum); return csum_fold((__force __wsum)csum);
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment