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 /arch/microblaze/lib | |
| 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>
Diffstat (limited to 'arch/microblaze/lib')
| -rw-r--r-- | arch/microblaze/lib/checksum.c | 31 |
1 files changed, 20 insertions, 11 deletions
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); |
