2019-05-27 14:55:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-08-03 04:09:52 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (C) IBM Corporation, 2010
|
|
|
|
*
|
|
|
|
* Author: Anton Blanchard <anton@au.ibm.com>
|
|
|
|
*/
|
2011-07-23 06:24:23 +08:00
|
|
|
#include <linux/export.h>
|
2010-08-03 04:09:52 +08:00
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <asm/checksum.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2010-08-03 04:09:52 +08:00
|
|
|
|
|
|
|
__wsum csum_and_copy_from_user(const void __user *src, void *dst,
|
2020-07-11 12:27:49 +08:00
|
|
|
int len)
|
2010-08-03 04:09:52 +08:00
|
|
|
{
|
2020-07-20 22:09:24 +08:00
|
|
|
__wsum csum;
|
2010-08-03 04:09:52 +08:00
|
|
|
|
2021-03-11 01:57:05 +08:00
|
|
|
if (unlikely(!user_read_access_begin(src, len)))
|
2020-07-11 12:27:49 +08:00
|
|
|
return 0;
|
2010-08-03 04:09:52 +08:00
|
|
|
|
2020-07-20 22:09:24 +08:00
|
|
|
csum = csum_partial_copy_generic((void __force *)src, dst, len);
|
2010-08-03 04:09:52 +08:00
|
|
|
|
2021-03-11 01:57:05 +08:00
|
|
|
user_read_access_end();
|
2020-07-20 22:09:24 +08:00
|
|
|
return csum;
|
2010-08-03 04:09:52 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(csum_and_copy_from_user);
|
2010-08-03 04:11:36 +08:00
|
|
|
|
2020-07-11 12:27:49 +08:00
|
|
|
__wsum csum_and_copy_to_user(const void *src, void __user *dst, int len)
|
2010-08-03 04:11:36 +08:00
|
|
|
{
|
2020-07-20 22:09:24 +08:00
|
|
|
__wsum csum;
|
2010-08-03 04:11:36 +08:00
|
|
|
|
2021-03-11 01:57:05 +08:00
|
|
|
if (unlikely(!user_write_access_begin(dst, len)))
|
2020-07-11 12:27:49 +08:00
|
|
|
return 0;
|
2010-08-03 04:11:36 +08:00
|
|
|
|
2020-07-20 22:09:24 +08:00
|
|
|
csum = csum_partial_copy_generic(src, (void __force *)dst, len);
|
2010-08-03 04:11:36 +08:00
|
|
|
|
2021-03-11 01:57:05 +08:00
|
|
|
user_write_access_end();
|
2020-07-20 22:09:24 +08:00
|
|
|
return csum;
|
2010-08-03 04:11:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(csum_and_copy_to_user);
|