diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2006-11-15 00:23:59 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-12-03 00:23:25 -0500 |
commit | 56649d5d3c4cb0fe6dd34808ca9f9208d84130ab (patch) | |
tree | 0cb1253ffbc068033d5e7bef9b34383816c3050c /include/net/checksum.h | |
parent | b8e4e01dd5576a14602a49829f9f9d997bb60b6b (diff) |
[NET]: Generic checksum annotations and cleanups.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/checksum.h')
-rw-r--r-- | include/net/checksum.h | 42 |
1 files changed, 25 insertions, 17 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 |
29 | static inline | 29 | static inline |
30 | unsigned 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 |
44 | static __inline__ unsigned int csum_and_copy_to_user | 44 | static __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 | ||
60 | static inline unsigned int csum_add(unsigned int csum, unsigned int addend) | 60 | static 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 | ||
66 | static inline unsigned int csum_sub(unsigned int csum, unsigned int addend) | 67 | static 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 | ||
71 | static inline unsigned int | 72 | static inline __wsum |
72 | csum_block_add(unsigned int csum, unsigned int csum2, int offset) | 73 | csum_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 | ||
79 | static inline unsigned int | 81 | static inline __wsum |
80 | csum_block_sub(unsigned int csum, unsigned int csum2, int offset) | 82 | csum_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 | |||
90 | static inline __wsum csum_unfold(__sum16 n) | ||
91 | { | ||
92 | return (__force __wsum)n; | ||
85 | } | 93 | } |
86 | 94 | ||
87 | #endif | 95 | #endif |