Skip to content

Commit b26b181

Browse files
committed
microblaze: use generic strncpy/strnlen from_user
Remove the microblaze implemenation of strncpy/strnlen and instead use the generic versions. The microblaze 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>
1 parent 0cd1151 commit b26b181

4 files changed

Lines changed: 6 additions & 108 deletions

File tree

arch/microblaze/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ config MICROBLAZE
2121
select GENERIC_IRQ_SHOW
2222
select GENERIC_PCI_IOMAP
2323
select GENERIC_SCHED_CLOCK
24+
select GENERIC_STRNCPY_FROM_USER
25+
select GENERIC_STRNLEN_USER
2426
select HAVE_ARCH_HASH
2527
select HAVE_ARCH_KGDB
2628
select HAVE_ARCH_SECCOMP

arch/microblaze/include/asm/uaccess.h

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
# define get_fs() (current_thread_info()->addr_limit)
3737
# define set_fs(val) (current_thread_info()->addr_limit = (val))
38+
# define user_addr_max() get_fs().seg
3839

3940
# define uaccess_kernel() (get_fs().seg == KERNEL_DS.seg)
4041

@@ -296,28 +297,14 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n)
296297
/*
297298
* Copy a null terminated string from userspace.
298299
*/
299-
extern int __strncpy_user(char *to, const char __user *from, int len);
300-
301-
static inline long
302-
strncpy_from_user(char *dst, const char __user *src, long count)
303-
{
304-
if (!access_ok(src, 1))
305-
return -EFAULT;
306-
return __strncpy_user(dst, src, count);
307-
}
300+
__must_check long strncpy_from_user(char *dst, const char __user *src,
301+
long count);
308302

309303
/*
310304
* Return the size of a string (including the ending 0)
311305
*
312306
* Return 0 on exception, a value greater than N if too long
313307
*/
314-
extern int __strnlen_user(const char __user *sstr, int len);
315-
316-
static inline long strnlen_user(const char __user *src, long n)
317-
{
318-
if (!access_ok(src, 1))
319-
return 0;
320-
return __strnlen_user(src, n);
321-
}
308+
__must_check long strnlen_user(const char __user *sstr, long len);
322309

323310
#endif /* _ASM_MICROBLAZE_UACCESS_H */

arch/microblaze/kernel/microblaze_ksyms.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ EXPORT_SYMBOL(_mcount);
2626
* Assembly functions that may be used (directly or indirectly) by modules
2727
*/
2828
EXPORT_SYMBOL(__copy_tofrom_user);
29-
EXPORT_SYMBOL(__strncpy_user);
3029

3130
#ifdef CONFIG_OPT_LIB_ASM
3231
EXPORT_SYMBOL(memcpy);

arch/microblaze/lib/uaccess_old.S

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -12,96 +12,6 @@
1212
#include <linux/linkage.h>
1313
#include <asm/page.h>
1414

15-
/*
16-
* int __strncpy_user(char *to, char *from, int len);
17-
*
18-
* Returns:
19-
* -EFAULT for an exception
20-
* len if we hit the buffer limit
21-
* bytes copied
22-
*/
23-
24-
.text
25-
.globl __strncpy_user;
26-
.type __strncpy_user, @function
27-
.align 4;
28-
__strncpy_user:
29-
30-
/*
31-
* r5 - to
32-
* r6 - from
33-
* r7 - len
34-
* r3 - temp count
35-
* r4 - temp val
36-
*/
37-
beqid r7,3f
38-
addik r3,r7,0 /* temp_count = len */
39-
1:
40-
lbu r4,r6,r0
41-
beqid r4,2f
42-
sb r4,r5,r0
43-
44-
addik r5,r5,1
45-
addik r6,r6,1 /* delay slot */
46-
47-
addik r3,r3,-1
48-
bnei r3,1b /* break on len */
49-
2:
50-
rsubk r3,r3,r7 /* temp_count = len - temp_count */
51-
3:
52-
rtsd r15,8
53-
nop
54-
.size __strncpy_user, . - __strncpy_user
55-
56-
.section .fixup, "ax"
57-
.align 2
58-
4:
59-
brid 3b
60-
addik r3,r0, -EFAULT
61-
62-
.section __ex_table, "a"
63-
.word 1b,4b
64-
65-
/*
66-
* int __strnlen_user(char __user *str, int maxlen);
67-
*
68-
* Returns:
69-
* 0 on error
70-
* maxlen + 1 if no NUL byte found within maxlen bytes
71-
* size of the string (including NUL byte)
72-
*/
73-
74-
.text
75-
.globl __strnlen_user;
76-
.type __strnlen_user, @function
77-
.align 4;
78-
__strnlen_user:
79-
beqid r6,3f
80-
addik r3,r6,0
81-
1:
82-
lbu r4,r5,r0
83-
beqid r4,2f /* break on NUL */
84-
addik r3,r3,-1 /* delay slot */
85-
86-
bneid r3,1b
87-
addik r5,r5,1 /* delay slot */
88-
89-
addik r3,r3,-1 /* for break on len */
90-
2:
91-
rsubk r3,r3,r6
92-
3:
93-
rtsd r15,8
94-
nop
95-
.size __strnlen_user, . - __strnlen_user
96-
97-
.section .fixup,"ax"
98-
4:
99-
brid 3b
100-
addk r3,r0,r0
101-
102-
.section __ex_table,"a"
103-
.word 1b,4b
104-
10515
/* Loop unrolling for __copy_tofrom_user */
10616
#define COPY(offset) \
10717
1: lwi r4 , r6, 0x0000 + offset; \

0 commit comments

Comments
 (0)