^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) unsigned long raw_copy_from_user(void *to, const void *from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) ___copy_from_user(to, from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) EXPORT_SYMBOL(raw_copy_from_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) unsigned long raw_copy_to_user(void *to, const void *from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) ___copy_to_user(to, from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) EXPORT_SYMBOL(raw_copy_to_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * copy a null terminated string from userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define __do_strncpy_from_user(dst, src, count, res) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) int tmp; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) long faultres; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) asm volatile( \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) " cmpnei %3, 0 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) " bf 4f \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) "1: cmpnei %1, 0 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) " bf 5f \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) "2: ldb %4, (%3, 0) \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) " stb %4, (%2, 0) \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) " cmpnei %4, 0 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) " bf 3f \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) " addi %3, 1 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) " addi %2, 1 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) " subi %1, 1 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) " br 1b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) "3: subu %0, %1 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) " br 5f \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) "4: mov %0, %5 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) " br 5f \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) ".section __ex_table, \"a\" \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ".align 2 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ".long 2b, 4b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ".previous \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) "5: \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) : "=r"(res), "=r"(count), "=r"(dst), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) "=r"(src), "=r"(tmp), "=r"(faultres) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) : "5"(-EFAULT), "0"(count), "1"(count), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) "2"(dst), "3"(src) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) : "memory", "cc"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * __strncpy_from_user: - Copy a NUL terminated string from userspace,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * with less checking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * @dst: Destination address, in kernel space. This buffer must be at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * least @count bytes long.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * @src: Source address, in user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * @count: Maximum number of bytes to copy, including the trailing NUL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * Copies a NUL-terminated string from userspace to kernel space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * Caller must check the specified block with access_ok() before calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * On success, returns the length of the string (not including the trailing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * NUL).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * If access to userspace fails, returns -EFAULT (some data may have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * copied).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * If @count is smaller than the length of the string, copies @count bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * and returns @count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) long __strncpy_from_user(char *dst, const char *src, long count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) long res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) __do_strncpy_from_user(dst, src, count, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) EXPORT_SYMBOL(__strncpy_from_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * strncpy_from_user: - Copy a NUL terminated string from userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * @dst: Destination address, in kernel space. This buffer must be at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * least @count bytes long.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * @src: Source address, in user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * @count: Maximum number of bytes to copy, including the trailing NUL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * Copies a NUL-terminated string from userspace to kernel space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * On success, returns the length of the string (not including the trailing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * NUL).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * If access to userspace fails, returns -EFAULT (some data may have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * copied).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * If @count is smaller than the length of the string, copies @count bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * and returns @count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) long strncpy_from_user(char *dst, const char *src, long count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) long res = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (access_ok(src, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) __do_strncpy_from_user(dst, src, count, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) EXPORT_SYMBOL(strncpy_from_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * strlen_user: - Get the size of a string in user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * @str: The string to measure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * @n: The maximum valid length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * Get the size of a NUL-terminated string in user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * Returns the size of the string INCLUDING the terminating NUL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * On exception, returns 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * If the string is too long, returns a value greater than @n.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) long strnlen_user(const char *s, long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unsigned long res, tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (s == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) " cmpnei %1, 0 \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) " bf 3f \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) "1: cmpnei %0, 0 \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) " bf 3f \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) "2: ldb %3, (%1, 0) \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) " cmpnei %3, 0 \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) " bf 3f \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) " subi %0, 1 \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) " addi %1, 1 \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) " br 1b \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) "3: subu %2, %0 \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) " addi %2, 1 \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) " br 5f \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) "4: movi %0, 0 \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) " br 5f \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ".section __ex_table, \"a\" \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ".align 2 \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ".long 2b, 4b \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ".previous \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) "5: \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) : "=r"(n), "=r"(s), "=r"(res), "=r"(tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) : "0"(n), "1"(s), "2"(n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) : "memory", "cc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) EXPORT_SYMBOL(strnlen_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #define __do_clear_user(addr, size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int __d0, zvalue, tmp; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) asm volatile( \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) "0: cmpnei %1, 0 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) " bf 7f \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) " mov %3, %1 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) " andi %3, 3 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) " cmpnei %3, 0 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) " bf 1f \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) " br 5f \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) "1: cmplti %0, 32 \n" /* 4W */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) " bt 3f \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) "8: stw %2, (%1, 0) \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) "10: stw %2, (%1, 4) \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) "11: stw %2, (%1, 8) \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) "12: stw %2, (%1, 12) \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) "13: stw %2, (%1, 16) \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) "14: stw %2, (%1, 20) \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) "15: stw %2, (%1, 24) \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) "16: stw %2, (%1, 28) \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) " addi %1, 32 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) " subi %0, 32 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) " br 1b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) "3: cmplti %0, 4 \n" /* 1W */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) " bt 5f \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) "4: stw %2, (%1, 0) \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) " addi %1, 4 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) " subi %0, 4 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) " br 3b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) "5: cmpnei %0, 0 \n" /* 1B */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) "9: bf 7f \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) "6: stb %2, (%1, 0) \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) " addi %1, 1 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) " subi %0, 1 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) " br 5b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) ".section __ex_table,\"a\" \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ".align 2 \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ".long 8b, 9b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) ".long 10b, 9b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) ".long 11b, 9b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ".long 12b, 9b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) ".long 13b, 9b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) ".long 14b, 9b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) ".long 15b, 9b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) ".long 16b, 9b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ".long 4b, 9b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) ".long 6b, 9b \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) ".previous \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) "7: \n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) : "=r"(size), "=r" (__d0), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) "=r"(zvalue), "=r"(tmp) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) : "0"(size), "1"(addr), "2"(0) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) : "memory", "cc"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * clear_user: - Zero a block of memory in user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * @to: Destination address, in user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * @n: Number of bytes to zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * Zero a block of memory in user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * Returns number of bytes that could not be cleared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * On success, this will be zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) clear_user(void __user *to, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (access_ok(to, n))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) __do_clear_user(to, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) EXPORT_SYMBOL(clear_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * __clear_user: - Zero a block of memory in user space, with less checking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * @to: Destination address, in user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * @n: Number of bytes to zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * Zero a block of memory in user space. Caller must check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * the specified block with access_ok() before calling this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * Returns number of bytes that could not be cleared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * On success, this will be zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) __clear_user(void __user *to, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) __do_clear_user(to, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) EXPORT_SYMBOL(__clear_user);