xref: /linux/arch/powerpc/lib/checksum_wrappers.c (revision d4b996f9ef1fe83d9ce9ad5c1ca0bd8231638ce5)
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 EXPORT_SYMBOL(csum_and_copy_from_user);
28 
29 __wsum csum_and_copy_to_user(const void *src, void __user *dst, int len)
30 {
31 	__wsum csum;
32 
33 	if (unlikely(!user_write_access_begin(dst, len)))
34 		return 0;
35 
36 	csum = csum_partial_copy_generic(src, (void __force *)dst, len);
37 
38 	user_write_access_end();
39 	return csum;
40 }
41 EXPORT_SYMBOL(csum_and_copy_to_user);
42