1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
4*4882a593Smuzhiyun */
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun /*
7*4882a593Smuzhiyun * Support for user memory access from kernel. This will
8*4882a593Smuzhiyun * probably be inlined for performance at some point, but
9*4882a593Smuzhiyun * for ease of debug, and to a lesser degree for code size,
10*4882a593Smuzhiyun * we implement here as subroutines.
11*4882a593Smuzhiyun */
12*4882a593Smuzhiyun #include <linux/types.h>
13*4882a593Smuzhiyun #include <linux/uaccess.h>
14*4882a593Smuzhiyun #include <linux/pgtable.h>
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun /*
17*4882a593Smuzhiyun * For clear_user(), exploit previously defined copy_to_user function
18*4882a593Smuzhiyun * and the fact that we've got a handy zero page defined in kernel/head.S
19*4882a593Smuzhiyun *
20*4882a593Smuzhiyun * dczero here would be even faster.
21*4882a593Smuzhiyun */
__clear_user_hexagon(void __user * dest,unsigned long count)22*4882a593Smuzhiyun __kernel_size_t __clear_user_hexagon(void __user *dest, unsigned long count)
23*4882a593Smuzhiyun {
24*4882a593Smuzhiyun long uncleared;
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun while (count > PAGE_SIZE) {
27*4882a593Smuzhiyun uncleared = raw_copy_to_user(dest, &empty_zero_page, PAGE_SIZE);
28*4882a593Smuzhiyun if (uncleared)
29*4882a593Smuzhiyun return count - (PAGE_SIZE - uncleared);
30*4882a593Smuzhiyun count -= PAGE_SIZE;
31*4882a593Smuzhiyun dest += PAGE_SIZE;
32*4882a593Smuzhiyun }
33*4882a593Smuzhiyun if (count)
34*4882a593Smuzhiyun count = raw_copy_to_user(dest, &empty_zero_page, count);
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun return count;
37*4882a593Smuzhiyun }
38*4882a593Smuzhiyun
clear_user_hexagon(void __user * dest,unsigned long count)39*4882a593Smuzhiyun unsigned long clear_user_hexagon(void __user *dest, unsigned long count)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun if (!access_ok(dest, count))
42*4882a593Smuzhiyun return count;
43*4882a593Smuzhiyun else
44*4882a593Smuzhiyun return __clear_user_hexagon(dest, count);
45*4882a593Smuzhiyun }
46