Skip to content

Commit

Permalink
take the dummy csum_and_copy_from_user() into net/checksum.h
Browse files Browse the repository at this point in the history
now that can be done conveniently - all non-trivial cases have
_HAVE_ARCH_COPY_AND_CSUM_FROM_USER defined, so the fallback in
net/checksum.h is used only for dummy (copy_from_user, then
csum_partial) implementation.  Allowing us to get rid of all
dummy instances, both of csum_and_copy_from_user() and
csum_partial_copy_from_user().

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed May 29, 2020
1 parent 24f9aa9 commit 5904122
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 149 deletions.
22 changes: 0 additions & 22 deletions arch/c6x/lib/checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,6 @@
#include <linux/module.h>
#include <net/checksum.h>

#include <asm/byteorder.h>

/*
* copy from fs while checksumming, otherwise like csum_partial
*/
__wsum
csum_partial_copy_from_user(const void __user *src, void *dst, int len,
__wsum sum, int *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;

return csum_partial(dst, len, sum);
}
EXPORT_SYMBOL(csum_partial_copy_from_user);

/* These are from csum_64plus.S */
EXPORT_SYMBOL(csum_partial);
EXPORT_SYMBOL(csum_partial_copy);
Expand Down
11 changes: 0 additions & 11 deletions arch/ia64/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ extern __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
*/
extern __wsum csum_partial(const void *buff, int len, __wsum sum);

#define _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
/*
* Same as csum_partial, but copies from src while it checksums.
*
* Here it is even more important to align src and dst on a 32-bit (or
* even better 64-bit) boundary.
*/
extern __wsum csum_and_copy_from_user(const void __user *src, void *dst,
int len, __wsum sum,
int *errp);

extern __wsum csum_partial_copy_nocheck(const void *src, void *dst,
int len, __wsum sum);

Expand Down
18 changes: 0 additions & 18 deletions arch/ia64/lib/csum_partial_copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,6 @@ unsigned long do_csum_c(const unsigned char * buff, int len, unsigned int psum)
* This is very ugly but temporary. THIS NEEDS SERIOUS ENHANCEMENTS.
* But it's very tricky to get right even in C.
*/
__wsum
csum_and_copy_from_user(const void __user *src, void *dst,
int len, __wsum psum, int *errp)
{
/* XXX Fixme
* for now we separate the copy from checksum for obvious
* alignment difficulties. Look at the Alpha code and you'll be
* scared.
*/

if (copy_from_user(dst, src, len))
*errp = -EFAULT;

return csum_partial(dst, len, psum);
}

EXPORT_SYMBOL(csum_and_copy_from_user);

__wsum
csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum)
{
Expand Down
2 changes: 0 additions & 2 deletions arch/nios2/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
extern __wsum csum_partial(const void *buff, int len, __wsum sum);
extern __wsum csum_partial_copy(const void *src, void *dst, int len,
__wsum sum);
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))

Expand Down
8 changes: 0 additions & 8 deletions arch/parisc/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ extern __wsum csum_partial(const void *, int, __wsum);
*/
extern __wsum csum_partial_copy_nocheck(const void *, void *, int, __wsum);

#define _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
/*
* this is a new version of the above that records errors it finds in *errp,
* but continues and zeros the rest of the buffer.
*/
extern __wsum csum_and_copy_from_user(const void __user *src,
void *dst, int len, __wsum sum, int *errp);

/*
* Optimized for IP headers, which always checksum on 4 octet boundaries.
*
Expand Down
14 changes: 0 additions & 14 deletions arch/parisc/lib/checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,3 @@ __wsum csum_partial_copy_nocheck(const void *src, void *dst,
return sum;
}
EXPORT_SYMBOL(csum_partial_copy_nocheck);

/*
* Copy from userspace and compute checksum. If we catch an exception
* then zero the rest of the buffer.
*/
__wsum csum_and_copy_from_user(const void __user *src,
void *dst, int len,
__wsum sum, int *err_ptr)
{
if (copy_from_user(dst, src, len))
*err_ptr = -EFAULT;
return csum_partial(dst, len, sum);
}
EXPORT_SYMBOL(csum_and_copy_from_user);
19 changes: 0 additions & 19 deletions arch/s390/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,6 @@ csum_partial(const void *buff, int len, __wsum sum)
return sum;
}

/*
* the same as csum_partial_copy, but copies from user space.
*
* here even more important to align src and dst on a 32-bit (or even
* better 64-bit) boundary
*
* Copy from userspace and compute checksum.
*/
static inline __wsum
csum_partial_copy_from_user(const void __user *src, void *dst,
int len, __wsum sum,
int *err_ptr)
{
if (unlikely(copy_from_user(dst, src, len)))
*err_ptr = -EFAULT;
return csum_partial(dst, len, sum);
}


static inline __wsum
csum_partial_copy_nocheck (const void *src, void *dst, int len, __wsum sum)
{
Expand Down
20 changes: 0 additions & 20 deletions arch/x86/um/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,6 @@ __wsum csum_partial_copy_nocheck(const void *src, void *dst,
return csum_partial(dst, len, sum);
}

/*
* the same as csum_partial, but copies from src while it
* checksums, and handles user-space pointer exceptions correctly, when needed.
*
* here even more important to align src and dst on a 32-bit (or even
* better 64-bit) boundary
*/

static __inline__
__wsum csum_partial_copy_from_user(const void __user *src, void *dst,
int len, __wsum sum, int *err_ptr)
{
if (copy_from_user(dst, src, len)) {
*err_ptr = -EFAULT;
return (__force __wsum)-1;
}

return csum_partial(dst, len, sum);
}

/**
* csum_fold - Fold and invert a 32bit checksum.
* sum: 32bit unfolded sum
Expand Down
9 changes: 0 additions & 9 deletions include/asm-generic/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ extern __wsum csum_partial(const void *buff, int len, __wsum 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.
*
* here even more important to align src and dst on a 32-bit (or even
* better 64-bit) boundary
*/
extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
int len, __wsum sum, int *csum_err);

#ifndef csum_partial_copy_nocheck
#define csum_partial_copy_nocheck(src, dst, len, sum) \
csum_partial_copy((src), (dst), (len), (sum))
Expand Down
8 changes: 2 additions & 6 deletions include/net/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ static inline
__wsum csum_and_copy_from_user (const void __user *src, void *dst,
int len, __wsum sum, int *err_ptr)
{
if (access_ok(src, len))
return csum_partial_copy_from_user(src, dst, len, sum, err_ptr);

if (len)
if (copy_from_user(dst, src, len))
*err_ptr = -EFAULT;

return sum;
return csum_partial(dst, len, sum);
}
#endif

Expand Down
20 changes: 0 additions & 20 deletions lib/checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,26 +145,6 @@ __sum16 ip_compute_csum(const void *buff, int len)
}
EXPORT_SYMBOL(ip_compute_csum);

/*
* copy from fs while checksumming, otherwise like csum_partial
*/
__wsum
csum_partial_copy_from_user(const void __user *src, void *dst, int len,
__wsum sum, int *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;

return csum_partial(dst, len, sum);
}
EXPORT_SYMBOL(csum_partial_copy_from_user);

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

0 comments on commit 5904122

Please sign in to comment.