Commit 9d3d41955845939cb41b87affb039db0bae03b65

Authored by Al Viro
Committed by David S. Miller
1 parent abf419b809

[NET]: V850 checksum annotations and cleanups.

* sanitize prototypes, annotate
* collapse csum_partial_copy
* usual ntohs->shift

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 3 changed files with 31 additions and 35 deletions Side-by-side Diff

arch/v850/kernel/v850_ksyms.c
... ... @@ -24,7 +24,7 @@
24 24 EXPORT_SYMBOL (__bug);
25 25  
26 26 /* Networking helper routines. */
27   -EXPORT_SYMBOL (csum_partial_copy);
  27 +EXPORT_SYMBOL (csum_partial_copy_nocheck);
28 28 EXPORT_SYMBOL (csum_partial_copy_from_user);
29 29 EXPORT_SYMBOL (ip_compute_csum);
30 30 EXPORT_SYMBOL (ip_fast_csum);
arch/v850/lib/checksum.c
... ... @@ -88,32 +88,32 @@
88 88 * This is a version of ip_compute_csum() optimized for IP headers,
89 89 * which always checksum on 4 octet boundaries.
90 90 */
91   -unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl)
  91 +__sum16 ip_fast_csum(const void *iph, unsigned int ihl)
92 92 {
93   - return ~do_csum(iph,ihl*4);
  93 + return (__force __sum16)~do_csum(iph,ihl*4);
94 94 }
95 95  
96 96 /*
97 97 * this routine is used for miscellaneous IP-like checksums, mainly
98 98 * in icmp.c
99 99 */
100   -unsigned short ip_compute_csum(const unsigned char * buff, int len)
  100 +__sum16 ip_compute_csum(const void *buff, int len)
101 101 {
102   - return ~do_csum(buff,len);
  102 + return (__force __sum16)~do_csum(buff,len);
103 103 }
104 104  
105 105 /*
106 106 * computes a partial checksum, e.g. for TCP/UDP fragments
107 107 */
108   -unsigned int csum_partial(const unsigned char *buff, int len, unsigned int sum)
  108 +__wsum csum_partial(const void *buff, int len, __wsum sum)
109 109 {
110 110 unsigned int result = do_csum(buff, len);
111 111  
112 112 /* add in old sum, and carry.. */
113   - result += sum;
114   - if(sum > result)
  113 + result += (__force u32)sum;
  114 + if ((__force u32)sum > result)
115 115 result += 1;
116   - return result;
  116 + return (__force __wsum)result;
117 117 }
118 118  
119 119 EXPORT_SYMBOL(csum_partial);
... ... @@ -121,8 +121,8 @@
121 121 /*
122 122 * copy while checksumming, otherwise like csum_partial
123 123 */
124   -unsigned int csum_partial_copy(const unsigned char *src, unsigned char *dst,
125   - int len, unsigned int sum)
  124 +__wsum csum_partial_copy_nocheck(const void *src, void *dst,
  125 + int len, __wsum sum)
