Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

csky: use generic strncpy/strnlen from_user

Remove the csky implemenation of strncpy/strnlen and instead use the
generic versions. The csky version is fairly slow because it always does
byte accesses even for aligned data, and it lacks a checks for
user_addr_max().

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+2 -114
+2
arch/csky/Kconfig
··· 35 35 select GENERIC_IRQ_MULTI_HANDLER 36 36 select GENERIC_SCHED_CLOCK 37 37 select GENERIC_SMP_IDLE_THREAD 38 + select GENERIC_STRNCPY_FROM_USER 39 + select GENERIC_STRNLEN_USER 38 40 select GENERIC_TIME_VSYSCALL 39 41 select GENERIC_VDSO_32 40 42 select GENERIC_GETTIMEOFDAY
-6
arch/csky/include/asm/uaccess.h
··· 209 209 unsigned long __clear_user(void __user *to, unsigned long n); 210 210 #define __clear_user __clear_user 211 211 212 - long strncpy_from_user(char *dst, const char *src, long count); 213 - #define strncpy_from_user strncpy_from_user 214 - 215 - long strnlen_user(const char *s, long n); 216 - #define strnlen_user strnlen_user 217 - 218 212 #include <asm/segment.h> 219 213 #include <asm-generic/uaccess.h> 220 214
-108
arch/csky/lib/usercopy.c
··· 143 143 EXPORT_SYMBOL(raw_copy_to_user); 144 144 145 145 /* 146 - * __strncpy_from_user: - Copy a NUL terminated string from userspace, 147 - * with less checking. 148 - * @dst: Destination address, in kernel space. This buffer must be at 149 - * least @count bytes long. 150 - * @src: Source address, in user space. 151 - * @count: Maximum number of bytes to copy, including the trailing NUL. 152 - * 153 - * Copies a NUL-terminated string from userspace to kernel space. 154 - * Caller must check the specified block with access_ok() before calling 155 - * this function. 156 - * 157 - * On success, returns the length of the string (not including the trailing 158 - * NUL). 159 - * 160 - * If access to userspace fails, returns -EFAULT (some data may have been 161 - * copied). 162 - * 163 - * If @count is smaller than the length of the string, copies @count bytes 164 - * and returns @count. 165 - */ 166 - long strncpy_from_user(char *dst, const char *src, long count) 167 - { 168 - long res, faultres; 169 - int tmp; 170 - 171 - if (!access_ok(s, 1)) 172 - return -EFAULT; 173 - 174 - __asm__ __volatile__( 175 - " cmpnei %3, 0 \n" 176 - " bf 4f \n" 177 - "1: cmpnei %1, 0 \n" 178 - " bf 5f \n" 179 - "2: ldb %4, (%3, 0) \n" 180 - " stb %4, (%2, 0) \n" 181 - " cmpnei %4, 0 \n" 182 - " bf 3f \n" 183 - " addi %3, 1 \n" 184 - " addi %2, 1 \n" 185 - " subi %1, 1 \n" 186 - " br 1b \n" 187 - "3: subu %0, %1 \n" 188 - " br 5f \n" 189 - "4: mov %0, %5 \n" 190 - " br 5f \n" 191 - ".section __ex_table, \"a\" \n" 192 - ".align 2 \n" 193 - ".long 2b, 4b \n" 194 - ".previous \n" 195 - "5: \n" 196 - : "=r"(res), "=r"(count), "=r"(dst), 197 - "=r"(src), "=r"(tmp), "=r"(faultres) 198 - : "5"(-EFAULT), "0"(count), "1"(count), 199 - "2"(dst), "3"(src) 200 - : "memory"); 201 - 202 - return res; 203 - } 204 - EXPORT_SYMBOL(strncpy_from_user); 205 - 206 - /* 207 - * strnlen_user: - Get the size of a string in user space. 208 - * @str: The string to measure. 209 - * @n: The maximum valid length 210 - * 211 - * Get the size of a NUL-terminated string in user space. 212 - * 213 - * Returns the size of the string INCLUDING the terminating NUL. 214 - * On exception, returns 0. 215 - * If the string is too long, returns a value greater than @n. 216 - */ 217 - long strnlen_user(const char *s, long n) 218 - { 219 - unsigned long res, tmp; 220 - 221 - if (!access_ok(s, 1)) 222 - return -EFAULT; 223 - 224 - __asm__ __volatile__( 225 - " cmpnei %1, 0 \n" 226 - " bf 3f \n" 227 - "1: cmpnei %0, 0 \n" 228 - " bf 3f \n" 229 - "2: ldb %3, (%1, 0) \n" 230 - " cmpnei %3, 0 \n" 231 - " bf 3f \n" 232 - " subi %0, 1 \n" 233 - " addi %1, 1 \n" 234 - " br 1b \n" 235 - "3: subu %2, %0 \n" 236 - " addi %2, 1 \n" 237 - " br 5f \n" 238 - "4: movi %0, 0 \n" 239 - " br 5f \n" 240 - ".section __ex_table, \"a\" \n" 241 - ".align 2 \n" 242 - ".long 2b, 4b \n" 243 - ".previous \n" 244 - "5: \n" 245 - : "=r"(n), "=r"(s), "=r"(res), "=r"(tmp) 246 - : "0"(n), "1"(s), "2"(n) 247 - : "memory"); 248 - 249 - return res; 250 - } 251 - EXPORT_SYMBOL(strnlen_user); 252 - 253 - /* 254 146 * __clear_user: - Zero a block of memory in user space, with less checking. 255 147 * @to: Destination address, in user space. 256 148 * @n: Number of bytes to zero.