Skip to content

Commit

Permalink
[NET]: V850 checksum annotations and cleanups.
Browse files Browse the repository at this point in the history
* sanitize prototypes, annotate
* collapse csum_partial_copy
* usual ntohs->shift

Signed-off-by: Al Viro <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Al Viro authored and David S. Miller committed Dec 3, 2006
1 parent abf419b commit 9d3d419
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 35 deletions.
2 changes: 1 addition & 1 deletion arch/v850/kernel/v850_ksyms.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ EXPORT_SYMBOL (kernel_thread);
EXPORT_SYMBOL (__bug);

/* Networking helper routines. */
EXPORT_SYMBOL (csum_partial_copy);
EXPORT_SYMBOL (csum_partial_copy_nocheck);
EXPORT_SYMBOL (csum_partial_copy_from_user);
EXPORT_SYMBOL (ip_compute_csum);
EXPORT_SYMBOL (ip_fast_csum);
Expand Down
26 changes: 13 additions & 13 deletions arch/v850/lib/checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,41 +88,41 @@ static inline unsigned int 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);
}

/*
* 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);
}

/*
* computes a partial checksum, e.g. for TCP/UDP fragments
*/
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);

/*
* copy while checksumming, otherwise like csum_partial
*/
unsigned int csum_partial_copy(const unsigned char *src, unsigned char *dst,
int len, unsigned int sum)
__wsum csum_partial_copy_nocheck(const void *src, void *dst,
int len, __wsum sum)
{
/*
* It's 2:30 am and I don't feel like doing it real ...
Expand All @@ -138,9 +138,9 @@ unsigned int csum_partial_copy(const unsigned char *src, unsigned char *dst,
* Copy from userspace and compute checksum. If we catch an exception
* then zero the rest of the buffer.
*/
unsigned int csum_partial_copy_from_user (const unsigned char *src,
unsigned char *dst,
int len, unsigned int sum,
__wsum csum_partial_copy_from_user (const void *src,
void *dst,
int len, __wsum sum,
int *err_ptr)
{
int missing;
Expand Down
38 changes: 17 additions & 21 deletions include/asm-v850/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
*
* it's best to have buff aligned on a 32-bit boundary
*/
extern unsigned int csum_partial (const unsigned char * buff, int len,
unsigned int sum);
extern __wsum csum_partial(const void *buff, int len, __wsum sum);

/*
* the same as csum_partial, but copies from src while it
Expand All @@ -36,8 +35,8 @@ extern unsigned int csum_partial (const unsigned char * buff, int len,
* here even more important to align src and dst on a 32-bit (or even
* better 64-bit) boundary
*/
extern unsigned csum_partial_copy (const unsigned char *src,
unsigned char *dst, int len, unsigned sum);
extern __wsum csum_partial_copy_nocheck(const void *src,
void *dst, int len, __wsum sum);


/*
Expand All @@ -46,20 +45,17 @@ extern unsigned csum_partial_copy (const unsigned char *src,
* here even more important to align src and dst on a 32-bit (or even
* better 64-bit) boundary
*/
extern unsigned csum_partial_copy_from_user (const unsigned char *src,
unsigned char *dst,
int len, unsigned sum,
extern __wsum csum_partial_copy_from_user (const void *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 long sum)
static inline __sum16 csum_fold (__wsum sum)
{
unsigned int result;
/*
Expand All @@ -68,18 +64,18 @@ static inline unsigned int csum_fold (unsigned long sum)
add %1, %0 H L H+L+C H+L
*/
asm ("hsw %1, %0; add %1, %0" : "=&r" (result) : "r" (sum));
return (~result) >> 16;
return (__force __sum16)(~result >> 16);
}


/*
* computes the checksum of the TCP/UDP pseudo-header
* returns a 16-bit checksum, already complemented
*/
static inline unsigned int
csum_tcpudp_nofold (unsigned long saddr, unsigned long daddr,
static inline __wsum
csum_tcpudp_nofold (__be32 saddr, __be32 daddr,
unsigned short len,
unsigned short proto, unsigned int sum)
unsigned short proto, __wsum sum)
{
int __carry;
__asm__ ("add %2, %0;"
Expand All @@ -93,15 +89,15 @@ csum_tcpudp_nofold (unsigned long saddr, unsigned long daddr,
"add %1, %0"
: "=&r" (sum), "=&r" (__carry)
: "r" (daddr), "r" (saddr),
"r" (ntohs (len) + (proto << 8)),
"r" ((len + proto) << 8),
"0" (sum));
return sum;
}

static inline unsigned short int
csum_tcpudp_magic (unsigned long saddr, unsigned long daddr,
static inline __sum16
csum_tcpudp_magic (__be32 saddr, __be32 daddr,
unsigned short len,
unsigned short proto, unsigned int sum)
unsigned short proto, __wsum sum)
{
return csum_fold (csum_tcpudp_nofold (saddr, daddr, len, proto, sum));
}
Expand All @@ -110,7 +106,7 @@ csum_tcpudp_magic (unsigned long saddr, unsigned long daddr,
* this routine is used for miscellaneous IP-like checksums, mainly
* 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);


#endif /* __V850_CHECKSUM_H__ */

0 comments on commit 9d3d419

Please sign in to comment.