126 126 {
127 127 /*
128 128 * It's 2:30 am and I don't feel like doing it real ...
... ... @@ -138,9 +138,9 @@
138 138 * Copy from userspace and compute checksum. If we catch an exception
139 139 * then zero the rest of the buffer.
140 140 */
141   -unsigned int csum_partial_copy_from_user (const unsigned char *src,
142   - unsigned char *dst,
143   - int len, unsigned int sum,
  141 +__wsum csum_partial_copy_from_user (const void *src,
  142 + void *dst,
  143 + int len, __wsum sum,
144 144 int *err_ptr)
145 145 {
146 146 int missing;
include/asm-v850/checksum.h
... ... @@ -26,8 +26,7 @@
26 26 *
27 27 * it's best to have buff aligned on a 32-bit boundary
28 28 */
29   -extern unsigned int csum_partial (const unsigned char * buff, int len,
30   - unsigned int sum);
  29 +extern __wsum csum_partial(const void *buff, int len, __wsum sum);
31 30  
32 31 /*
33 32 * the same as csum_partial, but copies from src while it
... ... @@ -36,8 +35,8 @@
36 35 * here even more important to align src and dst on a 32-bit (or even
37 36 * better 64-bit) boundary
38 37 */
39   -extern unsigned csum_partial_copy (const unsigned char *src,
40   - unsigned char *dst, int len, unsigned sum);
  38 +extern __wsum csum_partial_copy_nocheck(const void *src,
  39 + void *dst, int len, __wsum sum);
41 40  
42 41  
43 42 /*
44 43  
45 44  
46 45  
... ... @@ -46,20 +45,17 @@
46 45 * here even more important to align src and dst on a 32-bit (or even
47 46 * better 64-bit) boundary
48 47 */
49   -extern unsigned csum_partial_copy_from_user (const unsigned char *src,
50   - unsigned char *dst,
51   - int len, unsigned sum,
  48 +extern __wsum csum_partial_copy_from_user (const void *src,
  49 + void *dst,
  50 + int len, __wsum sum,
52 51 int *csum_err);
53 52  
54   -#define csum_partial_copy_nocheck(src, dst, len, sum) \
55   - csum_partial_copy ((src), (dst), (len), (sum))
  53 +__sum16 ip_fast_csum(const void *iph, unsigned int ihl);
56 54  
57   -unsigned short ip_fast_csum (unsigned char *iph, unsigned int ihl);
58   -
59 55 /*
60 56 * Fold a partial checksum
61 57 */
62   -static inline unsigned int csum_fold (unsigned long sum)
  58 +static inline __sum16 csum_fold (__wsum sum)
63 59 {
64 60 unsigned int result;
65 61 /*
... ... @@ -68,7 +64,7 @@
68 64 add %1, %0 H L H+L+C H+L
69 65 */
70 66 asm ("hsw %1, %0; add %1, %0" : "=&r" (result) : "r" (sum));
71   - return (~result) >> 16;
  67 + return (__force __sum16)(~result >> 16);
72 68 }
73 69  
74 70  
75 71  
... ... @@ -76,10 +72,10 @@
76 72 * computes the checksum of the TCP/UDP pseudo-header
77 73 * returns a 16-bit checksum, already complemented
78 74 */
79   -static inline unsigned int
80   -csum_tcpudp_nofold (unsigned long saddr, unsigned long daddr,
  75 +static inline __wsum
  76 +csum_tcpudp_nofold (__be32 saddr, __be32 daddr,
81 77 unsigned short len,
82   - unsigned short proto, unsigned int sum)
  78 + unsigned short proto, __wsum sum)
83 79 {
84 80 int __carry;
85 81 __asm__ ("add %2, %0;"
86 82  
87 83  
... ... @@ -93,15 +89,15 @@
93 89 "add %1, %0"
94 90 : "=&r" (sum), "=&r" (__carry)
95 91 : "r" (daddr), "r" (saddr),
96   - "r" (ntohs (len) + (proto << 8)),
  92 + "r" ((len + proto) << 8),
97 93 "0" (sum));
98 94 return sum;
99 95 }
100 96  
101   -static inline unsigned short int
102   -csum_tcpudp_magic (unsigned long saddr, unsigned long daddr,
  97 +static inline __sum16
  98 +csum_tcpudp_magic (__be32 saddr, __be32 daddr,
103 99 unsigned short len,
104   - unsigned short proto, unsigned int sum)
  100 + unsigned short proto, __wsum sum)
105 101 {
106 102 return csum_fold (csum_tcpudp_nofold (saddr, daddr, len, proto, sum));
107 103 }
... ... @@ -110,7 +106,7 @@
110 106 * this routine is used for miscellaneous IP-like checksums, mainly
111 107 * in icmp.c
112 108 */
113   -extern unsigned short ip_compute_csum (const unsigned char * buff, int len);
  109 +extern __sum16 ip_compute_csum(const void *buff, int len);
114 110  
115 111  
116 112 #endif /* __V850_CHECKSUM_H__ */