Commit c459dd90 authored by Al Viro's avatar Al Viro Committed by David S. Miller

[NET]: SH64 checksum annotations and cleanups.

* sanitize prototypes, annotate
* collapse csum_partial_copy
* kill csum_partial_copy_fromuser
* ntohs->shift in checksum calculation
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7814e4b6
...@@ -38,7 +38,7 @@ EXPORT_SYMBOL(disable_irq); ...@@ -38,7 +38,7 @@ EXPORT_SYMBOL(disable_irq);
EXPORT_SYMBOL(kernel_thread); EXPORT_SYMBOL(kernel_thread);
/* Networking helper routines. */ /* Networking helper routines. */
EXPORT_SYMBOL(csum_partial_copy); EXPORT_SYMBOL(csum_partial_copy_nocheck);
EXPORT_SYMBOL(strstr); EXPORT_SYMBOL(strstr);
......
...@@ -118,24 +118,24 @@ static unsigned long do_csum(const unsigned char *buff, int len) ...@@ -118,24 +118,24 @@ static unsigned long do_csum(const unsigned char *buff, int len)
/* computes the checksum of a memory block at buff, length len, /* computes the checksum of a memory block at buff, length len,
and adds in "sum" (32-bit) */ and adds in "sum" (32-bit) */
unsigned int csum_partial(const unsigned char *buff, int len, unsigned int sum) __wsum csum_partial(const void *buff, int len, __wsum sum)
{ {
unsigned long long result = do_csum(buff, len); unsigned long long result = do_csum(buff, len);
/* add in old sum, and carry.. */ /* add in old sum, and carry.. */
result += sum; result += (__force u32)sum;
/* 32+c bits -> 32 bits */ /* 32+c bits -> 32 bits */
result = (result & 0xffffffff) + (result >> 32); result = (result & 0xffffffff) + (result >> 32);
pr_debug("csum_partial, buff %p len %d sum 0x%x result=0x%016Lx\n", pr_debug("csum_partial, buff %p len %d sum 0x%x result=0x%016Lx\n",
buff, len, sum, result); buff, len, sum, result);
return result; return (__force __wsum)result;
} }
/* Copy while checksumming, otherwise like csum_partial. */ /* Copy while checksumming, otherwise like csum_partial. */
unsigned int __wsum
csum_partial_copy(const unsigned char *src, unsigned char *dst, int len, unsigned int sum) csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum)
{ {
sum = csum_partial(src, len, sum); sum = csum_partial(src, len, sum);
memcpy(dst, src, len); memcpy(dst, src, len);
...@@ -145,9 +145,9 @@ csum_partial_copy(const unsigned char *src, unsigned char *dst, int len, unsigne ...@@ -145,9 +145,9 @@ csum_partial_copy(const unsigned char *src, unsigned char *dst, int len, unsigne
/* Copy from userspace and compute checksum. If we catch an exception /* Copy from userspace and compute checksum. If we catch an exception
then zero the rest of the buffer. */ then zero the rest of the buffer. */
unsigned int __wsum
csum_partial_copy_from_user(const unsigned char *src, unsigned char *dst, int len, csum_partial_copy_from_user(const void __user *src, void *dst, int len,
unsigned int sum, int *err_ptr) __wsum sum, int *err_ptr)
{ {
int missing; int missing;
...@@ -166,9 +166,9 @@ csum_partial_copy_from_user(const unsigned char *src, unsigned char *dst, int le ...@@ -166,9 +166,9 @@ csum_partial_copy_from_user(const unsigned char *src, unsigned char *dst, int le
} }
/* Copy to userspace and compute checksum. */ /* Copy to userspace and compute checksum. */
unsigned int __wsum
csum_partial_copy_to_user(const unsigned char *src, unsigned char *dst, int len, csum_partial_copy_to_user(const unsigned char *src, unsigned char *dst, int len,
unsigned int sum, int *err_ptr) __wsum sum, int *err_ptr)
{ {
sum = csum_partial(src, len, sum); sum = csum_partial(src, len, sum);
...@@ -182,28 +182,24 @@ csum_partial_copy_to_user(const unsigned char *src, unsigned char *dst, int len, ...@@ -182,28 +182,24 @@ csum_partial_copy_to_user(const unsigned char *src, unsigned char *dst, int len,
* This is a version of ip_compute_csum() optimized for IP headers, * This is a version of ip_compute_csum() optimized for IP headers,
* which always checksum on 4 octet boundaries. * which always checksum on 4 octet boundaries.
*/ */
unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl) __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
{ {
pr_debug("ip_fast_csum %p,%d\n", iph, ihl); pr_debug("ip_fast_csum %p,%d\n", iph, ihl);
return ~do_csum(iph, ihl * 4); return (__force __sum16)~do_csum(iph, ihl * 4);
} }
unsigned int csum_tcpudp_nofold(unsigned long saddr, __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
unsigned long daddr,
unsigned short len, unsigned short len,
unsigned short proto, unsigned int sum) unsigned short proto, __wsum sum)
{ {
unsigned long long result; unsigned long long result;
pr_debug("ntohs(0x%x)=0x%x\n", 0xdead, ntohs(0xdead)); pr_debug("ntohs(0x%x)=0x%x\n", 0xdead, ntohs(0xdead));
pr_debug("htons(0x%x)=0x%x\n", 0xdead, htons(0xdead)); pr_debug("htons(0x%x)=0x%x\n", 0xdead, htons(0xdead));
result = ((unsigned long long) saddr + result = (__force u64) saddr + (__force u64) daddr +
(unsigned long long) daddr + (__force u64) sum + ((len + proto) << 8);
(unsigned long long) sum +
((unsigned long long) ntohs(len) << 16) +
((unsigned long long) proto << 8));
/* Fold down to 32-bits so we don't loose in the typedef-less /* Fold down to 32-bits so we don't loose in the typedef-less
network stack. */ network stack. */
...@@ -215,16 +211,5 @@ unsigned int csum_tcpudp_nofold(unsigned long saddr, ...@@ -215,16 +211,5 @@ unsigned int csum_tcpudp_nofold(unsigned long saddr,
pr_debug("%s saddr %x daddr %x len %x proto %x sum %x result %08Lx\n", pr_debug("%s saddr %x daddr %x len %x proto %x sum %x result %08Lx\n",
__FUNCTION__, saddr, daddr, len, proto, sum, result); __FUNCTION__, saddr, daddr, len, proto, sum, result);
return result; return (__wsum)result;
}
// Post SIM:
unsigned int
csum_partial_copy_nocheck(const unsigned char *src, unsigned char *dst, int len, unsigned int sum)
{
// unsigned dummy;
pr_debug("csum_partial_copy_nocheck src %p dst %p len %d\n", src, dst,
len);
return csum_partial_copy(src, dst, len, sum);
} }
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
* *
* it's best to have buff aligned on a 32-bit boundary * it's best to have buff aligned on a 32-bit boundary
*/ */
asmlinkage unsigned int csum_partial(const unsigned char *buff, int len, asmlinkage __wsum csum_partial(const void *buff, int len, __wsum sum);
unsigned int sum);
/* /*
* Note: when you get a NULL pointer exception here this means someone * Note: when you get a NULL pointer exception here this means someone
...@@ -38,46 +37,34 @@ asmlinkage unsigned int csum_partial(const unsigned char *buff, int len, ...@@ -38,46 +37,34 @@ asmlinkage unsigned int csum_partial(const unsigned char *buff, int len,
*/ */
unsigned int csum_partial_copy_nocheck(const char *src, char *dst, int len, __wsum csum_partial_copy_nocheck(const void *src, void *dst, int len,
unsigned int sum); __wsum sum);
unsigned int csum_partial_copy_from_user(const char *src, char *dst, __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
int len, int sum, int *err_ptr); int len, __wsum sum, int *err_ptr);
/* static inline __sum16 csum_fold(__wsum csum)
* These are the old (and unsafe) way of doing checksums, a warning message will be
* printed if they are used and an exeption occurs.
*
* these functions should go away after some time.
*/
#define csum_partial_copy_fromuser csum_partial_copy
unsigned int csum_partial_copy(const char *src, char *dst, int len,
unsigned int sum);
static inline unsigned short csum_fold(unsigned int sum)
{ {
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;
} }
unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl); __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
unsigned long csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr, __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
unsigned short len, unsigned short proto, unsigned short len, unsigned short proto,
unsigned int sum); __wsum sum);
/* /*
* computes the checksum of the TCP/UDP pseudo-header * computes the checksum of the TCP/UDP pseudo-header
* returns a 16-bit checksum, already complemented * returns a 16-bit checksum, already complemented
*/ */
static inline unsigned short int csum_tcpudp_magic(unsigned long saddr, static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
unsigned long daddr,
unsigned short len, unsigned short len,
unsigned short proto, unsigned short proto,
unsigned int sum) __wsum sum)
{ {
return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
} }
...@@ -86,7 +73,7 @@ static inline unsigned short int csum_tcpudp_magic(unsigned long saddr, ...@@ -86,7 +73,7 @@ static inline unsigned short int csum_tcpudp_magic(unsigned long saddr,
* 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
*/ */
static inline unsigned short ip_compute_csum(unsigned char * buff, int len) static inline __sum16 ip_compute_csum(const void *buff, int len)
{ {
return csum_fold(csum_partial(buff, len, 0)); return csum_fold(csum_partial(buff, len, 0));
} }
......
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