diff options
author | Arnd Bergmann <arnd@arndb.de> | 2009-03-31 09:30:31 -0400 |
---|---|---|
committer | Michal Simek <monstr@monstr.eu> | 2009-05-21 09:56:07 -0400 |
commit | 732703af9c3478c3f935dd5ae80140b9b12bda09 (patch) | |
tree | 4eba20e0ef2d98181702a5f643f2f45ab49faba1 | |
parent | 838d2406ee62595c1b40d1d03b48bc9a2102258b (diff) |
microblaze: clean up checksum.c
This changes the function prototypes in the checksum code
to have the usual prototypes, typically by turning int
arguments into __wsum.
Also change csum_partial_copy_from_user() to operate
on the right address space and export ip_fast_csum,
which is used in modular networking code.
The new version is now sparse-clean including endianess
checks.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Michal Simek <monstr@monstr.eu>
-rw-r--r-- | arch/microblaze/include/asm/checksum.h | 14 | ||||
-rw-r--r-- | arch/microblaze/lib/checksum.c | 31 |
2 files changed, 28 insertions, 17 deletions
diff --git a/arch/microblaze/include/asm/checksum.h b/arch/microblaze/include/asm/checksum.h index 92b30762ce59..97ea46b5cf80 100644 --- a/arch/microblaze/include/asm/checksum.h +++ b/arch/microblaze/include/asm/checksum.h | |||
@@ -51,7 +51,8 @@ extern __wsum csum_partial(const void *buff, int len, __wsum sum); | |||
51 | * here even more important to align src and dst on a 32-bit (or even | 51 | * here even more important to align src and dst on a 32-bit (or even |
52 | * better 64-bit) boundary | 52 | * better 64-bit) boundary |
53 | */ | 53 | */ |
54 | extern __wsum csum_partial_copy(const char *src, char *dst, int len, int sum); | 54 | extern __wsum csum_partial_copy(const void *src, void *dst, int len, |
55 | __wsum sum); | ||
55 | 56 | ||
56 | /* | 57 | /* |
57 | * the same as csum_partial_copy, but copies from user space. | 58 | * the same as csum_partial_copy, but copies from user space. |
@@ -59,8 +60,8 @@ extern __wsum csum_partial_copy(const char *src, char *dst, int len, int sum); | |||
59 | * here even more important to align src and dst on a 32-bit (or even | 60 | * here even more important to align src and dst on a 32-bit (or even |
60 | * better 64-bit) boundary | 61 | * better 64-bit) boundary |
61 | */ | 62 | */ |
62 | extern __wsum csum_partial_copy_from_user(const char *src, char *dst, | 63 | extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst, |
63 | int len, int sum, int *csum_err); | 64 | int len, __wsum sum, int *csum_err); |
64 | 65 | ||
65 | #define csum_partial_copy_nocheck(src, dst, len, sum) \ | 66 | #define csum_partial_copy_nocheck(src, dst, len, sum) \ |
66 | csum_partial_copy((src), (dst), (len), (sum)) | 67 | csum_partial_copy((src), (dst), (len), (sum)) |
@@ -75,11 +76,12 @@ extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl); | |||
75 | /* | 76 | /* |
76 | * Fold a partial checksum | 77 | * Fold a partial checksum |
77 | */ | 78 | */ |
78 | static inline __sum16 csum_fold(unsigned int sum) | 79 | static inline __sum16 csum_fold(__wsum csum) |
79 | { | 80 | { |
81 | u32 sum = (__force u32)csum; | ||
80 | sum = (sum & 0xffff) + (sum >> 16); | 82 | sum = (sum & 0xffff) + (sum >> 16); |
81 | sum = (sum & 0xffff) + (sum >> 16); | 83 | sum = (sum & 0xffff) + (sum >> 16); |
82 | return ~sum; | 84 | return (__force __sum16)~sum; |
83 | } | 85 | } |
84 | 86 | ||
85 | static inline __sum16 | 87 | static inline __sum16 |
@@ -93,6 +95,6 @@ csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len, | |||
93 | * this routine is used for miscellaneous IP-like checksums, mainly | 95 | * this routine is used for miscellaneous IP-like checksums, mainly |
94 | * in icmp.c | 96 | * in icmp.c |
95 | */ | 97 | */ |
96 | extern __sum16 ip_compute_csum(const unsigned char *buff, int len); | 98 | extern __sum16 ip_compute_csum(const void *buff, int len); |
97 | 99 | ||
98 | #endif /* _ASM_MICROBLAZE_CHECKSUM_H */ | 100 | #endif /* _ASM_MICROBLAZE_CHECKSUM_H */ |
diff --git a/arch/microblaze/lib/checksum.c b/arch/microblaze/lib/checksum.c index 809340070a13..f08e74591418 100644 --- a/arch/microblaze/lib/checksum.c +++ b/arch/microblaze/lib/checksum.c | |||
@@ -32,9 +32,10 @@ | |||
32 | /* Revised by Kenneth Albanowski for m68knommu. Basic problem: unaligned access | 32 | /* Revised by Kenneth Albanowski for m68knommu. Basic problem: unaligned access |
33 | kills, so most of the assembly has to go. */ | 33 | kills, so most of the assembly has to go. */ |
34 | 34 | ||
35 | #include <net/checksum.h> | ||
36 | #include <asm/checksum.h> | ||
37 | #include <linux/module.h> | 35 | #include <linux/module.h> |
36 | #include <net/checksum.h> | ||
37 | |||
38 | #include <asm/byteorder.h> | ||
38 | 39 | ||
39 | static inline unsigned short from32to16(unsigned long x) | 40 | static inline unsigned short from32to16(unsigned long x) |
40 | { | 41 | { |
@@ -102,6 +103,7 @@ __sum16 ip_fast_csum(const void *iph, unsigned int ihl) | |||
102 | { | 103 | { |
103 | return (__force __sum16)~do_csum(iph, ihl*4); | 104 | return (__force __sum16)~do_csum(iph, ihl*4); |
104 | } | 105 | } |
106 | EXPORT_SYMBOL(ip_fast_csum); | ||
105 | 107 | ||
106 | /* | 108 | /* |
107 | * computes the checksum of a memory block at buff, length len, | 109 | * computes the checksum of a memory block at buff, length len, |
@@ -115,15 +117,16 @@ __sum16 ip_fast_csum(const void *iph, unsigned int ihl) | |||
115 | * | 117 | * |
116 | * it's best to have buff aligned on a 32-bit boundary | 118 | * it's best to have buff aligned on a 32-bit boundary |
117 | */ | 119 | */ |
118 | __wsum csum_partial(const void *buff, int len, __wsum sum) | 120 | __wsum csum_partial(const void *buff, int len, __wsum wsum) |
119 | { | 121 | { |
122 | unsigned int sum = (__force unsigned int)wsum; | ||
120 | unsigned int result = do_csum(buff, len); | 123 | unsigned int result = do_csum(buff, len); |
121 | 124 | ||
122 | /* add in old sum, and carry.. */ | 125 | /* add in old sum, and carry.. */ |
123 | result += sum; | 126 | result += sum; |
124 | if (sum > result) | 127 | if (sum > result) |
125 | result += 1; | 128 | result += 1; |
126 | return result; | 129 | return (__force __wsum)result; |
127 | } | 130 | } |
128 | EXPORT_SYMBOL(csum_partial); | 131 | EXPORT_SYMBOL(csum_partial); |
129 | 132 | ||
@@ -131,9 +134,9 @@ EXPORT_SYMBOL(csum_partial); | |||
131 | * this routine is used for miscellaneous IP-like checksums, mainly | 134 | * this routine is used for miscellaneous IP-like checksums, mainly |
132 | * in icmp.c | 135 | * in icmp.c |
133 | */ | 136 | */ |
134 | __sum16 ip_compute_csum(const unsigned char *buff, int len) | 137 | __sum16 ip_compute_csum(const void *buff, int len) |
135 | { | 138 | { |
136 | return ~do_csum(buff, len); | 139 | return (__force __sum16)~do_csum(buff, len); |
137 | } | 140 | } |
138 | EXPORT_SYMBOL(ip_compute_csum); | 141 | EXPORT_SYMBOL(ip_compute_csum); |
139 | 142 | ||
@@ -141,12 +144,18 @@ EXPORT_SYMBOL(ip_compute_csum); | |||
141 | * copy from fs while checksumming, otherwise like csum_partial | 144 | * copy from fs while checksumming, otherwise like csum_partial |
142 | */ | 145 | */ |
143 | __wsum | 146 | __wsum |
144 | csum_partial_copy_from_user(const char __user *src, char *dst, int len, | 147 | csum_partial_copy_from_user(const void __user *src, void *dst, int len, |
145 | int sum, int *csum_err) | 148 | __wsum sum, int *csum_err) |
146 | { | 149 | { |
147 | if (csum_err) | 150 | int missing; |
151 | |||
152 | missing = __copy_from_user(dst, src, len); | ||
153 | if (missing) { | ||
154 | memset(dst + len - missing, 0, missing); | ||
155 | *csum_err = -EFAULT; | ||
156 | } else | ||
148 | *csum_err = 0; | 157 | *csum_err = 0; |
149 | memcpy(dst, src, len); | 158 | |
150 | return csum_partial(dst, len, sum); | 159 | return csum_partial(dst, len, sum); |
151 | } | 160 | } |
152 | EXPORT_SYMBOL(csum_partial_copy_from_user); | 161 | EXPORT_SYMBOL(csum_partial_copy_from_user); |
@@ -155,7 +164,7 @@ EXPORT_SYMBOL(csum_partial_copy_from_user); | |||
155 | * copy from ds while checksumming, otherwise like csum_partial | 164 | * copy from ds while checksumming, otherwise like csum_partial |
156 | */ | 165 | */ |
157 | __wsum | 166 | __wsum |
158 | csum_partial_copy(const char *src, char *dst, int len, int sum) | 167 | csum_partial_copy(const void *src, void *dst, int len, __wsum sum) |
159 | { | 168 | { |
160 | memcpy(dst, src, len); | 169 | memcpy(dst, src, len); |
161 | return csum_partial(dst, len, sum); | 170 | return csum_partial(dst, len, sum); |