Skip to content

Commit

Permalink
[NET]: M68Knommu checksum annotations and cleanups.
Browse files Browse the repository at this point in the history
* sanitize prototypes, annotated
* collapsed csum_partial_copy()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Al Viro authored and David S. Miller committed Dec 3, 2006
1 parent 2061aca commit 59ed05a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
2 changes: 1 addition & 1 deletion arch/m68knommu/kernel/m68k_ksyms.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ EXPORT_SYMBOL(ip_fast_csum);
EXPORT_SYMBOL(kernel_thread);

/* Networking helper routines. */
EXPORT_SYMBOL(csum_partial_copy);
EXPORT_SYMBOL(csum_partial_copy_nocheck);

/* The following are special because they're not called
explicitly (the C compiler generates them). Fortunately,
Expand Down
28 changes: 14 additions & 14 deletions arch/m68knommu/lib/checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ static unsigned long do_csum(const unsigned char * buff, int len)
* This is a version of ip_compute_csum() optimized for IP headers,
* 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)
{
return ~do_csum(iph,ihl*4);
return (__force __sum16)~do_csum(iph,ihl*4);
}

/*
Expand All @@ -113,15 +113,15 @@ unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl)
*
* it's best to have buff aligned on a 32-bit boundary
*/
unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum)
__wsum csum_partial(const void *buff, int len, __wsum sum)
{
unsigned int result = do_csum(buff, len);

/* add in old sum, and carry.. */
result += sum;
if (sum > result)
result += (__force u32)sum;
if ((__force u32)sum > result)
result += 1;
return result;
return (__force __wsum)result;
}

EXPORT_SYMBOL(csum_partial);
Expand All @@ -130,30 +130,30 @@ EXPORT_SYMBOL(csum_partial);
* this routine is used for miscellaneous IP-like checksums, mainly
* in icmp.c
*/
unsigned short 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);
}

/*
* copy from fs while checksumming, otherwise like csum_partial
*/

unsigned int
csum_partial_copy_from_user(const unsigned char *src, unsigned char *dst,
int len, int sum, int *csum_err)
__wsum
csum_partial_copy_from_user(const void __user *src, void *dst,
int len, __wsum sum, int *csum_err)
{
if (csum_err) *csum_err = 0;
memcpy(dst, src, len);
memcpy(dst, (__force const void *)src, len);
return csum_partial(dst, len, sum);
}

/*
* copy from ds while checksumming, otherwise like csum_partial
*/

unsigned int
csum_partial_copy(const unsigned char *src, unsigned char *dst, int len, int sum)
__wsum
csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum)
{
memcpy(dst, src, len);
return csum_partial(dst, len, sum);
Expand Down
46 changes: 22 additions & 24 deletions include/asm-m68knommu/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* it's best to have buff aligned on a 32-bit boundary
*/
unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum);
__wsum csum_partial(const void *buff, int len, __wsum sum);

/*
* the same as csum_partial, but copies from src while it
Expand All @@ -25,8 +25,8 @@ unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum)
* better 64-bit) boundary
*/

unsigned int csum_partial_copy(const unsigned char *src, unsigned char *dst,
int len, int sum);
__wsum csum_partial_copy_nocheck(const void *src, void *dst,
int len, __wsum sum);


/*
Expand All @@ -36,33 +36,31 @@ unsigned int csum_partial_copy(const unsigned char *src, unsigned char *dst,
* better 64-bit) boundary
*/

extern unsigned int csum_partial_copy_from_user(const unsigned char *src,
unsigned char *dst, int len, int sum, int *csum_err);
extern __wsum csum_partial_copy_from_user(const void __user *src,
void *dst, int len, __wsum sum, int *csum_err);

#define csum_partial_copy_nocheck(src, dst, len, sum) \
csum_partial_copy((src), (dst), (len), (sum))

unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl);
__sum16 ip_fast_csum(const void *iph, unsigned int ihl);

/*
* Fold a partial checksum
*/

static inline unsigned int csum_fold(unsigned int sum)
static inline __sum16 csum_fold(__wsum sum)
{
unsigned int tmp = (__force u32)sum;
#ifdef CONFIG_COLDFIRE
sum = (sum & 0xffff) + (sum >> 16);
sum = (sum & 0xffff) + (sum >> 16);
tmp = (tmp & 0xffff) + (tmp >> 16);
tmp = (tmp & 0xffff) + (tmp >> 16);
return (__force __sum16)~tmp;
#else
unsigned int tmp = sum;
__asm__("swap %1\n\t"
"addw %1, %0\n\t"
"clrw %1\n\t"
"addxw %1, %0"
: "=&d" (sum), "=&d" (tmp)
: "0" (sum), "1" (sum));
return (__force __sum16)~sum;
#endif
return ~sum;
}


Expand All @@ -71,9 +69,9 @@ static inline unsigned int csum_fold(unsigned int sum)
* returns a 16-bit checksum, already complemented
*/

static inline unsigned int
csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr, unsigned short len,
unsigned short proto, unsigned int sum)
static inline __wsum
csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,
unsigned short proto, __wsum sum)
{
__asm__ ("addl %1,%0\n\t"
"addxl %4,%0\n\t"
Expand All @@ -86,9 +84,9 @@ csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr, unsigned short len,
return sum;
}

static inline unsigned short int
csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len,
unsigned short proto, unsigned int sum)
static inline __sum16
csum_tcpudp_magic(__be32 saddr, __be32 daddr, unsigned short len,
unsigned short proto, __wsum sum)
{
return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
}
Expand All @@ -98,12 +96,12 @@ csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len,
* in icmp.c
*/

extern unsigned short ip_compute_csum(const unsigned char * buff, int len);
extern __sum16 ip_compute_csum(const void *buff, int len);

#define _HAVE_ARCH_IPV6_CSUM
static __inline__ unsigned short int
csum_ipv6_magic(struct in6_addr *saddr, struct in6_addr *daddr,
__u32 len, unsigned short proto, unsigned int sum)
static __inline__ __sum16
csum_ipv6_magic(const struct in6_addr *saddr, const struct in6_addr *daddr,
__u32 len, unsigned short proto, __wsum sum)
{
register unsigned long tmp;
__asm__("addl %2@,%0\n\t"
Expand Down

0 comments on commit 59ed05a

Please sign in to comment.