Commit c693cc46 authored by Al Viro's avatar Al Viro
Browse files

saner calling conventions for csum_and_copy_..._user()



All callers of these primitives will
	* discard anything we might've copied in case of error
	* ignore the csum value in case of error
	* always pass 0xffffffff as the initial sum, so the
resulting csum value (in case of success, that is) will never be 0.

That suggest the following calling conventions:
	* don't pass err_ptr - just return 0 on error.
	* don't bother with zeroing destination, etc. in case of error
	* don't pass the initial sum - just use 0xffffffff.

This commit does the minimal conversion in the instances of csum_and_copy_...();
the changes of actual asm code behind them are done later in the series.
Note that this asm code is often shared with csum_partial_copy_nocheck();
the difference is that csum_partial_copy_nocheck() passes 0 for initial
sum while csum_and_copy_..._user() pass 0xffffffff.  Fortunately, we are
free to pass 0xffffffff in all cases and subsequent patches will use that
freedom without any special comments.

A part that could be split off: parisc and uml/i386 claimed to have
csum_and_copy_to_user() instances of their own, but those were identical
to the generic one, so we simply drop them.  Not sure if it's worth
a separate commit...

Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 99a2c96d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ extern __wsum csum_partial(const void *buff, int len, __wsum sum);
 */
#define _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
#define _HAVE_ARCH_CSUM_AND_COPY
__wsum csum_and_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *errp);
__wsum csum_and_copy_from_user(const void __user *src, void *dst, int len);

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

+11 −14
Original line number Diff line number Diff line
@@ -325,30 +325,27 @@ csum_partial_cfu_unaligned(const unsigned long __user * src,
}

__wsum
csum_and_copy_from_user(const void __user *src, void *dst, int len,
			       __wsum sum, int *errp)
csum_and_copy_from_user(const void __user *src, void *dst, int len)
{
	unsigned long checksum = (__force u32) sum;
	unsigned long checksum = ~0U;
	unsigned long soff = 7 & (unsigned long) src;
	unsigned long doff = 7 & (unsigned long) dst;
	int err = 0;

	if (len) {
		if (!access_ok(src, len)) {
			if (errp) *errp = -EFAULT;
			memset(dst, 0, len);
			return sum;
		}
		if (!access_ok(src, len))
			return 0;
		if (!doff) {
			if (!soff)
				checksum = csum_partial_cfu_aligned(
					(const unsigned long __user *) src,
					(unsigned long *) dst,
					len-8, checksum, errp);
					len-8, checksum, &err);
			else
				checksum = csum_partial_cfu_dest_aligned(
					(const unsigned long __user *) src,
					(unsigned long *) dst,
					soff, len-8, checksum, errp);
					soff, len-8, checksum, &err);
		} else {
			unsigned long partial_dest;
			ldq_u(partial_dest, dst);
@@ -357,15 +354,15 @@ csum_and_copy_from_user(const void __user *src, void *dst, int len,
					(const unsigned long __user *) src,
					(unsigned long *) dst,
					doff, len-8, checksum,
					partial_dest, errp);
					partial_dest, &err);
			else
				checksum = csum_partial_cfu_unaligned(
					(const unsigned long __user *) src,
					(unsigned long *) dst,
					soff, doff, len-8, checksum,
					partial_dest, errp);
					partial_dest, &err);
		}
		checksum = from64to16 (checksum);
		checksum = err ? 0 : from64to16 (checksum);
	}
	return (__force __wsum)checksum;
}
@@ -378,7 +375,7 @@ csum_partial_copy_nocheck(const void *src, void *dst, int len)
	mm_segment_t oldfs = get_fs();
	set_fs(KERNEL_DS);
	checksum = csum_and_copy_from_user((__force const void __user *)src,
						dst, len, 0, NULL);
						dst, len);
	set_fs(oldfs);
	return checksum;
}
+6 −7
Original line number Diff line number Diff line
@@ -43,16 +43,15 @@ csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum s
#define _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
#define _HAVE_ARCH_CSUM_AND_COPY
static inline
__wsum csum_and_copy_from_user (const void __user *src, void *dst,
				      int len, __wsum sum, int *err_ptr)
__wsum csum_and_copy_from_user(const void __user *src, void *dst, int len)
{
	if (access_ok(src, len))
		return csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
	int err = 0;

	if (len)
		*err_ptr = -EFAULT;
	if (!access_ok(src, len))
		return 0;

	return sum;
	sum = csum_partial_copy_from_user(src, dst, len, ~0U, &err);
	return err ? 0 : sum;
}

/*
+1 −2
Original line number Diff line number Diff line
@@ -34,8 +34,7 @@ __wsum csum_partial(const void *buff, int len, __wsum sum);
#define _HAVE_ARCH_CSUM_AND_COPY
extern __wsum csum_and_copy_from_user(const void __user *src,
						void *dst,
						int len, __wsum sum,
						int *csum_err);
						int len);

extern __wsum csum_partial_copy_nocheck(const void *src,
					      void *dst, int len);
+3 −5
Original line number Diff line number Diff line
@@ -129,8 +129,7 @@ EXPORT_SYMBOL(csum_partial);
 */

__wsum
csum_and_copy_from_user(const void __user *src, void *dst,
			    int len, __wsum sum, int *csum_err)
csum_and_copy_from_user(const void __user *src, void *dst, int len)
{
	/*
	 * GCC doesn't like more than 10 operands for the asm
@@ -138,6 +137,7 @@ csum_and_copy_from_user(const void __user *src, void *dst,
	 * code.
	 */
	unsigned long tmp1, tmp2;
	__wsum sum = ~0U;

	__asm__("movel %2,%4\n\t"
		"btst #1,%4\n\t"	/* Check alignment */
@@ -311,9 +311,7 @@ csum_and_copy_from_user(const void __user *src, void *dst,
		: "0" (sum), "1" (len), "2" (src), "3" (dst)
	    );

	*csum_err = tmp2;

	return(sum);
	return tmp2 ? 0 : sum;
}

EXPORT_SYMBOL(csum_and_copy_from_user);
Loading