xref: /linux/arch/powerpc/lib/checksum_wrappers.c (revision b4db9f840283caca0d904436f187ef56a9126eaa)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *
4  * Copyright (C) IBM Corporation, 2010
5  *
6  * Author: Anton Blanchard <anton@au.ibm.com>
7  */
8 #include <linux/export.h>
9 #include <linux/compiler.h>
10 #include <linux/types.h>
11 #include <asm/checksum.h>
12 #include <linux/uaccess.h>
13 
14 __wsum csum_and_copy_from_user(const void __user *src, void *dst,
15 			       int len)
16 {
17 	__wsum csum;
18 
19 	if (unlikely(!user_read_access_begin(src, len)))
20 		return 0;
21 
22 	csum = csum_partial_copy_generic((void __force *)src, dst, len);
23 
24 	user_read_access_end();
25 	return csum;
26 }
27 
28 __wsum csum_and_copy_to_user(const void *src, void __user *dst, int len)
29 {
30 	__wsum csum;
31 
32 	if (unlikely(!user_write_access_begin(dst, len)))
33 		return 0;
34 
35 	csum = csum_partial_copy_generic(src, (void __force *)dst, len);
36 
37 	user_write_access_end();
38 	return csum;
39 }
40