Commit 732703af authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Michal Simek

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: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarMichal Simek <monstr@monstr.eu>
parent 838d2406
...@@ -51,7 +51,8 @@ extern __wsum csum_partial(const void *buff, int len, __wsum sum); ...@@ -51,7 +51,8 @@ extern __wsum csum_partial(const void *buff, int len, __wsum sum);
* here even more important to align src and dst on a 32-bit (or even * here even more important to align src and dst on a 32-bit (or even
* better 64-bit) boundary * better 64-bit) boundary
*/ */
extern __wsum csum_partial_copy(const char *src, char *dst, int len, int sum); extern __wsum csum_partial_copy(const void *src, void *dst, int len,
__wsum sum);
/* /*
* the same as csum_partial_copy, but copies from user space. * 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,8 +60,8 @@ extern __wsum csum_partial_copy(const char *src, char *dst, int len, int sum);
* here even more important to align src and dst on a 32-bit (or even * here even more important to align src and dst on a 32-bit (or even
* better 64-bit) boundary * better 64-bit) boundary
*/ */
extern __wsum csum_partial_copy_from_user(const char *src, char *dst, extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
int len, int sum, int *csum_err); int len, __wsum sum, int *csum_err);
#define csum_partial_copy_nocheck(src, dst, len, sum) \ #define csum_partial_copy_nocheck(src, dst, len, sum) \
csum_partial_copy((src), (dst), (len), (sum)) csum_partial_copy((src), (dst), (len), (sum))
...@@ -75,11 +76,12 @@ extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl); ...@@ -75,11 +76,12 @@ extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
/* /*
* Fold a partial checksum * Fold a partial checksum
*/ */
static inline __sum16 csum_fold(unsigned int sum) static inline __sum16 csum_fold(__wsum csum)
{ {
u32 sum = (__force u32)csum;
sum = (sum & 0xffff) + (sum >> 16); sum = (sum & 0xffff) + (sum >> 16);
sum = (sum & 0xffff) + (sum >> 16); sum = (sum & 0xffff) + (sum >> 16);
return ~sum; return (__force __sum16)~sum;
} }
static inline __sum16 static inline __sum16
...@@ -93,6 +95,6 @@ csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len, ...@@ -93,6 +95,6 @@ csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len,
* this routine is used for miscellaneous IP-like checksums, mainly * this routine is used for miscellaneous IP-like checksums, mainly
* in icmp.c * in icmp.c
*/ */
extern __sum16 ip_compute_csum(const unsigned char *buff, int len); extern __sum16 ip_compute_csum(const void *buff, int len);
#endif /* _ASM_MICROBLAZE_CHECKSUM_H */ #endif /* _ASM_MICROBLAZE_CHECKSUM_H */
...@@ -32,9 +32,10 @@ ...@@ -32,9 +32,10 @@
/* Revised by Kenneth Albanowski for m68knommu. Basic problem: unaligned access /* Revised by Kenneth Albanowski for m68knommu. Basic problem: unaligned access
kills, so most of the assembly has to go. */ kills, so most of the assembly has to go. */
#include <net/checksum.h>
#include <asm/checksum.h>
#include <linux/module.h> #include <linux/module.h>
#include <net/checksum.h>
#include <asm/byteorder.h>
static inline unsigned short from32to16(unsigned long x) static inline unsigned short from32to16(unsigned long x)
{ {
...@@ -102,6 +103,7 @@ __sum16 ip_fast_csum(const void *iph, unsigned int ihl) ...@@ -102,6 +103,7 @@ __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
{ {
return (__force __sum16)~do_csum(iph, ihl*4); return (__force __sum16)~do_csum(iph, ihl*4);
} }
EXPORT_SYMBOL(ip_fast_csum);
/* /*
* computes the checksum of a memory block at buff, length len, * 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,15 +117,16 @@ __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
* *
* it's best to have buff aligned on a 32-bit boundary * it's best to have buff aligned on a 32-bit boundary
*/ */
__wsum csum_partial(const void *buff, int len, __wsum sum) __wsum csum_partial(const void *buff, int len, __wsum wsum)
{ {
unsigned int sum = (__force unsigned int)wsum;
unsigned int result = do_csum(buff, len); unsigned int result = do_csum(buff, len);
/* add in old sum, and carry.. */ /* add in old sum, and carry.. */
result += sum; result += sum;
if (sum > result) if (sum > result)
result += 1; result += 1;
return result; return (__force __wsum)result;
} }
EXPORT_SYMBOL(csum_partial); EXPORT_SYMBOL(csum_partial);
...@@ -131,9 +134,9 @@ EXPORT_SYMBOL(csum_partial); ...@@ -131,9 +134,9 @@ EXPORT_SYMBOL(csum_partial);
* this routine is used for miscellaneous IP-like checksums, mainly * this routine is used for miscellaneous IP-like checksums, mainly
* in icmp.c * in icmp.c
*/ */
__sum16 ip_compute_csum(const unsigned char *buff, int len) __sum16 ip_compute_csum(const void *buff, int len)
{ {
return ~do_csum(buff, len); return (__force __sum16)~do_csum(buff, len);
} }
EXPORT_SYMBOL(ip_compute_csum); EXPORT_SYMBOL(ip_compute_csum);
...@@ -141,12 +144,18 @@ EXPORT_SYMBOL(ip_compute_csum); ...@@ -141,12 +144,18 @@ EXPORT_SYMBOL(ip_compute_csum);
* copy from fs while checksumming, otherwise like csum_partial * copy from fs while checksumming, otherwise like csum_partial
*/ */
__wsum __wsum
csum_partial_copy_from_user(const char __user *src, char *dst, int len, csum_partial_copy_from_user(const void __user *src, void *dst, int len,
int sum, int *csum_err) __wsum sum, int *csum_err)
{ {
if (csum_err) int missing;
missing = __copy_from_user(dst, src, len);
if (missing) {
memset(dst + len - missing, 0, missing);
*csum_err = -EFAULT;
} else
*csum_err = 0; *csum_err = 0;
memcpy(dst, src, len);
return csum_partial(dst, len, sum); return csum_partial(dst, len, sum);
} }
EXPORT_SYMBOL(csum_partial_copy_from_user); EXPORT_SYMBOL(csum_partial_copy_from_user);
...@@ -155,7 +164,7 @@ EXPORT_SYMBOL(csum_partial_copy_from_user); ...@@ -155,7 +164,7 @@ EXPORT_SYMBOL(csum_partial_copy_from_user);
* copy from ds while checksumming, otherwise like csum_partial * copy from ds while checksumming, otherwise like csum_partial
*/ */
__wsum __wsum
csum_partial_copy(const char *src, char *dst, int len, int sum) csum_partial_copy(const void *src, void *dst, int len, __wsum sum)
{ {
memcpy(dst, src, len); memcpy(dst, src, len);
return csum_partial(dst, len, sum); return csum_partial(dst, len, sum);
......
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