import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / arch / mips / lib / csum_partial_copy.c
1 /*
2  * INET         An implementation of the TCP/IP protocol suite for the LINUX
3  *              operating system.  INET is implemented using the  BSD Socket
4  *              interface as the means of communication with the user level.
5  *
6  *              MIPS specific IP/TCP/UDP checksumming routines
7  *
8  * Authors:     Ralf Baechle, <ralf@waldorf-gmbh.de>
9  *              Lots of code moved from tcp.c and ip.c; see those files
10  *              for more names.
11  *
12  *              This program is free software; you can redistribute it and/or
13  *              modify it under the terms of the GNU General Public License
14  *              as published by the Free Software Foundation; either version
15  *              2 of the License, or (at your option) any later version.
16  */
17 #include <net/checksum.h>
18 #include <linux/types.h>
19 #include <asm/byteorder.h>
20 #include <asm/string.h>
21 #include <asm/uaccess.h>
22
23 /*
24  * copy while checksumming, otherwise like csum_partial
25  */
26 unsigned int csum_partial_copy(const char *src, char *dst,
27                                int len, unsigned int sum)
28 {
29         /*
30          * It's 2:30 am and I don't feel like doing it real ...
31          * This is lots slower than the real thing (tm)
32          */
33         sum = csum_partial(src, len, sum);
34         memcpy(dst, src, len);
35
36         return sum;
37 }
38
39 /*
40  * Copy from userspace and compute checksum.  If we catch an exception
41  * then zero the rest of the buffer.
42  */
43 unsigned int csum_partial_copy_from_user (const char *src, char *dst,
44                                           int len, unsigned int sum,
45                                           int *err_ptr)
46 {
47         int missing;
48
49         missing = copy_from_user(dst, src, len);
50         if (missing) {
51                 memset(dst + len - missing, 0, missing);
52                 *err_ptr = -EFAULT;
53         }
54
55         return csum_partial(dst, len, sum);
56 }