aboutsummaryrefslogtreecommitdiffstats
path: root/lib/strncpy_from_user.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/strncpy_from_user.c')
-rw-r--r--lib/strncpy_from_user.c47
1 files changed, 7 insertions, 40 deletions
diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
index c4c09b0e96ba..bb2b201d6ad0 100644
--- a/lib/strncpy_from_user.c
+++ b/lib/strncpy_from_user.c
@@ -4,37 +4,7 @@
4#include <linux/errno.h> 4#include <linux/errno.h>
5 5
6#include <asm/byteorder.h> 6#include <asm/byteorder.h>
7 7#include <asm/word-at-a-time.h>
8static inline long find_zero(unsigned long mask)
9{
10 long byte = 0;
11
12#ifdef __BIG_ENDIAN
13#ifdef CONFIG_64BIT
14 if (mask >> 32)
15 mask >>= 32;
16 else
17 byte = 4;
18#endif
19 if (mask >> 16)
20 mask >>= 16;
21 else
22 byte += 2;
23 return (mask >> 8) ? byte : byte + 1;
24#else
25#ifdef CONFIG_64BIT
26 if (!((unsigned int) mask)) {
27 mask >>= 32;
28 byte = 4;
29 }
30#endif
31 if (!(mask & 0xffff)) {
32 mask >>= 16;
33 byte += 2;
34 }
35 return (mask & 0xff) ? byte : byte + 1;
36#endif
37}
38 8
39#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 9#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
40#define IS_UNALIGNED(src, dst) 0 10#define IS_UNALIGNED(src, dst) 0
@@ -51,8 +21,7 @@ static inline long find_zero(unsigned long mask)
51 */ 21 */
52static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max) 22static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
53{ 23{
54 const unsigned long high_bits = REPEAT_BYTE(0xfe) + 1; 24 const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
55 const unsigned long low_bits = REPEAT_BYTE(0x7f);
56 long res = 0; 25 long res = 0;
57 26
58 /* 27 /*
@@ -66,18 +35,16 @@ static inline long do_strncpy_from_user(char *dst, const char __user *src, long
66 goto byte_at_a_time; 35 goto byte_at_a_time;
67 36
68 while (max >= sizeof(unsigned long)) { 37 while (max >= sizeof(unsigned long)) {
69 unsigned long c, v, rhs; 38 unsigned long c, data;
70 39
71 /* Fall back to byte-at-a-time if we get a page fault */ 40 /* Fall back to byte-at-a-time if we get a page fault */
72 if (unlikely(__get_user(c,(unsigned long __user *)(src+res)))) 41 if (unlikely(__get_user(c,(unsigned long __user *)(src+res))))
73 break; 42 break;
74 rhs = c | low_bits;
75 v = (c + high_bits) & ~rhs;
76 *(unsigned long *)(dst+res) = c; 43 *(unsigned long *)(dst+res) = c;
77 if (v) { 44 if (has_zero(c, &data, &constants)) {
78 v = (c & low_bits) + low_bits; 45 data = prep_zero_mask(c, data, &constants);
79 v = ~(v | rhs); 46 data = create_zero_mask(data);
80 return res + find_zero(v); 47 return res + find_zero(data);
81 } 48 }
82 res += sizeof(unsigned long); 49 res += sizeof(unsigned long);
83 max -= sizeof(unsigned long); 50 max -= sizeof(unsigned long);