diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 3 | ||||
-rw-r--r-- | lib/Kconfig.debug | 25 | ||||
-rw-r--r-- | lib/Makefile | 7 | ||||
-rw-r--r-- | lib/argv_split.c | 87 | ||||
-rw-r--r-- | lib/decompress.c | 2 | ||||
-rw-r--r-- | lib/div64.c | 19 | ||||
-rw-r--r-- | lib/dump_stack.c | 11 | ||||
-rw-r--r-- | lib/dynamic_debug.c | 49 | ||||
-rw-r--r-- | lib/fault-inject.c | 2 | ||||
-rw-r--r-- | lib/genalloc.c | 81 | ||||
-rw-r--r-- | lib/idr.c | 27 | ||||
-rw-r--r-- | lib/int_sqrt.c | 32 | ||||
-rw-r--r-- | lib/kobject.c | 9 | ||||
-rw-r--r-- | lib/list_sort.c | 2 | ||||
-rw-r--r-- | lib/rbtree_test.c | 9 | ||||
-rw-r--r-- | lib/show_mem.c | 3 | ||||
-rw-r--r-- | lib/string_helpers.c | 133 | ||||
-rw-r--r-- | lib/swiotlb.c | 19 | ||||
-rw-r--r-- | lib/test-string_helpers.c | 103 | ||||
-rw-r--r-- | lib/ucs2_string.c | 51 | ||||
-rw-r--r-- | lib/usercopy.c | 9 | ||||
-rw-r--r-- | lib/uuid.c | 8 | ||||
-rw-r--r-- | lib/vsprintf.c | 18 |
23 files changed, 569 insertions, 140 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index 3958dc4389f9..fe01d418b09a 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
@@ -404,4 +404,7 @@ config OID_REGISTRY | |||
404 | help | 404 | help |
405 | Enable fast lookup object identifier registry. | 405 | Enable fast lookup object identifier registry. |
406 | 406 | ||
407 | config UCS2_STRING | ||
408 | tristate | ||
409 | |||
407 | endmenu | 410 | endmenu |
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 28be08c09bab..566cf2bc08ea 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
@@ -1192,7 +1192,7 @@ config MEMORY_NOTIFIER_ERROR_INJECT | |||
1192 | bash: echo: write error: Cannot allocate memory | 1192 | bash: echo: write error: Cannot allocate memory |
1193 | 1193 | ||
1194 | To compile this code as a module, choose M here: the module will | 1194 | To compile this code as a module, choose M here: the module will |
1195 | be called pSeries-reconfig-notifier-error-inject. | 1195 | be called memory-notifier-error-inject. |
1196 | 1196 | ||
1197 | If unsure, say N. | 1197 | If unsure, say N. |
1198 | 1198 | ||
@@ -1209,7 +1209,7 @@ config OF_RECONFIG_NOTIFIER_ERROR_INJECT | |||
1209 | notified, write the error code to "actions/<notifier event>/error". | 1209 | notified, write the error code to "actions/<notifier event>/error". |
1210 | 1210 | ||
1211 | To compile this code as a module, choose M here: the module will | 1211 | To compile this code as a module, choose M here: the module will |
1212 | be called memory-notifier-error-inject. | 1212 | be called of-reconfig-notifier-error-inject. |
1213 | 1213 | ||
1214 | If unsure, say N. | 1214 | If unsure, say N. |
1215 | 1215 | ||
@@ -1292,6 +1292,24 @@ config LATENCYTOP | |||
1292 | Enable this option if you want to use the LatencyTOP tool | 1292 | Enable this option if you want to use the LatencyTOP tool |
1293 | to find out which userspace is blocking on what kernel operations. | 1293 | to find out which userspace is blocking on what kernel operations. |
1294 | 1294 | ||
1295 | config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS | ||
1296 | bool | ||
1297 | |||
1298 | config DEBUG_STRICT_USER_COPY_CHECKS | ||
1299 | bool "Strict user copy size checks" | ||
1300 | depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS | ||
1301 | depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING | ||
1302 | help | ||
1303 | Enabling this option turns a certain set of sanity checks for user | ||
1304 | copy operations into compile time failures. | ||
1305 | |||
1306 | The copy_from_user() etc checks are there to help test if there | ||
1307 | are sufficient security checks on the length argument of | ||
1308 | the copy operation, by having gcc prove that the argument is | ||
1309 | within bounds. | ||
1310 | |||
1311 | If unsure, say N. | ||
1312 | |||
1295 | source mm/Kconfig.debug | 1313 | source mm/Kconfig.debug |
1296 | source kernel/trace/Kconfig | 1314 | source kernel/trace/Kconfig |
1297 | 1315 | ||
@@ -1463,5 +1481,8 @@ source "lib/Kconfig.kgdb" | |||
1463 | 1481 | ||
1464 | source "lib/Kconfig.kmemcheck" | 1482 | source "lib/Kconfig.kmemcheck" |
1465 | 1483 | ||
1484 | config TEST_STRING_HELPERS | ||
1485 | tristate "Test functions located in the string_helpers module at runtime" | ||
1486 | |||
1466 | config TEST_KSTRTOX | 1487 | config TEST_KSTRTOX |
1467 | tristate "Test kstrto*() family of functions at runtime" | 1488 | tristate "Test kstrto*() family of functions at runtime" |
diff --git a/lib/Makefile b/lib/Makefile index d7946ff75b2e..e9c52e1b853a 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -15,6 +15,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ | |||
15 | is_single_threaded.o plist.o decompress.o kobject_uevent.o \ | 15 | is_single_threaded.o plist.o decompress.o kobject_uevent.o \ |
16 | earlycpio.o | 16 | earlycpio.o |
17 | 17 | ||
18 | obj-$(CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o | ||
18 | lib-$(CONFIG_MMU) += ioremap.o | 19 | lib-$(CONFIG_MMU) += ioremap.o |
19 | lib-$(CONFIG_SMP) += cpumask.o | 20 | lib-$(CONFIG_SMP) += cpumask.o |
20 | 21 | ||
@@ -22,8 +23,10 @@ lib-y += kobject.o klist.o | |||
22 | 23 | ||
23 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | 24 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
24 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ | 25 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ |
25 | string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o \ | 26 | gcd.o lcm.o list_sort.o uuid.o flex_array.o \ |
26 | bsearch.o find_last_bit.o find_next_bit.o llist.o memweight.o kfifo.o | 27 | bsearch.o find_last_bit.o find_next_bit.o llist.o memweight.o kfifo.o |
28 | obj-y += string_helpers.o | ||
29 | obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o | ||
27 | obj-y += kstrtox.o | 30 | obj-y += kstrtox.o |
28 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o | 31 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o |
29 | 32 | ||
@@ -174,3 +177,5 @@ quiet_cmd_build_OID_registry = GEN $@ | |||
174 | cmd_build_OID_registry = perl $(srctree)/$(src)/build_OID_registry $< $@ | 177 | cmd_build_OID_registry = perl $(srctree)/$(src)/build_OID_registry $< $@ |
175 | 178 | ||
176 | clean-files += oid_registry_data.c | 179 | clean-files += oid_registry_data.c |
180 | |||
181 | obj-$(CONFIG_UCS2_STRING) += ucs2_string.o | ||
diff --git a/lib/argv_split.c b/lib/argv_split.c index 1e9a6cbc3689..e927ed0e18a8 100644 --- a/lib/argv_split.c +++ b/lib/argv_split.c | |||
@@ -8,23 +8,17 @@ | |||
8 | #include <linux/slab.h> | 8 | #include <linux/slab.h> |
9 | #include <linux/export.h> | 9 | #include <linux/export.h> |
10 | 10 | ||
11 | static const char *skip_arg(const char *cp) | ||
12 | { | ||
13 | while (*cp && !isspace(*cp)) | ||
14 | cp++; | ||
15 | |||
16 | return cp; | ||
17 | } | ||
18 | |||
19 | static int count_argc(const char *str) | 11 | static int count_argc(const char *str) |
20 | { | 12 | { |
21 | int count = 0; | 13 | int count = 0; |
14 | bool was_space; | ||
22 | 15 | ||
23 | while (*str) { | 16 | for (was_space = true; *str; str++) { |
24 | str = skip_spaces(str); | 17 | if (isspace(*str)) { |
25 | if (*str) { | 18 | was_space = true; |
19 | } else if (was_space) { | ||
20 | was_space = false; | ||
26 | count++; | 21 | count++; |
27 | str = skip_arg(str); | ||
28 | } | 22 | } |
29 | } | 23 | } |
30 | 24 | ||
@@ -39,10 +33,8 @@ static int count_argc(const char *str) | |||
39 | */ | 33 | */ |
40 | void argv_free(char **argv) | 34 | void argv_free(char **argv) |
41 | { | 35 | { |
42 | char **p; | 36 | argv--; |
43 | for (p = argv; *p; p++) | 37 | kfree(argv[0]); |
44 | kfree(*p); | ||
45 | |||
46 | kfree(argv); | 38 | kfree(argv); |
47 | } | 39 | } |
48 | EXPORT_SYMBOL(argv_free); | 40 | EXPORT_SYMBOL(argv_free); |
@@ -59,43 +51,44 @@ EXPORT_SYMBOL(argv_free); | |||
59 | * considered to be a single argument separator. The returned array | 51 | * considered to be a single argument separator. The returned array |
60 | * is always NULL-terminated. Returns NULL on memory allocation | 52 | * is always NULL-terminated. Returns NULL on memory allocation |
61 | * failure. | 53 | * failure. |
54 | * | ||
55 | * The source string at `str' may be undergoing concurrent alteration via | ||
56 | * userspace sysctl activity (at least). The argv_split() implementation | ||
57 | * attempts to handle this gracefully by taking a local copy to work on. | ||
62 | */ | 58 | */ |
63 | char **argv_split(gfp_t gfp, const char *str, int *argcp) | 59 | char **argv_split(gfp_t gfp, const char *str, int *argcp) |
64 | { | 60 | { |
65 | int argc = count_argc(str); | 61 | char *argv_str; |
66 | char **argv = kzalloc(sizeof(*argv) * (argc+1), gfp); | 62 | bool was_space; |
67 | char **argvp; | 63 | char **argv, **argv_ret; |
68 | 64 | int argc; | |
69 | if (argv == NULL) | 65 | |
70 | goto out; | 66 | argv_str = kstrndup(str, KMALLOC_MAX_SIZE - 1, gfp); |
71 | 67 | if (!argv_str) | |
72 | if (argcp) | 68 | return NULL; |
73 | *argcp = argc; | 69 | |
74 | 70 | argc = count_argc(argv_str); | |
75 | argvp = argv; | 71 | argv = kmalloc(sizeof(*argv) * (argc + 2), gfp); |
76 | 72 | if (!argv) { | |
77 | while (*str) { | 73 | kfree(argv_str); |
78 | str = skip_spaces(str); | 74 | return NULL; |
79 | 75 | } | |
80 | if (*str) { | ||
81 | const char *p = str; | ||
82 | char *t; | ||
83 | |||
84 | str = skip_arg(str); | ||
85 | 76 | ||
86 | t = kstrndup(p, str-p, gfp); | 77 | *argv = argv_str; |
87 | if (t == NULL) | 78 | argv_ret = ++argv; |
88 | goto fail; | 79 | for (was_space = true; *argv_str; argv_str++) { |
89 | *argvp++ = t; | 80 | if (isspace(*argv_str)) { |
81 | was_space = true; | ||
82 | *argv_str = 0; | ||
83 | } else if (was_space) { | ||
84 | was_space = false; | ||
85 | *argv++ = argv_str; | ||
90 | } | 86 | } |
91 | } | 87 | } |
92 | *argvp = NULL; | 88 | *argv = NULL; |
93 | |||
94 | out: | ||
95 | return argv; | ||
96 | 89 | ||
97 | fail: | 90 | if (argcp) |
98 | argv_free(argv); | 91 | *argcp = argc; |
99 | return NULL; | 92 | return argv_ret; |
100 | } | 93 | } |
101 | EXPORT_SYMBOL(argv_split); | 94 | EXPORT_SYMBOL(argv_split); |
diff --git a/lib/decompress.c b/lib/decompress.c index 31a804277282..f8fdedaf7b3d 100644 --- a/lib/decompress.c +++ b/lib/decompress.c | |||
@@ -38,7 +38,7 @@ struct compress_format { | |||
38 | decompress_fn decompressor; | 38 | decompress_fn decompressor; |
39 | }; | 39 | }; |
40 | 40 | ||
41 | static const struct compress_format compressed_formats[] __initdata = { | 41 | static const struct compress_format compressed_formats[] __initconst = { |
42 | { {037, 0213}, "gzip", gunzip }, | 42 | { {037, 0213}, "gzip", gunzip }, |
43 | { {037, 0236}, "gzip", gunzip }, | 43 | { {037, 0236}, "gzip", gunzip }, |
44 | { {0x42, 0x5a}, "bzip2", bunzip2 }, | 44 | { {0x42, 0x5a}, "bzip2", bunzip2 }, |
diff --git a/lib/div64.c b/lib/div64.c index a163b6caef73..3af5728d95fd 100644 --- a/lib/div64.c +++ b/lib/div64.c | |||
@@ -79,9 +79,10 @@ EXPORT_SYMBOL(div_s64_rem); | |||
79 | #endif | 79 | #endif |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * div64_u64 - unsigned 64bit divide with 64bit divisor | 82 | * div64_u64_rem - unsigned 64bit divide with 64bit divisor and 64bit remainder |
83 | * @dividend: 64bit dividend | 83 | * @dividend: 64bit dividend |
84 | * @divisor: 64bit divisor | 84 | * @divisor: 64bit divisor |
85 | * @remainder: 64bit remainder | ||
85 | * | 86 | * |
86 | * This implementation is a modified version of the algorithm proposed | 87 | * This implementation is a modified version of the algorithm proposed |
87 | * by the book 'Hacker's Delight'. The original source and full proof | 88 | * by the book 'Hacker's Delight'. The original source and full proof |
@@ -89,27 +90,33 @@ EXPORT_SYMBOL(div_s64_rem); | |||
89 | * | 90 | * |
90 | * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt' | 91 | * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt' |
91 | */ | 92 | */ |
92 | #ifndef div64_u64 | 93 | #ifndef div64_u64_rem |
93 | u64 div64_u64(u64 dividend, u64 divisor) | 94 | u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder) |
94 | { | 95 | { |
95 | u32 high = divisor >> 32; | 96 | u32 high = divisor >> 32; |
96 | u64 quot; | 97 | u64 quot; |
97 | 98 | ||
98 | if (high == 0) { | 99 | if (high == 0) { |
99 | quot = div_u64(dividend, divisor); | 100 | u32 rem32; |
101 | quot = div_u64_rem(dividend, divisor, &rem32); | ||
102 | *remainder = rem32; | ||
100 | } else { | 103 | } else { |
101 | int n = 1 + fls(high); | 104 | int n = 1 + fls(high); |
102 | quot = div_u64(dividend >> n, divisor >> n); | 105 | quot = div_u64(dividend >> n, divisor >> n); |
103 | 106 | ||
104 | if (quot != 0) | 107 | if (quot != 0) |
105 | quot--; | 108 | quot--; |
106 | if ((dividend - quot * divisor) >= divisor) | 109 | |
110 | *remainder = dividend - quot * divisor; | ||
111 | if (*remainder >= divisor) { | ||
107 | quot++; | 112 | quot++; |
113 | *remainder -= divisor; | ||
114 | } | ||
108 | } | 115 | } |
109 | 116 | ||
110 | return quot; | 117 | return quot; |
111 | } | 118 | } |
112 | EXPORT_SYMBOL(div64_u64); | 119 | EXPORT_SYMBOL(div64_u64_rem); |
113 | #endif | 120 | #endif |
114 | 121 | ||
115 | /** | 122 | /** |
diff --git a/lib/dump_stack.c b/lib/dump_stack.c index 42f4f55c9458..53bad099ebd6 100644 --- a/lib/dump_stack.c +++ b/lib/dump_stack.c | |||
@@ -5,11 +5,16 @@ | |||
5 | 5 | ||
6 | #include <linux/kernel.h> | 6 | #include <linux/kernel.h> |
7 | #include <linux/export.h> | 7 | #include <linux/export.h> |
8 | #include <linux/sched.h> | ||
8 | 9 | ||
10 | /** | ||
11 | * dump_stack - dump the current task information and its stack trace | ||
12 | * | ||
13 | * Architectures can override this implementation by implementing its own. | ||
14 | */ | ||
9 | void dump_stack(void) | 15 | void dump_stack(void) |
10 | { | 16 | { |
11 | printk(KERN_NOTICE | 17 | dump_stack_print_info(KERN_DEFAULT); |
12 | "This architecture does not implement dump_stack()\n"); | 18 | show_stack(NULL, NULL); |
13 | } | 19 | } |
14 | |||
15 | EXPORT_SYMBOL(dump_stack); | 20 | EXPORT_SYMBOL(dump_stack); |
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 5276b99ca650..99fec3ae405a 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/sysctl.h> | 24 | #include <linux/sysctl.h> |
25 | #include <linux/ctype.h> | 25 | #include <linux/ctype.h> |
26 | #include <linux/string.h> | 26 | #include <linux/string.h> |
27 | #include <linux/string_helpers.h> | ||
27 | #include <linux/uaccess.h> | 28 | #include <linux/uaccess.h> |
28 | #include <linux/dynamic_debug.h> | 29 | #include <linux/dynamic_debug.h> |
29 | #include <linux/debugfs.h> | 30 | #include <linux/debugfs.h> |
@@ -276,48 +277,6 @@ static inline int parse_lineno(const char *str, unsigned int *val) | |||
276 | return 0; | 277 | return 0; |
277 | } | 278 | } |
278 | 279 | ||
279 | /* | ||
280 | * Undo octal escaping in a string, inplace. This is useful to | ||
281 | * allow the user to express a query which matches a format | ||
282 | * containing embedded spaces. | ||
283 | */ | ||
284 | #define isodigit(c) ((c) >= '0' && (c) <= '7') | ||
285 | static char *unescape(char *str) | ||
286 | { | ||
287 | char *in = str; | ||
288 | char *out = str; | ||
289 | |||
290 | while (*in) { | ||
291 | if (*in == '\\') { | ||
292 | if (in[1] == '\\') { | ||
293 | *out++ = '\\'; | ||
294 | in += 2; | ||
295 | continue; | ||
296 | } else if (in[1] == 't') { | ||
297 | *out++ = '\t'; | ||
298 | in += 2; | ||
299 | continue; | ||
300 | } else if (in[1] == 'n') { | ||
301 | *out++ = '\n'; | ||
302 | in += 2; | ||
303 | continue; | ||
304 | } else if (isodigit(in[1]) && | ||
305 | isodigit(in[2]) && | ||
306 | isodigit(in[3])) { | ||
307 | *out++ = (((in[1] - '0') << 6) | | ||
308 | ((in[2] - '0') << 3) | | ||
309 | (in[3] - '0')); | ||
310 | in += 4; | ||
311 | continue; | ||
312 | } | ||
313 | } | ||
314 | *out++ = *in++; | ||
315 | } | ||
316 | *out = '\0'; | ||
317 | |||
318 | return str; | ||
319 | } | ||
320 | |||
321 | static int check_set(const char **dest, char *src, char *name) | 280 | static int check_set(const char **dest, char *src, char *name) |
322 | { | 281 | { |
323 | int rc = 0; | 282 | int rc = 0; |
@@ -371,8 +330,10 @@ static int ddebug_parse_query(char *words[], int nwords, | |||
371 | } else if (!strcmp(words[i], "module")) { | 330 | } else if (!strcmp(words[i], "module")) { |
372 | rc = check_set(&query->module, words[i+1], "module"); | 331 | rc = check_set(&query->module, words[i+1], "module"); |
373 | } else if (!strcmp(words[i], "format")) { | 332 | } else if (!strcmp(words[i], "format")) { |
374 | rc = check_set(&query->format, unescape(words[i+1]), | 333 | string_unescape_inplace(words[i+1], UNESCAPE_SPACE | |
375 | "format"); | 334 | UNESCAPE_OCTAL | |
335 | UNESCAPE_SPECIAL); | ||
336 | rc = check_set(&query->format, words[i+1], "format"); | ||
376 | } else if (!strcmp(words[i], "line")) { | 337 | } else if (!strcmp(words[i], "line")) { |
377 | char *first = words[i+1]; | 338 | char *first = words[i+1]; |
378 | char *last = strchr(first, '-'); | 339 | char *last = strchr(first, '-'); |
diff --git a/lib/fault-inject.c b/lib/fault-inject.c index f7210ad6cffd..c5c7a762b850 100644 --- a/lib/fault-inject.c +++ b/lib/fault-inject.c | |||
@@ -122,7 +122,7 @@ bool should_fail(struct fault_attr *attr, ssize_t size) | |||
122 | return false; | 122 | return false; |
123 | } | 123 | } |
124 | 124 | ||
125 | if (attr->probability <= random32() % 100) | 125 | if (attr->probability <= prandom_u32() % 100) |
126 | return false; | 126 | return false; |
127 | 127 | ||
128 | if (!fail_stacktrace(attr)) | 128 | if (!fail_stacktrace(attr)) |
diff --git a/lib/genalloc.c b/lib/genalloc.c index 54920433705a..b35cfa9bc3d4 100644 --- a/lib/genalloc.c +++ b/lib/genalloc.c | |||
@@ -34,6 +34,8 @@ | |||
34 | #include <linux/rculist.h> | 34 | #include <linux/rculist.h> |
35 | #include <linux/interrupt.h> | 35 | #include <linux/interrupt.h> |
36 | #include <linux/genalloc.h> | 36 | #include <linux/genalloc.h> |
37 | #include <linux/of_address.h> | ||
38 | #include <linux/of_device.h> | ||
37 | 39 | ||
38 | static int set_bits_ll(unsigned long *addr, unsigned long mask_to_set) | 40 | static int set_bits_ll(unsigned long *addr, unsigned long mask_to_set) |
39 | { | 41 | { |
@@ -480,3 +482,82 @@ unsigned long gen_pool_best_fit(unsigned long *map, unsigned long size, | |||
480 | return start_bit; | 482 | return start_bit; |
481 | } | 483 | } |
482 | EXPORT_SYMBOL(gen_pool_best_fit); | 484 | EXPORT_SYMBOL(gen_pool_best_fit); |
485 | |||
486 | static void devm_gen_pool_release(struct device *dev, void *res) | ||
487 | { | ||
488 | gen_pool_destroy(*(struct gen_pool **)res); | ||
489 | } | ||
490 | |||
491 | /** | ||
492 | * devm_gen_pool_create - managed gen_pool_create | ||
493 | * @dev: device that provides the gen_pool | ||
494 | * @min_alloc_order: log base 2 of number of bytes each bitmap bit represents | ||
495 | * @nid: node id of the node the pool structure should be allocated on, or -1 | ||
496 | * | ||
497 | * Create a new special memory pool that can be used to manage special purpose | ||
498 | * memory not managed by the regular kmalloc/kfree interface. The pool will be | ||
499 | * automatically destroyed by the device management code. | ||
500 | */ | ||
501 | struct gen_pool *devm_gen_pool_create(struct device *dev, int min_alloc_order, | ||
502 | int nid) | ||
503 | { | ||
504 | struct gen_pool **ptr, *pool; | ||
505 | |||
506 | ptr = devres_alloc(devm_gen_pool_release, sizeof(*ptr), GFP_KERNEL); | ||
507 | |||
508 | pool = gen_pool_create(min_alloc_order, nid); | ||
509 | if (pool) { | ||
510 | *ptr = pool; | ||
511 | devres_add(dev, ptr); | ||
512 | } else { | ||
513 | devres_free(ptr); | ||
514 | } | ||
515 | |||
516 | return pool; | ||
517 | } | ||
518 | |||
519 | /** | ||
520 | * dev_get_gen_pool - Obtain the gen_pool (if any) for a device | ||
521 | * @dev: device to retrieve the gen_pool from | ||
522 | * @name: Optional name for the gen_pool, usually NULL | ||
523 | * | ||
524 | * Returns the gen_pool for the device if one is present, or NULL. | ||
525 | */ | ||
526 | struct gen_pool *dev_get_gen_pool(struct device *dev) | ||
527 | { | ||
528 | struct gen_pool **p = devres_find(dev, devm_gen_pool_release, NULL, | ||
529 | NULL); | ||
530 | |||
531 | if (!p) | ||
532 | return NULL; | ||
533 | return *p; | ||
534 | } | ||
535 | EXPORT_SYMBOL_GPL(dev_get_gen_pool); | ||
536 | |||
537 | #ifdef CONFIG_OF | ||
538 | /** | ||
539 | * of_get_named_gen_pool - find a pool by phandle property | ||
540 | * @np: device node | ||
541 | * @propname: property name containing phandle(s) | ||
542 | * @index: index into the phandle array | ||
543 | * | ||
544 | * Returns the pool that contains the chunk starting at the physical | ||
545 | * address of the device tree node pointed at by the phandle property, | ||
546 | * or NULL if not found. | ||
547 | */ | ||
548 | struct gen_pool *of_get_named_gen_pool(struct device_node *np, | ||
549 | const char *propname, int index) | ||
550 | { | ||
551 | struct platform_device *pdev; | ||
552 | struct device_node *np_pool; | ||
553 | |||
554 | np_pool = of_parse_phandle(np, propname, index); | ||
555 | if (!np_pool) | ||
556 | return NULL; | ||
557 | pdev = of_find_device_by_node(np_pool); | ||
558 | if (!pdev) | ||
559 | return NULL; | ||
560 | return dev_get_gen_pool(&pdev->dev); | ||
561 | } | ||
562 | EXPORT_SYMBOL_GPL(of_get_named_gen_pool); | ||
563 | #endif /* CONFIG_OF */ | ||
@@ -495,6 +495,33 @@ int idr_alloc(struct idr *idr, void *ptr, int start, int end, gfp_t gfp_mask) | |||
495 | } | 495 | } |
496 | EXPORT_SYMBOL_GPL(idr_alloc); | 496 | EXPORT_SYMBOL_GPL(idr_alloc); |
497 | 497 | ||
498 | /** | ||
499 | * idr_alloc_cyclic - allocate new idr entry in a cyclical fashion | ||
500 | * @idr: the (initialized) idr | ||
501 | * @ptr: pointer to be associated with the new id | ||
502 | * @start: the minimum id (inclusive) | ||
503 | * @end: the maximum id (exclusive, <= 0 for max) | ||
504 | * @gfp_mask: memory allocation flags | ||
505 | * | ||
506 | * Essentially the same as idr_alloc, but prefers to allocate progressively | ||
507 | * higher ids if it can. If the "cur" counter wraps, then it will start again | ||
508 | * at the "start" end of the range and allocate one that has already been used. | ||
509 | */ | ||
510 | int idr_alloc_cyclic(struct idr *idr, void *ptr, int start, int end, | ||
511 | gfp_t gfp_mask) | ||
512 | { | ||
513 | int id; | ||
514 | |||
515 | id = idr_alloc(idr, ptr, max(start, idr->cur), end, gfp_mask); | ||
516 | if (id == -ENOSPC) | ||
517 | id = idr_alloc(idr, ptr, start, end, gfp_mask); | ||
518 | |||
519 | if (likely(id >= 0)) | ||
520 | idr->cur = id + 1; | ||
521 | return id; | ||
522 | } | ||
523 | EXPORT_SYMBOL(idr_alloc_cyclic); | ||
524 | |||
498 | static void idr_remove_warning(int id) | 525 | static void idr_remove_warning(int id) |
499 | { | 526 | { |
500 | printk(KERN_WARNING | 527 | printk(KERN_WARNING |
diff --git a/lib/int_sqrt.c b/lib/int_sqrt.c index fc2eeb7cb2ea..1ef4cc344977 100644 --- a/lib/int_sqrt.c +++ b/lib/int_sqrt.c | |||
@@ -1,3 +1,9 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2013 Davidlohr Bueso <davidlohr.bueso@hp.com> | ||
3 | * | ||
4 | * Based on the shift-and-subtract algorithm for computing integer | ||
5 | * square root from Guy L. Steele. | ||
6 | */ | ||
1 | 7 | ||
2 | #include <linux/kernel.h> | 8 | #include <linux/kernel.h> |
3 | #include <linux/export.h> | 9 | #include <linux/export.h> |
@@ -10,23 +16,23 @@ | |||
10 | */ | 16 | */ |
11 | unsigned long int_sqrt(unsigned long x) | 17 | unsigned long int_sqrt(unsigned long x) |
12 | { | 18 | { |
13 | unsigned long op, res, one; | 19 | unsigned long b, m, y = 0; |
14 | 20 | ||
15 | op = x; | 21 | if (x <= 1) |
16 | res = 0; | 22 | return x; |
17 | 23 | ||
18 | one = 1UL << (BITS_PER_LONG - 2); | 24 | m = 1UL << (BITS_PER_LONG - 2); |
19 | while (one > op) | 25 | while (m != 0) { |
20 | one >>= 2; | 26 | b = y + m; |
27 | y >>= 1; | ||
21 | 28 | ||
22 | while (one != 0) { | 29 | if (x >= b) { |
23 | if (op >= res + one) { | 30 | x -= b; |
24 | op = op - (res + one); | 31 | y += m; |
25 | res = res + 2 * one; | ||
26 | } | 32 | } |
27 | res /= 2; | 33 | m >>= 2; |
28 | one /= 4; | ||
29 | } | 34 | } |
30 | return res; | 35 | |
36 | return y; | ||
31 | } | 37 | } |
32 | EXPORT_SYMBOL(int_sqrt); | 38 | EXPORT_SYMBOL(int_sqrt); |
diff --git a/lib/kobject.c b/lib/kobject.c index e07ee1fcd6f1..a65486613d79 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
@@ -529,6 +529,13 @@ struct kobject *kobject_get(struct kobject *kobj) | |||
529 | return kobj; | 529 | return kobj; |
530 | } | 530 | } |
531 | 531 | ||
532 | static struct kobject *kobject_get_unless_zero(struct kobject *kobj) | ||
533 | { | ||
534 | if (!kref_get_unless_zero(&kobj->kref)) | ||
535 | kobj = NULL; | ||
536 | return kobj; | ||
537 | } | ||
538 | |||
532 | /* | 539 | /* |
533 | * kobject_cleanup - free kobject resources. | 540 | * kobject_cleanup - free kobject resources. |
534 | * @kobj: object to cleanup | 541 | * @kobj: object to cleanup |
@@ -751,7 +758,7 @@ struct kobject *kset_find_obj(struct kset *kset, const char *name) | |||
751 | 758 | ||
752 | list_for_each_entry(k, &kset->list, entry) { | 759 | list_for_each_entry(k, &kset->list, entry) { |
753 | if (kobject_name(k) && !strcmp(kobject_name(k), name)) { | 760 | if (kobject_name(k) && !strcmp(kobject_name(k), name)) { |
754 | ret = kobject_get(k); | 761 | ret = kobject_get_unless_zero(k); |
755 | break; | 762 | break; |
756 | } | 763 | } |
757 | } | 764 | } |
diff --git a/lib/list_sort.c b/lib/list_sort.c index d7325c6b103f..1183fa70a44d 100644 --- a/lib/list_sort.c +++ b/lib/list_sort.c | |||
@@ -229,7 +229,7 @@ static int __init list_sort_test(void) | |||
229 | goto exit; | 229 | goto exit; |
230 | } | 230 | } |
231 | /* force some equivalencies */ | 231 | /* force some equivalencies */ |
232 | el->value = random32() % (TEST_LIST_LEN/3); | 232 | el->value = prandom_u32() % (TEST_LIST_LEN / 3); |
233 | el->serial = i; | 233 | el->serial = i; |
234 | el->poison1 = TEST_POISON1; | 234 | el->poison1 = TEST_POISON1; |
235 | el->poison2 = TEST_POISON2; | 235 | el->poison2 = TEST_POISON2; |
diff --git a/lib/rbtree_test.c b/lib/rbtree_test.c index af38aedbd874..122f02f9941b 100644 --- a/lib/rbtree_test.c +++ b/lib/rbtree_test.c | |||
@@ -117,8 +117,7 @@ static int black_path_count(struct rb_node *rb) | |||
117 | static void check(int nr_nodes) | 117 | static void check(int nr_nodes) |
118 | { | 118 | { |
119 | struct rb_node *rb; | 119 | struct rb_node *rb; |
120 | int count = 0; | 120 | int count = 0, blacks = 0; |
121 | int blacks = 0; | ||
122 | u32 prev_key = 0; | 121 | u32 prev_key = 0; |
123 | 122 | ||
124 | for (rb = rb_first(&root); rb; rb = rb_next(rb)) { | 123 | for (rb = rb_first(&root); rb; rb = rb_next(rb)) { |
@@ -134,7 +133,9 @@ static void check(int nr_nodes) | |||
134 | prev_key = node->key; | 133 | prev_key = node->key; |
135 | count++; | 134 | count++; |
136 | } | 135 | } |
136 | |||
137 | WARN_ON_ONCE(count != nr_nodes); | 137 | WARN_ON_ONCE(count != nr_nodes); |
138 | WARN_ON_ONCE(count < (1 << black_path_count(rb_last(&root))) - 1); | ||
138 | } | 139 | } |
139 | 140 | ||
140 | static void check_augmented(int nr_nodes) | 141 | static void check_augmented(int nr_nodes) |
@@ -148,7 +149,7 @@ static void check_augmented(int nr_nodes) | |||
148 | } | 149 | } |
149 | } | 150 | } |
150 | 151 | ||
151 | static int rbtree_test_init(void) | 152 | static int __init rbtree_test_init(void) |
152 | { | 153 | { |
153 | int i, j; | 154 | int i, j; |
154 | cycles_t time1, time2, time; | 155 | cycles_t time1, time2, time; |
@@ -221,7 +222,7 @@ static int rbtree_test_init(void) | |||
221 | return -EAGAIN; /* Fail will directly unload the module */ | 222 | return -EAGAIN; /* Fail will directly unload the module */ |
222 | } | 223 | } |
223 | 224 | ||
224 | static void rbtree_test_exit(void) | 225 | static void __exit rbtree_test_exit(void) |
225 | { | 226 | { |
226 | printk(KERN_ALERT "test exit\n"); | 227 | printk(KERN_ALERT "test exit\n"); |
227 | } | 228 | } |
diff --git a/lib/show_mem.c b/lib/show_mem.c index 4407f8c9b1f7..b7c72311ad0c 100644 --- a/lib/show_mem.c +++ b/lib/show_mem.c | |||
@@ -18,6 +18,9 @@ void show_mem(unsigned int filter) | |||
18 | printk("Mem-Info:\n"); | 18 | printk("Mem-Info:\n"); |
19 | show_free_areas(filter); | 19 | show_free_areas(filter); |
20 | 20 | ||
21 | if (filter & SHOW_MEM_FILTER_PAGE_COUNT) | ||
22 | return; | ||
23 | |||
21 | for_each_online_pgdat(pgdat) { | 24 | for_each_online_pgdat(pgdat) { |
22 | unsigned long i, flags; | 25 | unsigned long i, flags; |
23 | 26 | ||
diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 1cffc223bff5..ed5c1454dd62 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c | |||
@@ -2,10 +2,12 @@ | |||
2 | * Helpers for formatting and printing strings | 2 | * Helpers for formatting and printing strings |
3 | * | 3 | * |
4 | * Copyright 31 August 2008 James Bottomley | 4 | * Copyright 31 August 2008 James Bottomley |
5 | * Copyright (C) 2013, Intel Corporation | ||
5 | */ | 6 | */ |
6 | #include <linux/kernel.h> | 7 | #include <linux/kernel.h> |
7 | #include <linux/math64.h> | 8 | #include <linux/math64.h> |
8 | #include <linux/export.h> | 9 | #include <linux/export.h> |
10 | #include <linux/ctype.h> | ||
9 | #include <linux/string_helpers.h> | 11 | #include <linux/string_helpers.h> |
10 | 12 | ||
11 | /** | 13 | /** |
@@ -66,3 +68,134 @@ int string_get_size(u64 size, const enum string_size_units units, | |||
66 | return 0; | 68 | return 0; |
67 | } | 69 | } |
68 | EXPORT_SYMBOL(string_get_size); | 70 | EXPORT_SYMBOL(string_get_size); |
71 | |||
72 | static bool unescape_space(char **src, char **dst) | ||
73 | { | ||
74 | char *p = *dst, *q = *src; | ||
75 | |||
76 | switch (*q) { | ||
77 | case 'n': | ||
78 | *p = '\n'; | ||
79 | break; | ||
80 | case 'r': | ||
81 | *p = '\r'; | ||
82 | break; | ||
83 | case 't': | ||
84 | *p = '\t'; | ||
85 | break; | ||
86 | case 'v': | ||
87 | *p = '\v'; | ||
88 | break; | ||
89 | case 'f': | ||
90 | *p = '\f'; | ||
91 | break; | ||
92 | default: | ||
93 | return false; | ||
94 | } | ||
95 | *dst += 1; | ||
96 | *src += 1; | ||
97 | return true; | ||
98 | } | ||
99 | |||
100 | static bool unescape_octal(char **src, char **dst) | ||
101 | { | ||
102 | char *p = *dst, *q = *src; | ||
103 | u8 num; | ||
104 | |||
105 | if (isodigit(*q) == 0) | ||
106 | return false; | ||
107 | |||
108 | num = (*q++) & 7; | ||
109 | while (num < 32 && isodigit(*q) && (q - *src < 3)) { | ||
110 | num <<= 3; | ||
111 | num += (*q++) & 7; | ||
112 | } | ||
113 | *p = num; | ||
114 | *dst += 1; | ||
115 | *src = q; | ||
116 | return true; | ||
117 | } | ||
118 | |||
119 | static bool unescape_hex(char **src, char **dst) | ||
120 | { | ||
121 | char *p = *dst, *q = *src; | ||
122 | int digit; | ||
123 | u8 num; | ||
124 | |||
125 | if (*q++ != 'x') | ||
126 | return false; | ||
127 | |||
128 | num = digit = hex_to_bin(*q++); | ||
129 | if (digit < 0) | ||
130 | return false; | ||
131 | |||
132 | digit = hex_to_bin(*q); | ||
133 | if (digit >= 0) { | ||
134 | q++; | ||
135 | num = (num << 4) | digit; | ||
136 | } | ||
137 | *p = num; | ||
138 | *dst += 1; | ||
139 | *src = q; | ||
140 | return true; | ||
141 | } | ||
142 | |||
143 | static bool unescape_special(char **src, char **dst) | ||
144 | { | ||
145 | char *p = *dst, *q = *src; | ||
146 | |||
147 | switch (*q) { | ||
148 | case '\"': | ||
149 | *p = '\"'; | ||
150 | break; | ||
151 | case '\\': | ||
152 | *p = '\\'; | ||
153 | break; | ||
154 | case 'a': | ||
155 | *p = '\a'; | ||
156 | break; | ||
157 | case 'e': | ||
158 | *p = '\e'; | ||
159 | break; | ||
160 | default: | ||
161 | return false; | ||
162 | } | ||
163 | *dst += 1; | ||
164 | *src += 1; | ||
165 | return true; | ||
166 | } | ||
167 | |||
168 | int string_unescape(char *src, char *dst, size_t size, unsigned int flags) | ||
169 | { | ||
170 | char *out = dst; | ||
171 | |||
172 | while (*src && --size) { | ||
173 | if (src[0] == '\\' && src[1] != '\0' && size > 1) { | ||
174 | src++; | ||
175 | size--; | ||
176 | |||
177 | if (flags & UNESCAPE_SPACE && | ||
178 | unescape_space(&src, &out)) | ||
179 | continue; | ||
180 | |||
181 | if (flags & UNESCAPE_OCTAL && | ||
182 | unescape_octal(&src, &out)) | ||
183 | continue; | ||
184 | |||
185 | if (flags & UNESCAPE_HEX && | ||
186 | unescape_hex(&src, &out)) | ||
187 | continue; | ||
188 | |||
189 | if (flags & UNESCAPE_SPECIAL && | ||
190 | unescape_special(&src, &out)) | ||
191 | continue; | ||
192 | |||
193 | *out++ = '\\'; | ||
194 | } | ||
195 | *out++ = *src++; | ||
196 | } | ||
197 | *out = '\0'; | ||
198 | |||
199 | return out - dst; | ||
200 | } | ||
201 | EXPORT_SYMBOL(string_unescape); | ||
diff --git a/lib/swiotlb.c b/lib/swiotlb.c index bfe02b8fc55b..d23762e6652c 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c | |||
@@ -105,9 +105,9 @@ setup_io_tlb_npages(char *str) | |||
105 | if (!strcmp(str, "force")) | 105 | if (!strcmp(str, "force")) |
106 | swiotlb_force = 1; | 106 | swiotlb_force = 1; |
107 | 107 | ||
108 | return 1; | 108 | return 0; |
109 | } | 109 | } |
110 | __setup("swiotlb=", setup_io_tlb_npages); | 110 | early_param("swiotlb", setup_io_tlb_npages); |
111 | /* make io_tlb_overflow tunable too? */ | 111 | /* make io_tlb_overflow tunable too? */ |
112 | 112 | ||
113 | unsigned long swiotlb_nr_tbl(void) | 113 | unsigned long swiotlb_nr_tbl(void) |
@@ -115,6 +115,18 @@ unsigned long swiotlb_nr_tbl(void) | |||
115 | return io_tlb_nslabs; | 115 | return io_tlb_nslabs; |
116 | } | 116 | } |
117 | EXPORT_SYMBOL_GPL(swiotlb_nr_tbl); | 117 | EXPORT_SYMBOL_GPL(swiotlb_nr_tbl); |
118 | |||
119 | /* default to 64MB */ | ||
120 | #define IO_TLB_DEFAULT_SIZE (64UL<<20) | ||
121 | unsigned long swiotlb_size_or_default(void) | ||
122 | { | ||
123 | unsigned long size; | ||
124 | |||
125 | size = io_tlb_nslabs << IO_TLB_SHIFT; | ||
126 | |||
127 | return size ? size : (IO_TLB_DEFAULT_SIZE); | ||
128 | } | ||
129 | |||
118 | /* Note that this doesn't work with highmem page */ | 130 | /* Note that this doesn't work with highmem page */ |
119 | static dma_addr_t swiotlb_virt_to_bus(struct device *hwdev, | 131 | static dma_addr_t swiotlb_virt_to_bus(struct device *hwdev, |
120 | volatile void *address) | 132 | volatile void *address) |
@@ -188,8 +200,7 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) | |||
188 | void __init | 200 | void __init |
189 | swiotlb_init(int verbose) | 201 | swiotlb_init(int verbose) |
190 | { | 202 | { |
191 | /* default to 64MB */ | 203 | size_t default_size = IO_TLB_DEFAULT_SIZE; |
192 | size_t default_size = 64UL<<20; | ||
193 | unsigned char *vstart; | 204 | unsigned char *vstart; |
194 | unsigned long bytes; | 205 | unsigned long bytes; |
195 | 206 | ||
diff --git a/lib/test-string_helpers.c b/lib/test-string_helpers.c new file mode 100644 index 000000000000..6ac48de04c0e --- /dev/null +++ b/lib/test-string_helpers.c | |||
@@ -0,0 +1,103 @@ | |||
1 | /* | ||
2 | * Test cases for lib/string_helpers.c module. | ||
3 | */ | ||
4 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
5 | |||
6 | #include <linux/init.h> | ||
7 | #include <linux/kernel.h> | ||
8 | #include <linux/module.h> | ||
9 | #include <linux/random.h> | ||
10 | #include <linux/string.h> | ||
11 | #include <linux/string_helpers.h> | ||
12 | |||
13 | struct test_string { | ||
14 | const char *in; | ||
15 | const char *out; | ||
16 | unsigned int flags; | ||
17 | }; | ||
18 | |||
19 | static const struct test_string strings[] __initconst = { | ||
20 | { | ||
21 | .in = "\\f\\ \\n\\r\\t\\v", | ||
22 | .out = "\f\\ \n\r\t\v", | ||
23 | .flags = UNESCAPE_SPACE, | ||
24 | }, | ||
25 | { | ||
26 | .in = "\\40\\1\\387\\0064\\05\\040\\8a\\110\\777", | ||
27 | .out = " \001\00387\0064\005 \\8aH?7", | ||
28 | .flags = UNESCAPE_OCTAL, | ||
29 | }, | ||
30 | { | ||
31 | .in = "\\xv\\xa\\x2c\\xD\\x6f2", | ||
32 | .out = "\\xv\n,\ro2", | ||
33 | .flags = UNESCAPE_HEX, | ||
34 | }, | ||
35 | { | ||
36 | .in = "\\h\\\\\\\"\\a\\e\\", | ||
37 | .out = "\\h\\\"\a\e\\", | ||
38 | .flags = UNESCAPE_SPECIAL, | ||
39 | }, | ||
40 | }; | ||
41 | |||
42 | static void __init test_string_unescape(unsigned int flags, bool inplace) | ||
43 | { | ||
44 | char in[256]; | ||
45 | char out_test[256]; | ||
46 | char out_real[256]; | ||
47 | int i, p = 0, q_test = 0, q_real = sizeof(out_real); | ||
48 | |||
49 | for (i = 0; i < ARRAY_SIZE(strings); i++) { | ||
50 | const char *s = strings[i].in; | ||
51 | int len = strlen(strings[i].in); | ||
52 | |||
53 | /* Copy string to in buffer */ | ||
54 | memcpy(&in[p], s, len); | ||
55 | p += len; | ||
56 | |||
57 | /* Copy expected result for given flags */ | ||
58 | if (flags & strings[i].flags) { | ||
59 | s = strings[i].out; | ||
60 | len = strlen(strings[i].out); | ||
61 | } | ||
62 | memcpy(&out_test[q_test], s, len); | ||
63 | q_test += len; | ||
64 | } | ||
65 | in[p++] = '\0'; | ||
66 | |||
67 | /* Call string_unescape and compare result */ | ||
68 | if (inplace) { | ||
69 | memcpy(out_real, in, p); | ||
70 | if (flags == UNESCAPE_ANY) | ||
71 | q_real = string_unescape_any_inplace(out_real); | ||
72 | else | ||
73 | q_real = string_unescape_inplace(out_real, flags); | ||
74 | } else if (flags == UNESCAPE_ANY) { | ||
75 | q_real = string_unescape_any(in, out_real, q_real); | ||
76 | } else { | ||
77 | q_real = string_unescape(in, out_real, q_real, flags); | ||
78 | } | ||
79 | |||
80 | if (q_real != q_test || memcmp(out_test, out_real, q_test)) { | ||
81 | pr_warn("Test failed: flags = %u\n", flags); | ||
82 | print_hex_dump(KERN_WARNING, "Input: ", | ||
83 | DUMP_PREFIX_NONE, 16, 1, in, p - 1, true); | ||
84 | print_hex_dump(KERN_WARNING, "Expected: ", | ||
85 | DUMP_PREFIX_NONE, 16, 1, out_test, q_test, true); | ||
86 | print_hex_dump(KERN_WARNING, "Got: ", | ||
87 | DUMP_PREFIX_NONE, 16, 1, out_real, q_real, true); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | static int __init test_string_helpers_init(void) | ||
92 | { | ||
93 | unsigned int i; | ||
94 | |||
95 | pr_info("Running tests...\n"); | ||
96 | for (i = 0; i < UNESCAPE_ANY + 1; i++) | ||
97 | test_string_unescape(i, false); | ||
98 | test_string_unescape(get_random_int() % (UNESCAPE_ANY + 1), true); | ||
99 | |||
100 | return -EINVAL; | ||
101 | } | ||
102 | module_init(test_string_helpers_init); | ||
103 | MODULE_LICENSE("Dual BSD/GPL"); | ||
diff --git a/lib/ucs2_string.c b/lib/ucs2_string.c new file mode 100644 index 000000000000..6f500ef2301d --- /dev/null +++ b/lib/ucs2_string.c | |||
@@ -0,0 +1,51 @@ | |||
1 | #include <linux/ucs2_string.h> | ||
2 | #include <linux/module.h> | ||
3 | |||
4 | /* Return the number of unicode characters in data */ | ||
5 | unsigned long | ||
6 | ucs2_strnlen(const ucs2_char_t *s, size_t maxlength) | ||
7 | { | ||
8 | unsigned long length = 0; | ||
9 | |||
10 | while (*s++ != 0 && length < maxlength) | ||
11 | length++; | ||
12 | return length; | ||
13 | } | ||
14 | EXPORT_SYMBOL(ucs2_strnlen); | ||
15 | |||
16 | unsigned long | ||
17 | ucs2_strlen(const ucs2_char_t *s) | ||
18 | { | ||
19 | return ucs2_strnlen(s, ~0UL); | ||
20 | } | ||
21 | EXPORT_SYMBOL(ucs2_strlen); | ||
22 | |||
23 | /* | ||
24 | * Return the number of bytes is the length of this string | ||
25 | * Note: this is NOT the same as the number of unicode characters | ||
26 | */ | ||
27 | unsigned long | ||
28 | ucs2_strsize(const ucs2_char_t *data, unsigned long maxlength) | ||
29 | { | ||
30 | return ucs2_strnlen(data, maxlength/sizeof(ucs2_char_t)) * sizeof(ucs2_char_t); | ||
31 | } | ||
32 | EXPORT_SYMBOL(ucs2_strsize); | ||
33 | |||
34 | int | ||
35 | ucs2_strncmp(const ucs2_char_t *a, const ucs2_char_t *b, size_t len) | ||
36 | { | ||
37 | while (1) { | ||
38 | if (len == 0) | ||
39 | return 0; | ||
40 | if (*a < *b) | ||
41 | return -1; | ||
42 | if (*a > *b) | ||
43 | return 1; | ||
44 | if (*a == 0) /* implies *b == 0 */ | ||
45 | return 0; | ||
46 | a++; | ||
47 | b++; | ||
48 | len--; | ||
49 | } | ||
50 | } | ||
51 | EXPORT_SYMBOL(ucs2_strncmp); | ||
diff --git a/lib/usercopy.c b/lib/usercopy.c new file mode 100644 index 000000000000..4f5b1ddbcd25 --- /dev/null +++ b/lib/usercopy.c | |||
@@ -0,0 +1,9 @@ | |||
1 | #include <linux/export.h> | ||
2 | #include <linux/bug.h> | ||
3 | #include <linux/uaccess.h> | ||
4 | |||
5 | void copy_from_user_overflow(void) | ||
6 | { | ||
7 | WARN(1, "Buffer overflow detected!\n"); | ||
8 | } | ||
9 | EXPORT_SYMBOL(copy_from_user_overflow); | ||
diff --git a/lib/uuid.c b/lib/uuid.c index 52a6fe6387de..398821e4dce1 100644 --- a/lib/uuid.c +++ b/lib/uuid.c | |||
@@ -25,13 +25,7 @@ | |||
25 | 25 | ||
26 | static void __uuid_gen_common(__u8 b[16]) | 26 | static void __uuid_gen_common(__u8 b[16]) |
27 | { | 27 | { |
28 | int i; | 28 | prandom_bytes(b, 16); |
29 | u32 r; | ||
30 | |||
31 | for (i = 0; i < 4; i++) { | ||
32 | r = random32(); | ||
33 | memcpy(b + i * 4, &r, 4); | ||
34 | } | ||
35 | /* reversion 0b10 */ | 29 | /* reversion 0b10 */ |
36 | b[8] = (b[8] & 0x3F) | 0x80; | 30 | b[8] = (b[8] & 0x3F) | 0x80; |
37 | } | 31 | } |
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 0d62fd700f68..e149c6416384 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -534,14 +534,21 @@ char *string(char *buf, char *end, const char *s, struct printf_spec spec) | |||
534 | 534 | ||
535 | static noinline_for_stack | 535 | static noinline_for_stack |
536 | char *symbol_string(char *buf, char *end, void *ptr, | 536 | char *symbol_string(char *buf, char *end, void *ptr, |
537 | struct printf_spec spec, char ext) | 537 | struct printf_spec spec, const char *fmt) |
538 | { | 538 | { |
539 | unsigned long value = (unsigned long) ptr; | 539 | unsigned long value; |
540 | #ifdef CONFIG_KALLSYMS | 540 | #ifdef CONFIG_KALLSYMS |
541 | char sym[KSYM_SYMBOL_LEN]; | 541 | char sym[KSYM_SYMBOL_LEN]; |
542 | if (ext == 'B') | 542 | #endif |
543 | |||
544 | if (fmt[1] == 'R') | ||
545 | ptr = __builtin_extract_return_addr(ptr); | ||
546 | value = (unsigned long)ptr; | ||
547 | |||
548 | #ifdef CONFIG_KALLSYMS | ||
549 | if (*fmt == 'B') | ||
543 | sprint_backtrace(sym, value); | 550 | sprint_backtrace(sym, value); |
544 | else if (ext != 'f' && ext != 's') | 551 | else if (*fmt != 'f' && *fmt != 's') |
545 | sprint_symbol(sym, value); | 552 | sprint_symbol(sym, value); |
546 | else | 553 | else |
547 | sprint_symbol_no_offset(sym, value); | 554 | sprint_symbol_no_offset(sym, value); |
@@ -987,6 +994,7 @@ int kptr_restrict __read_mostly; | |||
987 | * - 'f' For simple symbolic function names without offset | 994 | * - 'f' For simple symbolic function names without offset |
988 | * - 'S' For symbolic direct pointers with offset | 995 | * - 'S' For symbolic direct pointers with offset |
989 | * - 's' For symbolic direct pointers without offset | 996 | * - 's' For symbolic direct pointers without offset |
997 | * - '[FfSs]R' as above with __builtin_extract_return_addr() translation | ||
990 | * - 'B' For backtraced symbolic direct pointers with offset | 998 | * - 'B' For backtraced symbolic direct pointers with offset |
991 | * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref] | 999 | * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref] |
992 | * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201] | 1000 | * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201] |
@@ -1060,7 +1068,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
1060 | case 'S': | 1068 | case 'S': |
1061 | case 's': | 1069 | case 's': |
1062 | case 'B': | 1070 | case 'B': |
1063 | return symbol_string(buf, end, ptr, spec, *fmt); | 1071 | return symbol_string(buf, end, ptr, spec, fmt); |
1064 | case 'R': | 1072 | case 'R': |
1065 | case 'r': | 1073 | case 'r': |
1066 | return resource_string(buf, end, ptr, spec, fmt); | 1074 | return resource_string(buf, end, ptr, spec, fmt); |