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 might_sleep(); 20 21 if (unlikely(!access_ok(src, len))) 22 return 0; 23 24 allow_read_from_user(src, len); 25 26 csum = csum_partial_copy_generic((void __force *)src, dst, len); 27 28 prevent_read_from_user(src, len); 29 return csum; 30 } 31 EXPORT_SYMBOL(csum_and_copy_from_user); 32 33 __wsum csum_and_copy_to_user(const void *src, void __user *dst, int len) 34 { 35 __wsum csum; 36 37 might_sleep(); 38 if (unlikely(!access_ok(dst, len))) 39 return 0; 40 41 allow_write_to_user(dst, len); 42 43 csum = csum_partial_copy_generic(src, (void __force *)dst, len); 44 45 prevent_write_to_user(dst, len); 46 return csum; 47 } 48 EXPORT_SYMBOL(csum_and_copy_to_user); 49