diff options
author | Will Deacon <will.deacon@arm.com> | 2012-07-06 10:45:39 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2012-07-09 12:41:11 -0400 |
commit | 8c56cc8be5b38e3684eba96dc9b3f7ca7e495755 (patch) | |
tree | eccb882c8c5f1cc81fc226c769fc9ec99a45145b /arch/arm/lib | |
parent | 4295b898f5a5c7e62ae68e7a4ecc4b414622ffe6 (diff) |
ARM: 7449/1: use generic strnlen_user and strncpy_from_user functions
This patch implements the word-at-a-time interface for ARM using the
same algorithm as x86. We use the fls macro from ARMv5 onwards, where
we have a clz instruction available which saves us a mov instruction
when targetting Thumb-2. For older CPUs, we use the magic 0x0ff0001
constant. Big-endian configurations make use of the implementation from
asm-generic.
With this implemented, we can replace our byte-at-a-time strnlen_user
and strncpy_from_user functions with the optimised generic versions.
Reviewed-by: Nicolas Pitre <nico@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch/arm/lib')
-rw-r--r-- | arch/arm/lib/Makefile | 1 | ||||
-rw-r--r-- | arch/arm/lib/strncpy_from_user.S | 43 | ||||
-rw-r--r-- | arch/arm/lib/strnlen_user.S | 40 |
3 files changed, 0 insertions, 84 deletions
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile index 992769ae2599..d5060dab6e52 100644 --- a/arch/arm/lib/Makefile +++ b/arch/arm/lib/Makefile | |||
@@ -8,7 +8,6 @@ lib-y := backtrace.o changebit.o csumipv6.o csumpartial.o \ | |||
8 | csumpartialcopy.o csumpartialcopyuser.o clearbit.o \ | 8 | csumpartialcopy.o csumpartialcopyuser.o clearbit.o \ |
9 | delay.o findbit.o memchr.o memcpy.o \ | 9 | delay.o findbit.o memchr.o memcpy.o \ |
10 | memmove.o memset.o memzero.o setbit.o \ | 10 | memmove.o memset.o memzero.o setbit.o \ |
11 | strncpy_from_user.o strnlen_user.o \ | ||
12 | strchr.o strrchr.o \ | 11 | strchr.o strrchr.o \ |
13 | testchangebit.o testclearbit.o testsetbit.o \ | 12 | testchangebit.o testclearbit.o testsetbit.o \ |
14 | ashldi3.o ashrdi3.o lshrdi3.o muldi3.o \ | 13 | ashldi3.o ashrdi3.o lshrdi3.o muldi3.o \ |
diff --git a/arch/arm/lib/strncpy_from_user.S b/arch/arm/lib/strncpy_from_user.S deleted file mode 100644 index f202d7bd1647..000000000000 --- a/arch/arm/lib/strncpy_from_user.S +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/lib/strncpy_from_user.S | ||
3 | * | ||
4 | * Copyright (C) 1995-2000 Russell King | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | #include <linux/linkage.h> | ||
11 | #include <asm/assembler.h> | ||
12 | #include <asm/errno.h> | ||
13 | |||
14 | .text | ||
15 | .align 5 | ||
16 | |||
17 | /* | ||
18 | * Copy a string from user space to kernel space. | ||
19 | * r0 = dst, r1 = src, r2 = byte length | ||
20 | * returns the number of characters copied (strlen of copied string), | ||
21 | * -EFAULT on exception, or "len" if we fill the whole buffer | ||
22 | */ | ||
23 | ENTRY(__strncpy_from_user) | ||
24 | mov ip, r1 | ||
25 | 1: subs r2, r2, #1 | ||
26 | ldrusr r3, r1, 1, pl | ||
27 | bmi 2f | ||
28 | strb r3, [r0], #1 | ||
29 | teq r3, #0 | ||
30 | bne 1b | ||
31 | sub r1, r1, #1 @ take NUL character out of count | ||
32 | 2: sub r0, r1, ip | ||
33 | mov pc, lr | ||
34 | ENDPROC(__strncpy_from_user) | ||
35 | |||
36 | .pushsection .fixup,"ax" | ||
37 | .align 0 | ||
38 | 9001: mov r3, #0 | ||
39 | strb r3, [r0, #0] @ null terminate | ||
40 | mov r0, #-EFAULT | ||
41 | mov pc, lr | ||
42 | .popsection | ||
43 | |||
diff --git a/arch/arm/lib/strnlen_user.S b/arch/arm/lib/strnlen_user.S deleted file mode 100644 index 0ecbb459c4f1..000000000000 --- a/arch/arm/lib/strnlen_user.S +++ /dev/null | |||
@@ -1,40 +0,0 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/lib/strnlen_user.S | ||
3 | * | ||
4 | * Copyright (C) 1995-2000 Russell King | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | #include <linux/linkage.h> | ||
11 | #include <asm/assembler.h> | ||
12 | #include <asm/errno.h> | ||
13 | |||
14 | .text | ||
15 | .align 5 | ||
16 | |||
17 | /* Prototype: unsigned long __strnlen_user(const char *str, long n) | ||
18 | * Purpose : get length of a string in user memory | ||
19 | * Params : str - address of string in user memory | ||
20 | * Returns : length of string *including terminator* | ||
21 | * or zero on exception, or n + 1 if too long | ||
22 | */ | ||
23 | ENTRY(__strnlen_user) | ||
24 | mov r2, r0 | ||
25 | 1: | ||
26 | ldrusr r3, r0, 1 | ||
27 | teq r3, #0 | ||
28 | beq 2f | ||
29 | subs r1, r1, #1 | ||
30 | bne 1b | ||
31 | add r0, r0, #1 | ||
32 | 2: sub r0, r0, r2 | ||
33 | mov pc, lr | ||
34 | ENDPROC(__strnlen_user) | ||
35 | |||
36 | .pushsection .fixup,"ax" | ||
37 | .align 0 | ||
38 | 9001: mov r0, #0 | ||
39 | mov pc, lr | ||
40 | .popsection | ||