diff options
author | Ingo Molnar <mingo@kernel.org> | 2012-05-30 04:59:04 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2012-05-30 04:59:04 -0400 |
commit | 063e04776172f93b16a5eefd5661a340c1126513 (patch) | |
tree | 19cb1623631c8cc5dcf0d91f4731feec7cbefa04 /lib | |
parent | 59cd358a7a5b2f6b61faa01dae6cfda3830ac62a (diff) | |
parent | 731a7378b81c2f5fa88ca1ae20b83d548d5613dc (diff) |
Merge branch 'linus' into perf/urgent
Merge back Linus's latest branch so that we pick up the uprobes changes.
( I tested this branch locally and while it's one from the middle of the
merge window it's a good one to base further work off. )
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 9 | ||||
-rw-r--r-- | lib/Makefile | 5 | ||||
-rw-r--r-- | lib/bitmap.c | 12 | ||||
-rw-r--r-- | lib/list_debug.c | 3 | ||||
-rw-r--r-- | lib/radix-tree.c | 15 | ||||
-rw-r--r-- | lib/spinlock_debug.c | 2 | ||||
-rw-r--r-- | lib/stmp_device.c | 80 | ||||
-rw-r--r-- | lib/string_helpers.c | 8 | ||||
-rw-r--r-- | lib/strncpy_from_user.c | 113 | ||||
-rw-r--r-- | lib/strnlen_user.c | 138 | ||||
-rw-r--r-- | lib/swiotlb.c | 8 | ||||
-rw-r--r-- | lib/test-kstrtox.c | 4 | ||||
-rw-r--r-- | lib/vsprintf.c | 14 |
13 files changed, 387 insertions, 24 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index 0e25c03939e3..a9e15403434e 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
@@ -16,6 +16,12 @@ config BITREVERSE | |||
16 | config RATIONAL | 16 | config RATIONAL |
17 | boolean | 17 | boolean |
18 | 18 | ||
19 | config GENERIC_STRNCPY_FROM_USER | ||
20 | bool | ||
21 | |||
22 | config GENERIC_STRNLEN_USER | ||
23 | bool | ||
24 | |||
19 | config GENERIC_FIND_FIRST_BIT | 25 | config GENERIC_FIND_FIRST_BIT |
20 | bool | 26 | bool |
21 | 27 | ||
@@ -33,6 +39,9 @@ config GENERIC_IO | |||
33 | boolean | 39 | boolean |
34 | default n | 40 | default n |
35 | 41 | ||
42 | config STMP_DEVICE | ||
43 | bool | ||
44 | |||
36 | config CRC_CCITT | 45 | config CRC_CCITT |
37 | tristate "CRC-CCITT functions" | 46 | tristate "CRC-CCITT functions" |
38 | help | 47 | help |
diff --git a/lib/Makefile b/lib/Makefile index 74290c9e2864..8c31a0cb75e9 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -125,6 +125,11 @@ obj-$(CONFIG_CLZ_TAB) += clz_tab.o | |||
125 | 125 | ||
126 | obj-$(CONFIG_DDR) += jedec_ddr_data.o | 126 | obj-$(CONFIG_DDR) += jedec_ddr_data.o |
127 | 127 | ||
128 | obj-$(CONFIG_GENERIC_STRNCPY_FROM_USER) += strncpy_from_user.o | ||
129 | obj-$(CONFIG_GENERIC_STRNLEN_USER) += strnlen_user.o | ||
130 | |||
131 | obj-$(CONFIG_STMP_DEVICE) += stmp_device.o | ||
132 | |||
128 | hostprogs-y := gen_crc32table | 133 | hostprogs-y := gen_crc32table |
129 | clean-files := crc32table.h | 134 | clean-files := crc32table.h |
130 | 135 | ||
diff --git a/lib/bitmap.c b/lib/bitmap.c index b5a8b6ad2454..06fdfa1aeba7 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c | |||
@@ -369,7 +369,8 @@ EXPORT_SYMBOL(bitmap_find_next_zero_area); | |||
369 | * @nmaskbits: size of bitmap, in bits | 369 | * @nmaskbits: size of bitmap, in bits |
370 | * | 370 | * |
371 | * Exactly @nmaskbits bits are displayed. Hex digits are grouped into | 371 | * Exactly @nmaskbits bits are displayed. Hex digits are grouped into |
372 | * comma-separated sets of eight digits per set. | 372 | * comma-separated sets of eight digits per set. Returns the number of |
373 | * characters which were written to *buf, excluding the trailing \0. | ||
373 | */ | 374 | */ |
374 | int bitmap_scnprintf(char *buf, unsigned int buflen, | 375 | int bitmap_scnprintf(char *buf, unsigned int buflen, |
375 | const unsigned long *maskp, int nmaskbits) | 376 | const unsigned long *maskp, int nmaskbits) |
@@ -517,8 +518,8 @@ EXPORT_SYMBOL(bitmap_parse_user); | |||
517 | * | 518 | * |
518 | * Helper routine for bitmap_scnlistprintf(). Write decimal number | 519 | * Helper routine for bitmap_scnlistprintf(). Write decimal number |
519 | * or range to buf, suppressing output past buf+buflen, with optional | 520 | * or range to buf, suppressing output past buf+buflen, with optional |
520 | * comma-prefix. Return len of what would be written to buf, if it | 521 | * comma-prefix. Return len of what was written to *buf, excluding the |
521 | * all fit. | 522 | * trailing \0. |
522 | */ | 523 | */ |
523 | static inline int bscnl_emit(char *buf, int buflen, int rbot, int rtop, int len) | 524 | static inline int bscnl_emit(char *buf, int buflen, int rbot, int rtop, int len) |
524 | { | 525 | { |
@@ -544,9 +545,8 @@ static inline int bscnl_emit(char *buf, int buflen, int rbot, int rtop, int len) | |||
544 | * the range. Output format is compatible with the format | 545 | * the range. Output format is compatible with the format |
545 | * accepted as input by bitmap_parselist(). | 546 | * accepted as input by bitmap_parselist(). |
546 | * | 547 | * |
547 | * The return value is the number of characters which would be | 548 | * The return value is the number of characters which were written to *buf |
548 | * generated for the given input, excluding the trailing '\0', as | 549 | * excluding the trailing '\0', as per ISO C99's scnprintf. |
549 | * per ISO C99. | ||
550 | */ | 550 | */ |
551 | int bitmap_scnlistprintf(char *buf, unsigned int buflen, | 551 | int bitmap_scnlistprintf(char *buf, unsigned int buflen, |
552 | const unsigned long *maskp, int nmaskbits) | 552 | const unsigned long *maskp, int nmaskbits) |
diff --git a/lib/list_debug.c b/lib/list_debug.c index 3810b481f940..23a5e031cd8b 100644 --- a/lib/list_debug.c +++ b/lib/list_debug.c | |||
@@ -31,6 +31,9 @@ void __list_add(struct list_head *new, | |||
31 | "list_add corruption. prev->next should be " | 31 | "list_add corruption. prev->next should be " |
32 | "next (%p), but was %p. (prev=%p).\n", | 32 | "next (%p), but was %p. (prev=%p).\n", |
33 | next, prev->next, prev); | 33 | next, prev->next, prev); |
34 | WARN(new == prev || new == next, | ||
35 | "list_add double add: new=%p, prev=%p, next=%p.\n", | ||
36 | new, prev, next); | ||
34 | next->prev = new; | 37 | next->prev = new; |
35 | new->next = next; | 38 | new->next = next; |
36 | new->prev = prev; | 39 | new->prev = prev; |
diff --git a/lib/radix-tree.c b/lib/radix-tree.c index 86516f5588e3..d7c878cc006c 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c | |||
@@ -73,11 +73,24 @@ static unsigned long height_to_maxindex[RADIX_TREE_MAX_PATH + 1] __read_mostly; | |||
73 | static struct kmem_cache *radix_tree_node_cachep; | 73 | static struct kmem_cache *radix_tree_node_cachep; |
74 | 74 | ||
75 | /* | 75 | /* |
76 | * The radix tree is variable-height, so an insert operation not only has | ||
77 | * to build the branch to its corresponding item, it also has to build the | ||
78 | * branch to existing items if the size has to be increased (by | ||
79 | * radix_tree_extend). | ||
80 | * | ||
81 | * The worst case is a zero height tree with just a single item at index 0, | ||
82 | * and then inserting an item at index ULONG_MAX. This requires 2 new branches | ||
83 | * of RADIX_TREE_MAX_PATH size to be created, with only the root node shared. | ||
84 | * Hence: | ||
85 | */ | ||
86 | #define RADIX_TREE_PRELOAD_SIZE (RADIX_TREE_MAX_PATH * 2 - 1) | ||
87 | |||
88 | /* | ||
76 | * Per-cpu pool of preloaded nodes | 89 | * Per-cpu pool of preloaded nodes |
77 | */ | 90 | */ |
78 | struct radix_tree_preload { | 91 | struct radix_tree_preload { |
79 | int nr; | 92 | int nr; |
80 | struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH]; | 93 | struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE]; |
81 | }; | 94 | }; |
82 | static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, }; | 95 | static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, }; |
83 | 96 | ||
diff --git a/lib/spinlock_debug.c b/lib/spinlock_debug.c index 525d160d44f0..d0ec4f3d1593 100644 --- a/lib/spinlock_debug.c +++ b/lib/spinlock_debug.c | |||
@@ -58,7 +58,7 @@ static void spin_dump(raw_spinlock_t *lock, const char *msg) | |||
58 | printk(KERN_EMERG "BUG: spinlock %s on CPU#%d, %s/%d\n", | 58 | printk(KERN_EMERG "BUG: spinlock %s on CPU#%d, %s/%d\n", |
59 | msg, raw_smp_processor_id(), | 59 | msg, raw_smp_processor_id(), |
60 | current->comm, task_pid_nr(current)); | 60 | current->comm, task_pid_nr(current)); |
61 | printk(KERN_EMERG " lock: %p, .magic: %08x, .owner: %s/%d, " | 61 | printk(KERN_EMERG " lock: %ps, .magic: %08x, .owner: %s/%d, " |
62 | ".owner_cpu: %d\n", | 62 | ".owner_cpu: %d\n", |
63 | lock, lock->magic, | 63 | lock, lock->magic, |
64 | owner ? owner->comm : "<none>", | 64 | owner ? owner->comm : "<none>", |
diff --git a/lib/stmp_device.c b/lib/stmp_device.c new file mode 100644 index 000000000000..8ac9bcc4289a --- /dev/null +++ b/lib/stmp_device.c | |||
@@ -0,0 +1,80 @@ | |||
1 | /* | ||
2 | * Copyright (C) 1999 ARM Limited | ||
3 | * Copyright (C) 2000 Deep Blue Solutions Ltd | ||
4 | * Copyright 2006-2007,2010 Freescale Semiconductor, Inc. All Rights Reserved. | ||
5 | * Copyright 2008 Juergen Beisert, kernel@pengutronix.de | ||
6 | * Copyright 2009 Ilya Yanok, Emcraft Systems Ltd, yanok@emcraft.com | ||
7 | * Copyright (C) 2011 Wolfram Sang, Pengutronix e.K. | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | */ | ||
14 | |||
15 | #include <linux/io.h> | ||
16 | #include <linux/errno.h> | ||
17 | #include <linux/delay.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/stmp_device.h> | ||
20 | |||
21 | #define STMP_MODULE_CLKGATE (1 << 30) | ||
22 | #define STMP_MODULE_SFTRST (1 << 31) | ||
23 | |||
24 | /* | ||
25 | * Clear the bit and poll it cleared. This is usually called with | ||
26 | * a reset address and mask being either SFTRST(bit 31) or CLKGATE | ||
27 | * (bit 30). | ||
28 | */ | ||
29 | static int stmp_clear_poll_bit(void __iomem *addr, u32 mask) | ||
30 | { | ||
31 | int timeout = 0x400; | ||
32 | |||
33 | writel(mask, addr + STMP_OFFSET_REG_CLR); | ||
34 | udelay(1); | ||
35 | while ((readl(addr) & mask) && --timeout) | ||
36 | /* nothing */; | ||
37 | |||
38 | return !timeout; | ||
39 | } | ||
40 | |||
41 | int stmp_reset_block(void __iomem *reset_addr) | ||
42 | { | ||
43 | int ret; | ||
44 | int timeout = 0x400; | ||
45 | |||
46 | /* clear and poll SFTRST */ | ||
47 | ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_SFTRST); | ||
48 | if (unlikely(ret)) | ||
49 | goto error; | ||
50 | |||
51 | /* clear CLKGATE */ | ||
52 | writel(STMP_MODULE_CLKGATE, reset_addr + STMP_OFFSET_REG_CLR); | ||
53 | |||
54 | /* set SFTRST to reset the block */ | ||
55 | writel(STMP_MODULE_SFTRST, reset_addr + STMP_OFFSET_REG_SET); | ||
56 | udelay(1); | ||
57 | |||
58 | /* poll CLKGATE becoming set */ | ||
59 | while ((!(readl(reset_addr) & STMP_MODULE_CLKGATE)) && --timeout) | ||
60 | /* nothing */; | ||
61 | if (unlikely(!timeout)) | ||
62 | goto error; | ||
63 | |||
64 | /* clear and poll SFTRST */ | ||
65 | ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_SFTRST); | ||
66 | if (unlikely(ret)) | ||
67 | goto error; | ||
68 | |||
69 | /* clear and poll CLKGATE */ | ||
70 | ret = stmp_clear_poll_bit(reset_addr, STMP_MODULE_CLKGATE); | ||
71 | if (unlikely(ret)) | ||
72 | goto error; | ||
73 | |||
74 | return 0; | ||
75 | |||
76 | error: | ||
77 | pr_err("%s(%p): module reset timeout\n", __func__, reset_addr); | ||
78 | return -ETIMEDOUT; | ||
79 | } | ||
80 | EXPORT_SYMBOL(stmp_reset_block); | ||
diff --git a/lib/string_helpers.c b/lib/string_helpers.c index dd4ece372699..1cffc223bff5 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c | |||
@@ -23,15 +23,15 @@ | |||
23 | int string_get_size(u64 size, const enum string_size_units units, | 23 | int string_get_size(u64 size, const enum string_size_units units, |
24 | char *buf, int len) | 24 | char *buf, int len) |
25 | { | 25 | { |
26 | const char *units_10[] = { "B", "kB", "MB", "GB", "TB", "PB", | 26 | static const char *units_10[] = { "B", "kB", "MB", "GB", "TB", "PB", |
27 | "EB", "ZB", "YB", NULL}; | 27 | "EB", "ZB", "YB", NULL}; |
28 | const char *units_2[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", | 28 | static const char *units_2[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", |
29 | "EiB", "ZiB", "YiB", NULL }; | 29 | "EiB", "ZiB", "YiB", NULL }; |
30 | const char **units_str[] = { | 30 | static const char **units_str[] = { |
31 | [STRING_UNITS_10] = units_10, | 31 | [STRING_UNITS_10] = units_10, |
32 | [STRING_UNITS_2] = units_2, | 32 | [STRING_UNITS_2] = units_2, |
33 | }; | 33 | }; |
34 | const unsigned int divisor[] = { | 34 | static const unsigned int divisor[] = { |
35 | [STRING_UNITS_10] = 1000, | 35 | [STRING_UNITS_10] = 1000, |
36 | [STRING_UNITS_2] = 1024, | 36 | [STRING_UNITS_2] = 1024, |
37 | }; | 37 | }; |
diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c new file mode 100644 index 000000000000..bb2b201d6ad0 --- /dev/null +++ b/lib/strncpy_from_user.c | |||
@@ -0,0 +1,113 @@ | |||
1 | #include <linux/module.h> | ||
2 | #include <linux/uaccess.h> | ||
3 | #include <linux/kernel.h> | ||
4 | #include <linux/errno.h> | ||
5 | |||
6 | #include <asm/byteorder.h> | ||
7 | #include <asm/word-at-a-time.h> | ||
8 | |||
9 | #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS | ||
10 | #define IS_UNALIGNED(src, dst) 0 | ||
11 | #else | ||
12 | #define IS_UNALIGNED(src, dst) \ | ||
13 | (((long) dst | (long) src) & (sizeof(long) - 1)) | ||
14 | #endif | ||
15 | |||
16 | /* | ||
17 | * Do a strncpy, return length of string without final '\0'. | ||
18 | * 'count' is the user-supplied count (return 'count' if we | ||
19 | * hit it), 'max' is the address space maximum (and we return | ||
20 | * -EFAULT if we hit it). | ||
21 | */ | ||
22 | static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max) | ||
23 | { | ||
24 | const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; | ||
25 | long res = 0; | ||
26 | |||
27 | /* | ||
28 | * Truncate 'max' to the user-specified limit, so that | ||
29 | * we only have one limit we need to check in the loop | ||
30 | */ | ||
31 | if (max > count) | ||
32 | max = count; | ||
33 | |||
34 | if (IS_UNALIGNED(src, dst)) | ||
35 | goto byte_at_a_time; | ||
36 | |||
37 | while (max >= sizeof(unsigned long)) { | ||
38 | unsigned long c, data; | ||
39 | |||
40 | /* Fall back to byte-at-a-time if we get a page fault */ | ||
41 | if (unlikely(__get_user(c,(unsigned long __user *)(src+res)))) | ||
42 | break; | ||
43 | *(unsigned long *)(dst+res) = c; | ||
44 | if (has_zero(c, &data, &constants)) { | ||
45 | data = prep_zero_mask(c, data, &constants); | ||
46 | data = create_zero_mask(data); | ||
47 | return res + find_zero(data); | ||
48 | } | ||
49 | res += sizeof(unsigned long); | ||
50 | max -= sizeof(unsigned long); | ||
51 | } | ||
52 | |||
53 | byte_at_a_time: | ||
54 | while (max) { | ||
55 | char c; | ||
56 | |||
57 | if (unlikely(__get_user(c,src+res))) | ||
58 | return -EFAULT; | ||
59 | dst[res] = c; | ||
60 | if (!c) | ||
61 | return res; | ||
62 | res++; | ||
63 | max--; | ||
64 | } | ||
65 | |||
66 | /* | ||
67 | * Uhhuh. We hit 'max'. But was that the user-specified maximum | ||
68 | * too? If so, that's ok - we got as much as the user asked for. | ||
69 | */ | ||
70 | if (res >= count) | ||
71 | return res; | ||
72 | |||
73 | /* | ||
74 | * Nope: we hit the address space limit, and we still had more | ||
75 | * characters the caller would have wanted. That's an EFAULT. | ||
76 | */ | ||
77 | return -EFAULT; | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * strncpy_from_user: - Copy a NUL terminated string from userspace. | ||
82 | * @dst: Destination address, in kernel space. This buffer must be at | ||
83 | * least @count bytes long. | ||
84 | * @src: Source address, in user space. | ||
85 | * @count: Maximum number of bytes to copy, including the trailing NUL. | ||
86 | * | ||
87 | * Copies a NUL-terminated string from userspace to kernel space. | ||
88 | * | ||
89 | * On success, returns the length of the string (not including the trailing | ||
90 | * NUL). | ||
91 | * | ||
92 | * If access to userspace fails, returns -EFAULT (some data may have been | ||
93 | * copied). | ||
94 | * | ||
95 | * If @count is smaller than the length of the string, copies @count bytes | ||
96 | * and returns @count. | ||
97 | */ | ||
98 | long strncpy_from_user(char *dst, const char __user *src, long count) | ||
99 | { | ||
100 | unsigned long max_addr, src_addr; | ||
101 | |||
102 | if (unlikely(count <= 0)) | ||
103 | return 0; | ||
104 | |||
105 | max_addr = user_addr_max(); | ||
106 | src_addr = (unsigned long)src; | ||
107 | if (likely(src_addr < max_addr)) { | ||
108 | unsigned long max = max_addr - src_addr; | ||
109 | return do_strncpy_from_user(dst, src, count, max); | ||
110 | } | ||
111 | return -EFAULT; | ||
112 | } | ||
113 | EXPORT_SYMBOL(strncpy_from_user); | ||
diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c new file mode 100644 index 000000000000..a28df5206d95 --- /dev/null +++ b/lib/strnlen_user.c | |||
@@ -0,0 +1,138 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/export.h> | ||
3 | #include <linux/uaccess.h> | ||
4 | |||
5 | #include <asm/word-at-a-time.h> | ||
6 | |||
7 | /* Set bits in the first 'n' bytes when loaded from memory */ | ||
8 | #ifdef __LITTLE_ENDIAN | ||
9 | # define aligned_byte_mask(n) ((1ul << 8*(n))-1) | ||
10 | #else | ||
11 | # define aligned_byte_mask(n) (~0xfful << (BITS_PER_LONG - 8 - 8*(n))) | ||
12 | #endif | ||
13 | |||
14 | /* | ||
15 | * Do a strnlen, return length of string *with* final '\0'. | ||
16 | * 'count' is the user-supplied count, while 'max' is the | ||
17 | * address space maximum. | ||
18 | * | ||
19 | * Return 0 for exceptions (which includes hitting the address | ||
20 | * space maximum), or 'count+1' if hitting the user-supplied | ||
21 | * maximum count. | ||
22 | * | ||
23 | * NOTE! We can sometimes overshoot the user-supplied maximum | ||
24 | * if it fits in a aligned 'long'. The caller needs to check | ||
25 | * the return value against "> max". | ||
26 | */ | ||
27 | static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max) | ||
28 | { | ||
29 | const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; | ||
30 | long align, res = 0; | ||
31 | unsigned long c; | ||
32 | |||
33 | /* | ||
34 | * Truncate 'max' to the user-specified limit, so that | ||
35 | * we only have one limit we need to check in the loop | ||
36 | */ | ||
37 | if (max > count) | ||
38 | max = count; | ||
39 | |||
40 | /* | ||
41 | * Do everything aligned. But that means that we | ||
42 | * need to also expand the maximum.. | ||
43 | */ | ||
44 | align = (sizeof(long) - 1) & (unsigned long)src; | ||
45 | src -= align; | ||
46 | max += align; | ||
47 | |||
48 | if (unlikely(__get_user(c,(unsigned long __user *)src))) | ||
49 | return 0; | ||
50 | c |= aligned_byte_mask(align); | ||
51 | |||
52 | for (;;) { | ||
53 | unsigned long data; | ||
54 | if (has_zero(c, &data, &constants)) { | ||
55 | data = prep_zero_mask(c, data, &constants); | ||
56 | data = create_zero_mask(data); | ||
57 | return res + find_zero(data) + 1 - align; | ||
58 | } | ||
59 | res += sizeof(unsigned long); | ||
60 | if (unlikely(max < sizeof(unsigned long))) | ||
61 | break; | ||
62 | max -= sizeof(unsigned long); | ||
63 | if (unlikely(__get_user(c,(unsigned long __user *)(src+res)))) | ||
64 | return 0; | ||
65 | } | ||
66 | res -= align; | ||
67 | |||
68 | /* | ||
69 | * Uhhuh. We hit 'max'. But was that the user-specified maximum | ||
70 | * too? If so, return the marker for "too long". | ||
71 | */ | ||
72 | if (res >= count) | ||
73 | return count+1; | ||
74 | |||
75 | /* | ||
76 | * Nope: we hit the address space limit, and we still had more | ||
77 | * characters the caller would have wanted. That's 0. | ||
78 | */ | ||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | /** | ||
83 | * strnlen_user: - Get the size of a user string INCLUDING final NUL. | ||
84 | * @str: The string to measure. | ||
85 | * @count: Maximum count (including NUL character) | ||
86 | * | ||
87 | * Context: User context only. This function may sleep. | ||
88 | * | ||
89 | * Get the size of a NUL-terminated string in user space. | ||
90 | * | ||
91 | * Returns the size of the string INCLUDING the terminating NUL. | ||
92 | * If the string is too long, returns 'count+1'. | ||
93 | * On exception (or invalid count), returns 0. | ||
94 | */ | ||
95 | long strnlen_user(const char __user *str, long count) | ||
96 | { | ||
97 | unsigned long max_addr, src_addr; | ||
98 | |||
99 | if (unlikely(count <= 0)) | ||
100 | return 0; | ||
101 | |||
102 | max_addr = user_addr_max(); | ||
103 | src_addr = (unsigned long)str; | ||
104 | if (likely(src_addr < max_addr)) { | ||
105 | unsigned long max = max_addr - src_addr; | ||
106 | return do_strnlen_user(str, count, max); | ||
107 | } | ||
108 | return 0; | ||
109 | } | ||
110 | EXPORT_SYMBOL(strnlen_user); | ||
111 | |||
112 | /** | ||
113 | * strlen_user: - Get the size of a user string INCLUDING final NUL. | ||
114 | * @str: The string to measure. | ||
115 | * | ||
116 | * Context: User context only. This function may sleep. | ||
117 | * | ||
118 | * Get the size of a NUL-terminated string in user space. | ||
119 | * | ||
120 | * Returns the size of the string INCLUDING the terminating NUL. | ||
121 | * On exception, returns 0. | ||
122 | * | ||
123 | * If there is a limit on the length of a valid string, you may wish to | ||
124 | * consider using strnlen_user() instead. | ||
125 | */ | ||
126 | long strlen_user(const char __user *str) | ||
127 | { | ||
128 | unsigned long max_addr, src_addr; | ||
129 | |||
130 | max_addr = user_addr_max(); | ||
131 | src_addr = (unsigned long)str; | ||
132 | if (likely(src_addr < max_addr)) { | ||
133 | unsigned long max = max_addr - src_addr; | ||
134 | return do_strnlen_user(str, ~0ul, max); | ||
135 | } | ||
136 | return 0; | ||
137 | } | ||
138 | EXPORT_SYMBOL(strlen_user); | ||
diff --git a/lib/swiotlb.c b/lib/swiotlb.c index 414f46ed1dcd..45bc1f83a5ad 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c | |||
@@ -130,11 +130,9 @@ void swiotlb_print_info(void) | |||
130 | pstart = virt_to_phys(io_tlb_start); | 130 | pstart = virt_to_phys(io_tlb_start); |
131 | pend = virt_to_phys(io_tlb_end); | 131 | pend = virt_to_phys(io_tlb_end); |
132 | 132 | ||
133 | printk(KERN_INFO "Placing %luMB software IO TLB between %p - %p\n", | 133 | printk(KERN_INFO "software IO TLB [mem %#010llx-%#010llx] (%luMB) mapped at [%p-%p]\n", |
134 | bytes >> 20, io_tlb_start, io_tlb_end); | 134 | (unsigned long long)pstart, (unsigned long long)pend - 1, |
135 | printk(KERN_INFO "software IO TLB at phys %#llx - %#llx\n", | 135 | bytes >> 20, io_tlb_start, io_tlb_end - 1); |
136 | (unsigned long long)pstart, | ||
137 | (unsigned long long)pend); | ||
138 | } | 136 | } |
139 | 137 | ||
140 | void __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) | 138 | void __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) |
diff --git a/lib/test-kstrtox.c b/lib/test-kstrtox.c index d55769d63cb8..bea3f3fa3f02 100644 --- a/lib/test-kstrtox.c +++ b/lib/test-kstrtox.c | |||
@@ -11,7 +11,7 @@ struct test_fail { | |||
11 | }; | 11 | }; |
12 | 12 | ||
13 | #define DEFINE_TEST_FAIL(test) \ | 13 | #define DEFINE_TEST_FAIL(test) \ |
14 | const struct test_fail test[] __initdata | 14 | const struct test_fail test[] __initconst |
15 | 15 | ||
16 | #define DECLARE_TEST_OK(type, test_type) \ | 16 | #define DECLARE_TEST_OK(type, test_type) \ |
17 | test_type { \ | 17 | test_type { \ |
@@ -21,7 +21,7 @@ struct test_fail { | |||
21 | } | 21 | } |
22 | 22 | ||
23 | #define DEFINE_TEST_OK(type, test) \ | 23 | #define DEFINE_TEST_OK(type, test) \ |
24 | const type test[] __initdata | 24 | const type test[] __initconst |
25 | 25 | ||
26 | #define TEST_FAIL(fn, type, fmt, test) \ | 26 | #define TEST_FAIL(fn, type, fmt, test) \ |
27 | { \ | 27 | { \ |
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index abbabec9720a..5391299c1e78 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -284,6 +284,7 @@ char *number(char *buf, char *end, unsigned long long num, | |||
284 | char locase; | 284 | char locase; |
285 | int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10); | 285 | int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10); |
286 | int i; | 286 | int i; |
287 | bool is_zero = num == 0LL; | ||
287 | 288 | ||
288 | /* locase = 0 or 0x20. ORing digits or letters with 'locase' | 289 | /* locase = 0 or 0x20. ORing digits or letters with 'locase' |
289 | * produces same digits or (maybe lowercased) letters */ | 290 | * produces same digits or (maybe lowercased) letters */ |
@@ -305,8 +306,9 @@ char *number(char *buf, char *end, unsigned long long num, | |||
305 | } | 306 | } |
306 | } | 307 | } |
307 | if (need_pfx) { | 308 | if (need_pfx) { |
308 | spec.field_width--; | ||
309 | if (spec.base == 16) | 309 | if (spec.base == 16) |
310 | spec.field_width -= 2; | ||
311 | else if (!is_zero) | ||
310 | spec.field_width--; | 312 | spec.field_width--; |
311 | } | 313 | } |
312 | 314 | ||
@@ -353,9 +355,11 @@ char *number(char *buf, char *end, unsigned long long num, | |||
353 | } | 355 | } |
354 | /* "0x" / "0" prefix */ | 356 | /* "0x" / "0" prefix */ |
355 | if (need_pfx) { | 357 | if (need_pfx) { |
356 | if (buf < end) | 358 | if (spec.base == 16 || !is_zero) { |
357 | *buf = '0'; | 359 | if (buf < end) |
358 | ++buf; | 360 | *buf = '0'; |
361 | ++buf; | ||
362 | } | ||
359 | if (spec.base == 16) { | 363 | if (spec.base == 16) { |
360 | if (buf < end) | 364 | if (buf < end) |
361 | *buf = ('X' | locase); | 365 | *buf = ('X' | locase); |
@@ -436,7 +440,7 @@ char *symbol_string(char *buf, char *end, void *ptr, | |||
436 | else if (ext != 'f' && ext != 's') | 440 | else if (ext != 'f' && ext != 's') |
437 | sprint_symbol(sym, value); | 441 | sprint_symbol(sym, value); |
438 | else | 442 | else |
439 | kallsyms_lookup(value, NULL, NULL, NULL, sym); | 443 | sprint_symbol_no_offset(sym, value); |
440 | 444 | ||
441 | return string(buf, end, sym, spec); | 445 | return string(buf, end, sym, spec); |
442 | #else | 446 | #else |