Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/shaggy...
[pandora-kernel.git] / arch / mips / lib / csum_partial_copy.c
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1994, 1995 Waldorf Electronics GmbH
7  * Copyright (C) 1998, 1999 Ralf Baechle
8  */
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <asm/byteorder.h>
13 #include <asm/string.h>
14 #include <asm/uaccess.h>
15 #include <net/checksum.h>
16
17 /*
18  * copy while checksumming, otherwise like csum_partial
19  */
20 __wsum csum_partial_copy_nocheck(const void *src,
21         void *dst, int len, __wsum sum)
22 {
23         /*
24          * It's 2:30 am and I don't feel like doing it real ...
25          * This is lots slower than the real thing (tm)
26          */
27         sum = csum_partial(src, len, sum);
28         memcpy(dst, src, len);
29
30         return sum;
31 }
32
33 EXPORT_SYMBOL(csum_partial_copy_nocheck);
34
35 /*
36  * Copy from userspace and compute checksum.  If we catch an exception
37  * then zero the rest of the buffer.
38  */
39 __wsum csum_partial_copy_from_user (const void __user *src,
40         void *dst, int len, __wsum sum, int *err_ptr)
41 {
42         int missing;
43
44         might_sleep();
45         missing = copy_from_user(dst, src, len);
46         if (missing) {
47                 memset(dst + len - missing, 0, missing);
48                 *err_ptr = -EFAULT;
49         }
50
51         return csum_partial(dst, len, sum);
52 }