xref: /linux/arch/powerpc/lib/checksum_wrappers.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
203bc8b0fSChristophe Leroy /*
303bc8b0fSChristophe Leroy  *
403bc8b0fSChristophe Leroy  * Copyright (C) IBM Corporation, 2010
503bc8b0fSChristophe Leroy  *
603bc8b0fSChristophe Leroy  * Author: Anton Blanchard <anton@au.ibm.com>
703bc8b0fSChristophe Leroy  */
803bc8b0fSChristophe Leroy #include <linux/export.h>
903bc8b0fSChristophe Leroy #include <linux/compiler.h>
1003bc8b0fSChristophe Leroy #include <linux/types.h>
1103bc8b0fSChristophe Leroy #include <asm/checksum.h>
127c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
1303bc8b0fSChristophe Leroy 
csum_and_copy_from_user(const void __user * src,void * dst,int len)1403bc8b0fSChristophe Leroy __wsum csum_and_copy_from_user(const void __user *src, void *dst,
15c693cc46SAl Viro 			       int len)
1603bc8b0fSChristophe Leroy {
1770d65cd5SAl Viro 	__wsum csum;
1803bc8b0fSChristophe Leroy 
19*164dc6ceSChristophe Leroy 	if (unlikely(!user_read_access_begin(src, len)))
20c693cc46SAl Viro 		return 0;
21c693cc46SAl Viro 
2270d65cd5SAl Viro 	csum = csum_partial_copy_generic((void __force *)src, dst, len);
2303bc8b0fSChristophe Leroy 
24*164dc6ceSChristophe Leroy 	user_read_access_end();
2570d65cd5SAl Viro 	return csum;
2603bc8b0fSChristophe Leroy }
2703bc8b0fSChristophe Leroy 
csum_and_copy_to_user(const void * src,void __user * dst,int len)28c693cc46SAl Viro __wsum csum_and_copy_to_user(const void *src, void __user *dst, int len)
2903bc8b0fSChristophe Leroy {
3070d65cd5SAl Viro 	__wsum csum;
3103bc8b0fSChristophe Leroy 
32*164dc6ceSChristophe Leroy 	if (unlikely(!user_write_access_begin(dst, len)))
33c693cc46SAl Viro 		return 0;
34c693cc46SAl Viro 
3570d65cd5SAl Viro 	csum = csum_partial_copy_generic(src, (void __force *)dst, len);
3603bc8b0fSChristophe Leroy 
37*164dc6ceSChristophe Leroy 	user_write_access_end();
3870d65cd5SAl Viro 	return csum;
3903bc8b0fSChristophe Leroy }
40