Skip to content

Commit 1e2aec8

Browse files
committed
Merge branch 'generic-string-functions'
This makes <asm/word-at-a-time.h> actually live up to its promise of allowing architectures to help tune the string functions that do their work a word at a time. David had already taken the x86 strncpy_from_user() function, modified it to work on sparc, and then done the extra work to make it generically useful. This then expands on that work by making x86 use that generic version, completing the circle. But more importantly, it fixes up the word-at-a-time interfaces so that it's now easy to also support things like strnlen_user(), and pretty much most random string functions. David reports that it all works fine on sparc, and Jonas Bonn reported that an earlier version of this worked on OpenRISC too. It's pretty easy for architectures to add support for this and just replace their private versions with the generic code. * generic-string-functions: sparc: use the new generic strnlen_user() function x86: use the new generic strnlen_user() function lib: add generic strnlen_user() function word-at-a-time: make the interfaces truly generic x86: use generic strncpy_from_user routine
2 parents ae32adc + 2c66f62 commit 1e2aec8

23 files changed

Lines changed: 259 additions & 490 deletions

‎arch/openrisc/include/asm/Kbuild‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ generic-y += topology.h
6666
generic-y += types.h
6767
generic-y += ucontext.h
6868
generic-y += user.h
69+
generic-y += word-at-a-time.h

‎arch/sparc/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ config SPARC
3535
select GENERIC_CMOS_UPDATE
3636
select GENERIC_CLOCKEVENTS
3737
select GENERIC_STRNCPY_FROM_USER
38+
select GENERIC_STRNLEN_USER
3839

3940
config SPARC32
4041
def_bool !64BIT

‎arch/sparc/include/asm/Kbuild‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ generic-y += div64.h
2121
generic-y += local64.h
2222
generic-y += irq_regs.h
2323
generic-y += local.h
24+
generic-y += word-at-a-time.h

‎arch/sparc/include/asm/uaccess_32.h‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#ifndef __ASSEMBLY__
1818

19+
#include <asm/processor.h>
20+
1921
#define ARCH_HAS_SORT_EXTABLE
2022
#define ARCH_HAS_SEARCH_EXTABLE
2123

@@ -304,24 +306,8 @@ static inline unsigned long clear_user(void __user *addr, unsigned long n)
304306
return n;
305307
}
306308

307-
extern long __strlen_user(const char __user *);
308-
extern long __strnlen_user(const char __user *, long len);
309-
310-
static inline long strlen_user(const char __user *str)
311-
{
312-
if (!access_ok(VERIFY_READ, str, 0))
313-
return 0;
314-
else
315-
return __strlen_user(str);
316-
}
317-
318-
static inline long strnlen_user(const char __user *str, long len)
319-
{
320-
if (!access_ok(VERIFY_READ, str, 0))
321-
return 0;
322-
else
323-
return __strnlen_user(str, len);
324-
}
309+
extern __must_check long strlen_user(const char __user *str);
310+
extern __must_check long strnlen_user(const char __user *str, long n);
325311

326312
#endif /* __ASSEMBLY__ */
327313

‎arch/sparc/include/asm/uaccess_64.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#ifndef __ASSEMBLY__
1919

20+
#include <asm/processor.h>
21+
2022
/*
2123
* Sparc64 is segmented, though more like the M68K than the I386.
2224
* We use the secondary ASI to address user memory, which references a
@@ -257,11 +259,9 @@ extern unsigned long __must_check __clear_user(void __user *, unsigned long);
257259

258260
#define clear_user __clear_user
259261

260-
extern long __strlen_user(const char __user *);
261-
extern long __strnlen_user(const char __user *, long len);
262+
extern __must_check long strlen_user(const char __user *str);
263+
extern __must_check long strnlen_user(const char __user *str, long n);
262264

263-
#define strlen_user __strlen_user
264-
#define strnlen_user __strnlen_user
265265
#define __copy_to_user_inatomic ___copy_to_user
266266
#define __copy_from_user_inatomic ___copy_from_user
267267

‎arch/sparc/lib/Makefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ lib-y += strlen.o
1010
lib-y += checksum_$(BITS).o
1111
lib-$(CONFIG_SPARC32) += blockops.o
1212
lib-y += memscan_$(BITS).o memcmp.o strncmp_$(BITS).o
13-
lib-y += strlen_user_$(BITS).o
1413
lib-$(CONFIG_SPARC32) += divdi3.o udivdi3.o
1514
lib-$(CONFIG_SPARC32) += copy_user.o locks.o
1615
lib-$(CONFIG_SPARC64) += atomic_64.o

‎arch/sparc/lib/ksyms.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
/* string functions */
1717
EXPORT_SYMBOL(strlen);
18-
EXPORT_SYMBOL(__strlen_user);
19-
EXPORT_SYMBOL(__strnlen_user);
2018
EXPORT_SYMBOL(strncmp);
2119

2220
/* mem* functions */

‎arch/sparc/lib/strlen_user_32.S‎

Lines changed: 0 additions & 109 deletions
This file was deleted.

‎arch/sparc/lib/strlen_user_64.S‎

Lines changed: 0 additions & 97 deletions
This file was deleted.

‎arch/x86/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ config X86
9393
select GENERIC_CLOCKEVENTS_BROADCAST if X86_64 || (X86_32 && X86_LOCAL_APIC)
9494
select GENERIC_TIME_VSYSCALL if X86_64
9595
select KTIME_SCALAR if X86_32
96+
select GENERIC_STRNCPY_FROM_USER
97+
select GENERIC_STRNLEN_USER
9698

9799
config INSTRUCTION_DECODER
98100
def_bool (KPROBES || PERF_EVENTS || UPROBES)

0 commit comments

Comments
 (0)