]>
git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - arch/powerpc/lib/checksum_wrappers.c
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * Copyright (C) IBM Corporation, 2010
18 * Author: Anton Blanchard <anton@au.ibm.com>
20 #include <linux/export.h>
21 #include <linux/compiler.h>
22 #include <linux/types.h>
23 #include <asm/checksum.h>
24 #include <linux/uaccess.h>
26 __wsum
csum_and_copy_from_user(const void __user
*src
, void *dst
,
27 int len
, __wsum sum
, int *err_ptr
)
32 allow_read_from_user(src
, len
);
41 if (unlikely((len
< 0) || !access_ok(src
, len
))) {
43 csum
= (__force
unsigned int)sum
;
47 csum
= csum_partial_copy_generic((void __force
*)src
, dst
,
48 len
, sum
, err_ptr
, NULL
);
50 if (unlikely(*err_ptr
)) {
51 int missing
= __copy_from_user(dst
, src
, len
);
54 memset(dst
+ len
- missing
, 0, missing
);
60 csum
= csum_partial(dst
, len
, sum
);
64 prevent_read_from_user(src
, len
);
65 return (__force __wsum
)csum
;
67 EXPORT_SYMBOL(csum_and_copy_from_user
);
69 __wsum
csum_and_copy_to_user(const void *src
, void __user
*dst
, int len
,
70 __wsum sum
, int *err_ptr
)
75 allow_write_to_user(dst
, len
);
84 if (unlikely((len
< 0) || !access_ok(dst
, len
))) {
86 csum
= -1; /* invalid checksum */
90 csum
= csum_partial_copy_generic(src
, (void __force
*)dst
,
91 len
, sum
, NULL
, err_ptr
);
93 if (unlikely(*err_ptr
)) {
94 csum
= csum_partial(src
, len
, sum
);
96 if (copy_to_user(dst
, src
, len
)) {
98 csum
= -1; /* invalid checksum */
103 prevent_write_to_user(dst
, len
);
104 return (__force __wsum
)csum
;
106 EXPORT_SYMBOL(csum_and_copy_to_user
);