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