aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Kconfig13
-rw-r--r--lib/Kconfig.debug60
-rw-r--r--lib/Makefile4
-rw-r--r--lib/asn1_decoder.c2
-rw-r--r--lib/atomic64_test.c13
-rw-r--r--lib/audit.c15
-rw-r--r--lib/btree.c1
-rw-r--r--lib/bug.c21
-rw-r--r--lib/clz_ctz.c7
-rw-r--r--lib/compat_audit.c50
-rw-r--r--lib/crc32.c4
-rw-r--r--lib/debugobjects.c19
-rw-r--r--lib/decompress.c3
-rw-r--r--lib/decompress_inflate.c1
-rw-r--r--lib/devres.c26
-rw-r--r--lib/digsig.c5
-rw-r--r--lib/dump_stack.c4
-rw-r--r--lib/fdt_empty_tree.c2
-rw-r--r--lib/idr.c74
-rw-r--r--lib/iomap.c4
-rw-r--r--lib/kobject.c2
-rw-r--r--lib/kobject_uevent.c48
-rw-r--r--lib/libcrc32c.c5
-rw-r--r--lib/nlattr.c31
-rw-r--r--lib/percpu_counter.c2
-rw-r--r--lib/plist.c56
-rw-r--r--lib/radix-tree.c396
-rw-r--r--lib/random32.c76
-rw-r--r--lib/smp_processor_id.c18
-rw-r--r--lib/string.c28
-rw-r--r--lib/swiotlb.c2
-rw-r--r--lib/syscall.c1
-rw-r--r--lib/textsearch.c9
-rw-r--r--lib/vsprintf.c62
-rw-r--r--lib/xz/Kconfig24
-rw-r--r--lib/xz/xz_dec_lzma2.c4
36 files changed, 644 insertions, 448 deletions
diff --git a/lib/Kconfig b/lib/Kconfig
index 991c98bc4a3f..4771fb3f4da4 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -182,6 +182,15 @@ config AUDIT_GENERIC
182 depends on AUDIT && !AUDIT_ARCH 182 depends on AUDIT && !AUDIT_ARCH
183 default y 183 default y
184 184
185config AUDIT_ARCH_COMPAT_GENERIC
186 bool
187 default n
188
189config AUDIT_COMPAT_GENERIC
190 bool
191 depends on AUDIT_GENERIC && AUDIT_ARCH_COMPAT_GENERIC && COMPAT
192 default y
193
185config RANDOM32_SELFTEST 194config RANDOM32_SELFTEST
186 bool "PRNG perform self test on init" 195 bool "PRNG perform self test on init"
187 default n 196 default n
@@ -342,9 +351,9 @@ config HAS_IOMEM
342 select GENERIC_IO 351 select GENERIC_IO
343 default y 352 default y
344 353
345config HAS_IOPORT 354config HAS_IOPORT_MAP
346 boolean 355 boolean
347 depends on HAS_IOMEM && !NO_IOPORT 356 depends on HAS_IOMEM && !NO_IOPORT_MAP
348 default y 357 default y
349 358
350config HAS_DMA 359config HAS_DMA
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index a48abeac753f..ccca32264748 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -501,12 +501,21 @@ config DEBUG_VM
501 501
502 If unsure, say N. 502 If unsure, say N.
503 503
504config DEBUG_VM_VMACACHE
505 bool "Debug VMA caching"
506 depends on DEBUG_VM
507 help
508 Enable this to turn on VMA caching debug information. Doing so
509 can cause significant overhead, so only enable it in non-production
510 environments.
511
512 If unsure, say N.
513
504config DEBUG_VM_RB 514config DEBUG_VM_RB
505 bool "Debug VM red-black trees" 515 bool "Debug VM red-black trees"
506 depends on DEBUG_VM 516 depends on DEBUG_VM
507 help 517 help
508 Enable this to turn on more extended checks in the virtual-memory 518 Enable VM red-black tree debugging information and extra validations.
509 system that may impact performance.
510 519
511 If unsure, say N. 520 If unsure, say N.
512 521
@@ -576,8 +585,8 @@ config DEBUG_HIGHMEM
576 bool "Highmem debugging" 585 bool "Highmem debugging"
577 depends on DEBUG_KERNEL && HIGHMEM 586 depends on DEBUG_KERNEL && HIGHMEM
578 help 587 help
579 This options enables addition error checking for high memory systems. 588 This option enables additional error checking for high memory
580 Disable for production systems. 589 systems. Disable for production systems.
581 590
582config HAVE_DEBUG_STACKOVERFLOW 591config HAVE_DEBUG_STACKOVERFLOW
583 bool 592 bool
@@ -824,11 +833,6 @@ config DEBUG_RT_MUTEXES
824 This allows rt mutex semantics violations and rt mutex related 833 This allows rt mutex semantics violations and rt mutex related
825 deadlocks (lockups) to be detected and reported automatically. 834 deadlocks (lockups) to be detected and reported automatically.
826 835
827config DEBUG_PI_LIST
828 bool
829 default y
830 depends on DEBUG_RT_MUTEXES
831
832config RT_MUTEX_TESTER 836config RT_MUTEX_TESTER
833 bool "Built-in scriptable tester for rt-mutexes" 837 bool "Built-in scriptable tester for rt-mutexes"
834 depends on DEBUG_KERNEL && RT_MUTEXES 838 depends on DEBUG_KERNEL && RT_MUTEXES
@@ -980,6 +984,21 @@ config DEBUG_LOCKING_API_SELFTESTS
980 The following locking APIs are covered: spinlocks, rwlocks, 984 The following locking APIs are covered: spinlocks, rwlocks,
981 mutexes and rwsems. 985 mutexes and rwsems.
982 986
987config LOCK_TORTURE_TEST
988 tristate "torture tests for locking"
989 depends on DEBUG_KERNEL
990 select TORTURE_TEST
991 default n
992 help
993 This option provides a kernel module that runs torture tests
994 on kernel locking primitives. The kernel module may be built
995 after the fact on the running kernel to be tested, if desired.
996
997 Say Y here if you want kernel locking-primitive torture tests
998 to be built into the kernel.
999 Say M if you want these torture tests to build as a module.
1000 Say N if you are unsure.
1001
983endmenu # lock debugging 1002endmenu # lock debugging
984 1003
985config TRACE_IRQFLAGS 1004config TRACE_IRQFLAGS
@@ -1030,22 +1049,22 @@ config DEBUG_BUGVERBOSE
1030 of the BUG call as well as the EIP and oops trace. This aids 1049 of the BUG call as well as the EIP and oops trace. This aids
1031 debugging but costs about 70-100K of memory. 1050 debugging but costs about 70-100K of memory.
1032 1051
1033config DEBUG_WRITECOUNT 1052config DEBUG_LIST
1034 bool "Debug filesystem writers count" 1053 bool "Debug linked list manipulation"
1035 depends on DEBUG_KERNEL 1054 depends on DEBUG_KERNEL
1036 help 1055 help
1037 Enable this to catch wrong use of the writers count in struct 1056 Enable this to turn on extended checks in the linked-list
1038 vfsmount. This will increase the size of each file struct by 1057 walking routines.
1039 32 bits.
1040 1058
1041 If unsure, say N. 1059 If unsure, say N.
1042 1060
1043config DEBUG_LIST 1061config DEBUG_PI_LIST
1044 bool "Debug linked list manipulation" 1062 bool "Debug priority linked list manipulation"
1045 depends on DEBUG_KERNEL 1063 depends on DEBUG_KERNEL
1046 help 1064 help
1047 Enable this to turn on extended checks in the linked-list 1065 Enable this to turn on extended checks in the priority-ordered
1048 walking routines. 1066 linked-list (plist) walking routines. This checks the entire
1067 list multiple times during each manipulation.
1049 1068
1050 If unsure, say N. 1069 If unsure, say N.
1051 1070
@@ -1141,9 +1160,14 @@ config SPARSE_RCU_POINTER
1141 1160
1142 Say N if you are unsure. 1161 Say N if you are unsure.
1143 1162
1163config TORTURE_TEST
1164 tristate
1165 default n
1166
1144config RCU_TORTURE_TEST 1167config RCU_TORTURE_TEST
1145 tristate "torture tests for RCU" 1168 tristate "torture tests for RCU"
1146 depends on DEBUG_KERNEL 1169 depends on DEBUG_KERNEL
1170 select TORTURE_TEST
1147 default n 1171 default n
1148 help 1172 help
1149 This option provides a kernel module that runs torture tests 1173 This option provides a kernel module that runs torture tests
diff --git a/lib/Makefile b/lib/Makefile
index 48140e3ba73f..74a32dc49a93 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -96,6 +96,7 @@ obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o
96obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o 96obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o
97obj-$(CONFIG_SMP) += percpu_counter.o 97obj-$(CONFIG_SMP) += percpu_counter.o
98obj-$(CONFIG_AUDIT_GENERIC) += audit.o 98obj-$(CONFIG_AUDIT_GENERIC) += audit.o
99obj-$(CONFIG_AUDIT_COMPAT_GENERIC) += compat_audit.o
99 100
100obj-$(CONFIG_SWIOTLB) += swiotlb.o 101obj-$(CONFIG_SWIOTLB) += swiotlb.o
101obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o 102obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
@@ -147,7 +148,8 @@ obj-$(CONFIG_GENERIC_NET_UTILS) += net_utils.o
147 148
148obj-$(CONFIG_STMP_DEVICE) += stmp_device.o 149obj-$(CONFIG_STMP_DEVICE) += stmp_device.o
149 150
150libfdt_files = fdt.o fdt_ro.o fdt_wip.o fdt_rw.o fdt_sw.o fdt_strerror.o 151libfdt_files = fdt.o fdt_ro.o fdt_wip.o fdt_rw.o fdt_sw.o fdt_strerror.o \
152 fdt_empty_tree.o
151$(foreach file, $(libfdt_files), \ 153$(foreach file, $(libfdt_files), \
152 $(eval CFLAGS_$(file) = -I$(src)/../scripts/dtc/libfdt)) 154 $(eval CFLAGS_$(file) = -I$(src)/../scripts/dtc/libfdt))
153lib-$(CONFIG_LIBFDT) += $(libfdt_files) 155lib-$(CONFIG_LIBFDT) += $(libfdt_files)
diff --git a/lib/asn1_decoder.c b/lib/asn1_decoder.c
index 11b9b01fda6b..1a000bb050f9 100644
--- a/lib/asn1_decoder.c
+++ b/lib/asn1_decoder.c
@@ -140,7 +140,7 @@ error:
140 * @decoder: The decoder definition (produced by asn1_compiler) 140 * @decoder: The decoder definition (produced by asn1_compiler)
141 * @context: The caller's context (to be passed to the action functions) 141 * @context: The caller's context (to be passed to the action functions)
142 * @data: The encoded data 142 * @data: The encoded data
143 * @datasize: The size of the encoded data 143 * @datalen: The size of the encoded data
144 * 144 *
145 * Decode BER/DER/CER encoded ASN.1 data according to a bytecode pattern 145 * Decode BER/DER/CER encoded ASN.1 data according to a bytecode pattern
146 * produced by asn1_compiler. Action functions are called on marked tags to 146 * produced by asn1_compiler. Action functions are called on marked tags to
diff --git a/lib/atomic64_test.c b/lib/atomic64_test.c
index 00bca223d1e1..0211d30d8c39 100644
--- a/lib/atomic64_test.c
+++ b/lib/atomic64_test.c
@@ -8,6 +8,9 @@
8 * the Free Software Foundation; either version 2 of the License, or 8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
10 */ 10 */
11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
11#include <linux/init.h> 14#include <linux/init.h>
12#include <linux/bug.h> 15#include <linux/bug.h>
13#include <linux/kernel.h> 16#include <linux/kernel.h>
@@ -146,18 +149,18 @@ static __init int test_atomic64(void)
146 BUG_ON(v.counter != r); 149 BUG_ON(v.counter != r);
147 150
148#ifdef CONFIG_X86 151#ifdef CONFIG_X86
149 printk(KERN_INFO "atomic64 test passed for %s platform %s CX8 and %s SSE\n", 152 pr_info("passed for %s platform %s CX8 and %s SSE\n",
150#ifdef CONFIG_X86_64 153#ifdef CONFIG_X86_64
151 "x86-64", 154 "x86-64",
152#elif defined(CONFIG_X86_CMPXCHG64) 155#elif defined(CONFIG_X86_CMPXCHG64)
153 "i586+", 156 "i586+",
154#else 157#else
155 "i386+", 158 "i386+",
156#endif 159#endif
157 boot_cpu_has(X86_FEATURE_CX8) ? "with" : "without", 160 boot_cpu_has(X86_FEATURE_CX8) ? "with" : "without",
158 boot_cpu_has(X86_FEATURE_XMM) ? "with" : "without"); 161 boot_cpu_has(X86_FEATURE_XMM) ? "with" : "without");
159#else 162#else
160 printk(KERN_INFO "atomic64 test passed\n"); 163 pr_info("passed\n");
161#endif 164#endif
162 165
163 return 0; 166 return 0;
diff --git a/lib/audit.c b/lib/audit.c
index 76bbed4a20e5..1d726a22565b 100644
--- a/lib/audit.c
+++ b/lib/audit.c
@@ -30,11 +30,17 @@ static unsigned signal_class[] = {
30 30
31int audit_classify_arch(int arch) 31int audit_classify_arch(int arch)
32{ 32{
33 return 0; 33 if (audit_is_compat(arch))
34 return 1;
35 else
36 return 0;
34} 37}
35 38
36int audit_classify_syscall(int abi, unsigned syscall) 39int audit_classify_syscall(int abi, unsigned syscall)
37{ 40{
41 if (audit_is_compat(abi))
42 return audit_classify_compat_syscall(abi, syscall);
43
38 switch(syscall) { 44 switch(syscall) {
39#ifdef __NR_open 45#ifdef __NR_open
40 case __NR_open: 46 case __NR_open:
@@ -57,6 +63,13 @@ int audit_classify_syscall(int abi, unsigned syscall)
57 63
58static int __init audit_classes_init(void) 64static int __init audit_classes_init(void)
59{ 65{
66#ifdef CONFIG_AUDIT_COMPAT_GENERIC
67 audit_register_class(AUDIT_CLASS_WRITE_32, compat_write_class);
68 audit_register_class(AUDIT_CLASS_READ_32, compat_read_class);
69 audit_register_class(AUDIT_CLASS_DIR_WRITE_32, compat_dir_class);
70 audit_register_class(AUDIT_CLASS_CHATTR_32, compat_chattr_class);
71 audit_register_class(AUDIT_CLASS_SIGNAL_32, compat_signal_class);
72#endif
60 audit_register_class(AUDIT_CLASS_WRITE, write_class); 73 audit_register_class(AUDIT_CLASS_WRITE, write_class);
61 audit_register_class(AUDIT_CLASS_READ, read_class); 74 audit_register_class(AUDIT_CLASS_READ, read_class);
62 audit_register_class(AUDIT_CLASS_DIR_WRITE, dir_class); 75 audit_register_class(AUDIT_CLASS_DIR_WRITE, dir_class);
diff --git a/lib/btree.c b/lib/btree.c
index f9a484676cb6..4264871ea1a0 100644
--- a/lib/btree.c
+++ b/lib/btree.c
@@ -198,6 +198,7 @@ EXPORT_SYMBOL_GPL(btree_init);
198 198
199void btree_destroy(struct btree_head *head) 199void btree_destroy(struct btree_head *head)
200{ 200{
201 mempool_free(head->node, head->mempool);
201 mempool_destroy(head->mempool); 202 mempool_destroy(head->mempool);
202 head->mempool = NULL; 203 head->mempool = NULL;
203} 204}
diff --git a/lib/bug.c b/lib/bug.c
index 168603477f02..d1d7c7878900 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -37,6 +37,9 @@
37 37
38 Jeremy Fitzhardinge <jeremy@goop.org> 2006 38 Jeremy Fitzhardinge <jeremy@goop.org> 2006
39 */ 39 */
40
41#define pr_fmt(fmt) fmt
42
40#include <linux/list.h> 43#include <linux/list.h>
41#include <linux/module.h> 44#include <linux/module.h>
42#include <linux/kernel.h> 45#include <linux/kernel.h>
@@ -153,15 +156,13 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
153 156
154 if (warning) { 157 if (warning) {
155 /* this is a WARN_ON rather than BUG/BUG_ON */ 158 /* this is a WARN_ON rather than BUG/BUG_ON */
156 printk(KERN_WARNING "------------[ cut here ]------------\n"); 159 pr_warn("------------[ cut here ]------------\n");
157 160
158 if (file) 161 if (file)
159 printk(KERN_WARNING "WARNING: at %s:%u\n", 162 pr_warn("WARNING: at %s:%u\n", file, line);
160 file, line);
161 else 163 else
162 printk(KERN_WARNING "WARNING: at %p " 164 pr_warn("WARNING: at %p [verbose debug info unavailable]\n",
163 "[verbose debug info unavailable]\n", 165 (void *)bugaddr);
164 (void *)bugaddr);
165 166
166 print_modules(); 167 print_modules();
167 show_regs(regs); 168 show_regs(regs);
@@ -174,12 +175,10 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
174 printk(KERN_DEFAULT "------------[ cut here ]------------\n"); 175 printk(KERN_DEFAULT "------------[ cut here ]------------\n");
175 176
176 if (file) 177 if (file)
177 printk(KERN_CRIT "kernel BUG at %s:%u!\n", 178 pr_crit("kernel BUG at %s:%u!\n", file, line);
178 file, line);
179 else 179 else
180 printk(KERN_CRIT "Kernel BUG at %p " 180 pr_crit("Kernel BUG at %p [verbose debug info unavailable]\n",
181 "[verbose debug info unavailable]\n", 181 (void *)bugaddr);
182 (void *)bugaddr);
183 182
184 return BUG_TRAP_TYPE_BUG; 183 return BUG_TRAP_TYPE_BUG;
185} 184}
diff --git a/lib/clz_ctz.c b/lib/clz_ctz.c
index a8f8379eb49f..2e11e48446ab 100644
--- a/lib/clz_ctz.c
+++ b/lib/clz_ctz.c
@@ -6,6 +6,9 @@
6 * This program is free software; you can redistribute it and/or modify 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 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 * The functions in this file aren't called directly, but are required by
10 * GCC builtins such as __builtin_ctz, and therefore they can't be removed
11 * despite appearing unreferenced in kernel source.
9 * 12 *
10 * __c[lt]z[sd]i2 can be overridden by linking arch-specific versions. 13 * __c[lt]z[sd]i2 can be overridden by linking arch-specific versions.
11 */ 14 */
@@ -13,18 +16,22 @@
13#include <linux/export.h> 16#include <linux/export.h>
14#include <linux/kernel.h> 17#include <linux/kernel.h>
15 18
19int __weak __ctzsi2(int val);
16int __weak __ctzsi2(int val) 20int __weak __ctzsi2(int val)
17{ 21{
18 return __ffs(val); 22 return __ffs(val);
19} 23}
20EXPORT_SYMBOL(__ctzsi2); 24EXPORT_SYMBOL(__ctzsi2);
21 25
26int __weak __clzsi2(int val);
22int __weak __clzsi2(int val) 27int __weak __clzsi2(int val)
23{ 28{
24 return 32 - fls(val); 29 return 32 - fls(val);
25} 30}
26EXPORT_SYMBOL(__clzsi2); 31EXPORT_SYMBOL(__clzsi2);
27 32
33int __weak __clzdi2(long val);
34int __weak __ctzdi2(long val);
28#if BITS_PER_LONG == 32 35#if BITS_PER_LONG == 32
29 36
30int __weak __clzdi2(long val) 37int __weak __clzdi2(long val)
diff --git a/lib/compat_audit.c b/lib/compat_audit.c
new file mode 100644
index 000000000000..873f75b640ab
--- /dev/null
+++ b/lib/compat_audit.c
@@ -0,0 +1,50 @@
1#include <linux/init.h>
2#include <linux/types.h>
3#include <asm/unistd32.h>
4
5unsigned compat_dir_class[] = {
6#include <asm-generic/audit_dir_write.h>
7~0U
8};
9
10unsigned compat_read_class[] = {
11#include <asm-generic/audit_read.h>
12~0U
13};
14
15unsigned compat_write_class[] = {
16#include <asm-generic/audit_write.h>
17~0U
18};
19
20unsigned compat_chattr_class[] = {
21#include <asm-generic/audit_change_attr.h>
22~0U
23};
24
25unsigned compat_signal_class[] = {
26#include <asm-generic/audit_signal.h>
27~0U
28};
29
30int audit_classify_compat_syscall(int abi, unsigned syscall)
31{
32 switch (syscall) {
33#ifdef __NR_open
34 case __NR_open:
35 return 2;
36#endif
37#ifdef __NR_openat
38 case __NR_openat:
39 return 3;
40#endif
41#ifdef __NR_socketcall
42 case __NR_socketcall:
43 return 4;
44#endif
45 case __NR_execve:
46 return 5;
47 default:
48 return 1;
49 }
50}
diff --git a/lib/crc32.c b/lib/crc32.c
index 70f00ca5ef1e..21a7b2135af6 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -33,13 +33,13 @@
33#include "crc32defs.h" 33#include "crc32defs.h"
34 34
35#if CRC_LE_BITS > 8 35#if CRC_LE_BITS > 8
36# define tole(x) ((__force u32) __constant_cpu_to_le32(x)) 36# define tole(x) ((__force u32) cpu_to_le32(x))
37#else 37#else
38# define tole(x) (x) 38# define tole(x) (x)
39#endif 39#endif
40 40
41#if CRC_BE_BITS > 8 41#if CRC_BE_BITS > 8
42# define tobe(x) ((__force u32) __constant_cpu_to_be32(x)) 42# define tobe(x) ((__force u32) cpu_to_be32(x))
43#else 43#else
44# define tobe(x) (x) 44# define tobe(x) (x)
45#endif 45#endif
diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index e0731c3db706..547f7f923dbc 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -7,6 +7,9 @@
7 * 7 *
8 * For licencing details see kernel-base/COPYING 8 * For licencing details see kernel-base/COPYING
9 */ 9 */
10
11#define pr_fmt(fmt) "ODEBUG: " fmt
12
10#include <linux/debugobjects.h> 13#include <linux/debugobjects.h>
11#include <linux/interrupt.h> 14#include <linux/interrupt.h>
12#include <linux/sched.h> 15#include <linux/sched.h>
@@ -218,7 +221,7 @@ static void debug_objects_oom(void)
218 unsigned long flags; 221 unsigned long flags;
219 int i; 222 int i;
220 223
221 printk(KERN_WARNING "ODEBUG: Out of memory. ODEBUG disabled\n"); 224 pr_warn("Out of memory. ODEBUG disabled\n");
222 225
223 for (i = 0; i < ODEBUG_HASH_SIZE; i++, db++) { 226 for (i = 0; i < ODEBUG_HASH_SIZE; i++, db++) {
224 raw_spin_lock_irqsave(&db->lock, flags); 227 raw_spin_lock_irqsave(&db->lock, flags);
@@ -292,11 +295,9 @@ static void debug_object_is_on_stack(void *addr, int onstack)
292 295
293 limit++; 296 limit++;
294 if (is_on_stack) 297 if (is_on_stack)
295 printk(KERN_WARNING 298 pr_warn("object is on stack, but not annotated\n");
296 "ODEBUG: object is on stack, but not annotated\n");
297 else 299 else
298 printk(KERN_WARNING 300 pr_warn("object is not on stack, but annotated\n");
299 "ODEBUG: object is not on stack, but annotated\n");
300 WARN_ON(1); 301 WARN_ON(1);
301} 302}
302 303
@@ -985,7 +986,7 @@ static void __init debug_objects_selftest(void)
985 if (check_results(&obj, ODEBUG_STATE_NONE, ++fixups, ++warnings)) 986 if (check_results(&obj, ODEBUG_STATE_NONE, ++fixups, ++warnings))
986 goto out; 987 goto out;
987#endif 988#endif
988 printk(KERN_INFO "ODEBUG: selftest passed\n"); 989 pr_info("selftest passed\n");
989 990
990out: 991out:
991 debug_objects_fixups = oldfixups; 992 debug_objects_fixups = oldfixups;
@@ -1060,8 +1061,8 @@ static int __init debug_objects_replace_static_objects(void)
1060 } 1061 }
1061 local_irq_enable(); 1062 local_irq_enable();
1062 1063
1063 printk(KERN_DEBUG "ODEBUG: %d of %d active objects replaced\n", cnt, 1064 pr_debug("%d of %d active objects replaced\n",
1064 obj_pool_used); 1065 cnt, obj_pool_used);
1065 return 0; 1066 return 0;
1066free: 1067free:
1067 hlist_for_each_entry_safe(obj, tmp, &objects, node) { 1068 hlist_for_each_entry_safe(obj, tmp, &objects, node) {
@@ -1090,7 +1091,7 @@ void __init debug_objects_mem_init(void)
1090 debug_objects_enabled = 0; 1091 debug_objects_enabled = 0;
1091 if (obj_cache) 1092 if (obj_cache)
1092 kmem_cache_destroy(obj_cache); 1093 kmem_cache_destroy(obj_cache);
1093 printk(KERN_WARNING "ODEBUG: out of memory.\n"); 1094 pr_warn("out of memory.\n");
1094 } else 1095 } else
1095 debug_objects_selftest(); 1096 debug_objects_selftest();
1096} 1097}
diff --git a/lib/decompress.c b/lib/decompress.c
index 4d1cd0397aab..86069d74c062 100644
--- a/lib/decompress.c
+++ b/lib/decompress.c
@@ -16,6 +16,7 @@
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/string.h> 17#include <linux/string.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/printk.h>
19 20
20#ifndef CONFIG_DECOMPRESS_GZIP 21#ifndef CONFIG_DECOMPRESS_GZIP
21# define gunzip NULL 22# define gunzip NULL
@@ -61,6 +62,8 @@ decompress_fn __init decompress_method(const unsigned char *inbuf, int len,
61 if (len < 2) 62 if (len < 2)
62 return NULL; /* Need at least this much... */ 63 return NULL; /* Need at least this much... */
63 64
65 pr_debug("Compressed data magic: %#.2x %#.2x\n", inbuf[0], inbuf[1]);
66
64 for (cf = compressed_formats; cf->name; cf++) { 67 for (cf = compressed_formats; cf->name; cf++) {
65 if (!memcmp(inbuf, cf->magic, 2)) 68 if (!memcmp(inbuf, cf->magic, 2))
66 break; 69 break;
diff --git a/lib/decompress_inflate.c b/lib/decompress_inflate.c
index d619b28c456f..0edfd742a154 100644
--- a/lib/decompress_inflate.c
+++ b/lib/decompress_inflate.c
@@ -19,6 +19,7 @@
19#include "zlib_inflate/inflate.h" 19#include "zlib_inflate/inflate.h"
20 20
21#include "zlib_inflate/infutil.h" 21#include "zlib_inflate/infutil.h"
22#include <linux/decompress/inflate.h>
22 23
23#endif /* STATIC */ 24#endif /* STATIC */
24 25
diff --git a/lib/devres.c b/lib/devres.c
index 823533138fa0..f562bf6ff71d 100644
--- a/lib/devres.c
+++ b/lib/devres.c
@@ -81,11 +81,13 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
81void devm_iounmap(struct device *dev, void __iomem *addr) 81void devm_iounmap(struct device *dev, void __iomem *addr)
82{ 82{
83 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match, 83 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
84 (void *)addr)); 84 (__force void *)addr));
85 iounmap(addr); 85 iounmap(addr);
86} 86}
87EXPORT_SYMBOL(devm_iounmap); 87EXPORT_SYMBOL(devm_iounmap);
88 88
89#define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err)
90
89/** 91/**
90 * devm_ioremap_resource() - check, request region, and ioremap resource 92 * devm_ioremap_resource() - check, request region, and ioremap resource
91 * @dev: generic device to handle the resource for 93 * @dev: generic device to handle the resource for
@@ -114,7 +116,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
114 116
115 if (!res || resource_type(res) != IORESOURCE_MEM) { 117 if (!res || resource_type(res) != IORESOURCE_MEM) {
116 dev_err(dev, "invalid resource\n"); 118 dev_err(dev, "invalid resource\n");
117 return ERR_PTR(-EINVAL); 119 return IOMEM_ERR_PTR(-EINVAL);
118 } 120 }
119 121
120 size = resource_size(res); 122 size = resource_size(res);
@@ -122,7 +124,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
122 124
123 if (!devm_request_mem_region(dev, res->start, size, name)) { 125 if (!devm_request_mem_region(dev, res->start, size, name)) {
124 dev_err(dev, "can't request region for resource %pR\n", res); 126 dev_err(dev, "can't request region for resource %pR\n", res);
125 return ERR_PTR(-EBUSY); 127 return IOMEM_ERR_PTR(-EBUSY);
126 } 128 }
127 129
128 if (res->flags & IORESOURCE_CACHEABLE) 130 if (res->flags & IORESOURCE_CACHEABLE)
@@ -133,7 +135,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
133 if (!dest_ptr) { 135 if (!dest_ptr) {
134 dev_err(dev, "ioremap failed for resource %pR\n", res); 136 dev_err(dev, "ioremap failed for resource %pR\n", res);
135 devm_release_mem_region(dev, res->start, size); 137 devm_release_mem_region(dev, res->start, size);
136 dest_ptr = ERR_PTR(-ENOMEM); 138 dest_ptr = IOMEM_ERR_PTR(-ENOMEM);
137 } 139 }
138 140
139 return dest_ptr; 141 return dest_ptr;
@@ -155,12 +157,12 @@ EXPORT_SYMBOL(devm_ioremap_resource);
155 * if (!base) 157 * if (!base)
156 * return -EADDRNOTAVAIL; 158 * return -EADDRNOTAVAIL;
157 */ 159 */
158void __iomem *devm_request_and_ioremap(struct device *device, 160void __iomem *devm_request_and_ioremap(struct device *dev,
159 struct resource *res) 161 struct resource *res)
160{ 162{
161 void __iomem *dest_ptr; 163 void __iomem *dest_ptr;
162 164
163 dest_ptr = devm_ioremap_resource(device, res); 165 dest_ptr = devm_ioremap_resource(dev, res);
164 if (IS_ERR(dest_ptr)) 166 if (IS_ERR(dest_ptr))
165 return NULL; 167 return NULL;
166 168
@@ -168,7 +170,7 @@ void __iomem *devm_request_and_ioremap(struct device *device,
168} 170}
169EXPORT_SYMBOL(devm_request_and_ioremap); 171EXPORT_SYMBOL(devm_request_and_ioremap);
170 172
171#ifdef CONFIG_HAS_IOPORT 173#ifdef CONFIG_HAS_IOPORT_MAP
172/* 174/*
173 * Generic iomap devres 175 * Generic iomap devres
174 */ 176 */
@@ -192,7 +194,7 @@ static int devm_ioport_map_match(struct device *dev, void *res,
192 * Managed ioport_map(). Map is automatically unmapped on driver 194 * Managed ioport_map(). Map is automatically unmapped on driver
193 * detach. 195 * detach.
194 */ 196 */
195void __iomem * devm_ioport_map(struct device *dev, unsigned long port, 197void __iomem *devm_ioport_map(struct device *dev, unsigned long port,
196 unsigned int nr) 198 unsigned int nr)
197{ 199{
198 void __iomem **ptr, *addr; 200 void __iomem **ptr, *addr;
@@ -224,10 +226,10 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
224{ 226{
225 ioport_unmap(addr); 227 ioport_unmap(addr);
226 WARN_ON(devres_destroy(dev, devm_ioport_map_release, 228 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
227 devm_ioport_map_match, (void *)addr)); 229 devm_ioport_map_match, (__force void *)addr));
228} 230}
229EXPORT_SYMBOL(devm_ioport_unmap); 231EXPORT_SYMBOL(devm_ioport_unmap);
230#endif /* CONFIG_HAS_IOPORT */ 232#endif /* CONFIG_HAS_IOPORT_MAP */
231 233
232#ifdef CONFIG_PCI 234#ifdef CONFIG_PCI
233/* 235/*
@@ -263,7 +265,7 @@ static void pcim_iomap_release(struct device *gendev, void *res)
263 * be safely called without context and guaranteed to succed once 265 * be safely called without context and guaranteed to succed once
264 * allocated. 266 * allocated.
265 */ 267 */
266void __iomem * const * pcim_iomap_table(struct pci_dev *pdev) 268void __iomem * const *pcim_iomap_table(struct pci_dev *pdev)
267{ 269{
268 struct pcim_iomap_devres *dr, *new_dr; 270 struct pcim_iomap_devres *dr, *new_dr;
269 271
@@ -288,7 +290,7 @@ EXPORT_SYMBOL(pcim_iomap_table);
288 * Managed pci_iomap(). Map is automatically unmapped on driver 290 * Managed pci_iomap(). Map is automatically unmapped on driver
289 * detach. 291 * detach.
290 */ 292 */
291void __iomem * pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen) 293void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen)
292{ 294{
293 void __iomem **tbl; 295 void __iomem **tbl;
294 296
diff --git a/lib/digsig.c b/lib/digsig.c
index 8793aeda30ca..ae05ea393fc8 100644
--- a/lib/digsig.c
+++ b/lib/digsig.c
@@ -175,10 +175,11 @@ err1:
175 * digsig_verify() - digital signature verification with public key 175 * digsig_verify() - digital signature verification with public key
176 * @keyring: keyring to search key in 176 * @keyring: keyring to search key in
177 * @sig: digital signature 177 * @sig: digital signature
178 * @sigen: length of the signature 178 * @siglen: length of the signature
179 * @data: data 179 * @data: data
180 * @datalen: length of the data 180 * @datalen: length of the data
181 * @return: 0 on success, -EINVAL otherwise 181 *
182 * Returns 0 on success, -EINVAL otherwise
182 * 183 *
183 * Verifies data integrity against digital signature. 184 * Verifies data integrity against digital signature.
184 * Currently only RSA is supported. 185 * Currently only RSA is supported.
diff --git a/lib/dump_stack.c b/lib/dump_stack.c
index f23b63f0a1c3..6745c6230db3 100644
--- a/lib/dump_stack.c
+++ b/lib/dump_stack.c
@@ -23,7 +23,7 @@ static void __dump_stack(void)
23#ifdef CONFIG_SMP 23#ifdef CONFIG_SMP
24static atomic_t dump_lock = ATOMIC_INIT(-1); 24static atomic_t dump_lock = ATOMIC_INIT(-1);
25 25
26asmlinkage void dump_stack(void) 26asmlinkage __visible void dump_stack(void)
27{ 27{
28 int was_locked; 28 int was_locked;
29 int old; 29 int old;
@@ -55,7 +55,7 @@ retry:
55 preempt_enable(); 55 preempt_enable();
56} 56}
57#else 57#else
58asmlinkage void dump_stack(void) 58asmlinkage __visible void dump_stack(void)
59{ 59{
60 __dump_stack(); 60 __dump_stack();
61} 61}
diff --git a/lib/fdt_empty_tree.c b/lib/fdt_empty_tree.c
new file mode 100644
index 000000000000..5d30c58150ad
--- /dev/null
+++ b/lib/fdt_empty_tree.c
@@ -0,0 +1,2 @@
1#include <linux/libfdt_env.h>
2#include "../scripts/dtc/libfdt/fdt_empty_tree.c"
diff --git a/lib/idr.c b/lib/idr.c
index bfe4db4e165f..39158abebad1 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -18,12 +18,6 @@
18 * pointer or what ever, we treat it as a (void *). You can pass this 18 * pointer or what ever, we treat it as a (void *). You can pass this
19 * id to a user for him to pass back at a later time. You then pass 19 * id to a user for him to pass back at a later time. You then pass
20 * that id to this code and it returns your pointer. 20 * that id to this code and it returns your pointer.
21
22 * You can release ids at any time. When all ids are released, most of
23 * the memory is returned (we keep MAX_IDR_FREE) in a local pool so we
24 * don't need to go to the memory "store" during an id allocate, just
25 * so you don't need to be too concerned about locking and conflicts
26 * with the slab allocator.
27 */ 21 */
28 22
29#ifndef TEST // to test in user space... 23#ifndef TEST // to test in user space...
@@ -151,7 +145,7 @@ static void idr_layer_rcu_free(struct rcu_head *head)
151 145
152static inline void free_layer(struct idr *idr, struct idr_layer *p) 146static inline void free_layer(struct idr *idr, struct idr_layer *p)
153{ 147{
154 if (idr->hint && idr->hint == p) 148 if (idr->hint == p)
155 RCU_INIT_POINTER(idr->hint, NULL); 149 RCU_INIT_POINTER(idr->hint, NULL);
156 call_rcu(&p->rcu_head, idr_layer_rcu_free); 150 call_rcu(&p->rcu_head, idr_layer_rcu_free);
157} 151}
@@ -196,7 +190,7 @@ static void idr_mark_full(struct idr_layer **pa, int id)
196 } 190 }
197} 191}
198 192
199int __idr_pre_get(struct idr *idp, gfp_t gfp_mask) 193static int __idr_pre_get(struct idr *idp, gfp_t gfp_mask)
200{ 194{
201 while (idp->id_free_cnt < MAX_IDR_FREE) { 195 while (idp->id_free_cnt < MAX_IDR_FREE) {
202 struct idr_layer *new; 196 struct idr_layer *new;
@@ -207,7 +201,6 @@ int __idr_pre_get(struct idr *idp, gfp_t gfp_mask)
207 } 201 }
208 return 1; 202 return 1;
209} 203}
210EXPORT_SYMBOL(__idr_pre_get);
211 204
212/** 205/**
213 * sub_alloc - try to allocate an id without growing the tree depth 206 * sub_alloc - try to allocate an id without growing the tree depth
@@ -250,7 +243,7 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa,
250 id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1; 243 id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
251 244
252 /* if already at the top layer, we need to grow */ 245 /* if already at the top layer, we need to grow */
253 if (id >= 1 << (idp->layers * IDR_BITS)) { 246 if (id > idr_max(idp->layers)) {
254 *starting_id = id; 247 *starting_id = id;
255 return -EAGAIN; 248 return -EAGAIN;
256 } 249 }
@@ -374,20 +367,6 @@ static void idr_fill_slot(struct idr *idr, void *ptr, int id,
374 idr_mark_full(pa, id); 367 idr_mark_full(pa, id);
375} 368}
376 369
377int __idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id)
378{
379 struct idr_layer *pa[MAX_IDR_LEVEL + 1];
380 int rv;
381
382 rv = idr_get_empty_slot(idp, starting_id, pa, 0, idp);
383 if (rv < 0)
384 return rv == -ENOMEM ? -EAGAIN : rv;
385
386 idr_fill_slot(idp, ptr, rv, pa);
387 *id = rv;
388 return 0;
389}
390EXPORT_SYMBOL(__idr_get_new_above);
391 370
392/** 371/**
393 * idr_preload - preload for idr_alloc() 372 * idr_preload - preload for idr_alloc()
@@ -548,7 +527,7 @@ static void sub_remove(struct idr *idp, int shift, int id)
548 n = id & IDR_MASK; 527 n = id & IDR_MASK;
549 if (likely(p != NULL && test_bit(n, p->bitmap))) { 528 if (likely(p != NULL && test_bit(n, p->bitmap))) {
550 __clear_bit(n, p->bitmap); 529 __clear_bit(n, p->bitmap);
551 rcu_assign_pointer(p->ary[n], NULL); 530 RCU_INIT_POINTER(p->ary[n], NULL);
552 to_free = NULL; 531 to_free = NULL;
553 while(*paa && ! --((**paa)->count)){ 532 while(*paa && ! --((**paa)->count)){
554 if (to_free) 533 if (to_free)
@@ -577,6 +556,11 @@ void idr_remove(struct idr *idp, int id)
577 if (id < 0) 556 if (id < 0)
578 return; 557 return;
579 558
559 if (id > idr_max(idp->layers)) {
560 idr_remove_warning(id);
561 return;
562 }
563
580 sub_remove(idp, (idp->layers - 1) * IDR_BITS, id); 564 sub_remove(idp, (idp->layers - 1) * IDR_BITS, id);
581 if (idp->top && idp->top->count == 1 && (idp->layers > 1) && 565 if (idp->top && idp->top->count == 1 && (idp->layers > 1) &&
582 idp->top->ary[0]) { 566 idp->top->ary[0]) {
@@ -594,20 +578,10 @@ void idr_remove(struct idr *idp, int id)
594 bitmap_clear(to_free->bitmap, 0, IDR_SIZE); 578 bitmap_clear(to_free->bitmap, 0, IDR_SIZE);
595 free_layer(idp, to_free); 579 free_layer(idp, to_free);
596 } 580 }
597 while (idp->id_free_cnt >= MAX_IDR_FREE) {
598 p = get_from_free_list(idp);
599 /*
600 * Note: we don't call the rcu callback here, since the only
601 * layers that fall into the freelist are those that have been
602 * preallocated.
603 */
604 kmem_cache_free(idr_layer_cache, p);
605 }
606 return;
607} 581}
608EXPORT_SYMBOL(idr_remove); 582EXPORT_SYMBOL(idr_remove);
609 583
610void __idr_remove_all(struct idr *idp) 584static void __idr_remove_all(struct idr *idp)
611{ 585{
612 int n, id, max; 586 int n, id, max;
613 int bt_mask; 587 int bt_mask;
@@ -617,7 +591,7 @@ void __idr_remove_all(struct idr *idp)
617 591
618 n = idp->layers * IDR_BITS; 592 n = idp->layers * IDR_BITS;
619 p = idp->top; 593 p = idp->top;
620 rcu_assign_pointer(idp->top, NULL); 594 RCU_INIT_POINTER(idp->top, NULL);
621 max = idr_max(idp->layers); 595 max = idr_max(idp->layers);
622 596
623 id = 0; 597 id = 0;
@@ -640,7 +614,6 @@ void __idr_remove_all(struct idr *idp)
640 } 614 }
641 idp->layers = 0; 615 idp->layers = 0;
642} 616}
643EXPORT_SYMBOL(__idr_remove_all);
644 617
645/** 618/**
646 * idr_destroy - release all cached layers within an idr tree 619 * idr_destroy - release all cached layers within an idr tree
@@ -825,14 +798,12 @@ void *idr_replace(struct idr *idp, void *ptr, int id)
825 798
826 p = idp->top; 799 p = idp->top;
827 if (!p) 800 if (!p)
828 return ERR_PTR(-EINVAL); 801 return ERR_PTR(-ENOENT);
829
830 n = (p->layer+1) * IDR_BITS;
831 802
832 if (id >= (1 << n)) 803 if (id > idr_max(p->layer + 1))
833 return ERR_PTR(-EINVAL); 804 return ERR_PTR(-ENOENT);
834 805
835 n -= IDR_BITS; 806 n = p->layer * IDR_BITS;
836 while ((n > 0) && p) { 807 while ((n > 0) && p) {
837 p = p->ary[(id >> n) & IDR_MASK]; 808 p = p->ary[(id >> n) & IDR_MASK];
838 n -= IDR_BITS; 809 n -= IDR_BITS;
@@ -869,6 +840,16 @@ void idr_init(struct idr *idp)
869} 840}
870EXPORT_SYMBOL(idr_init); 841EXPORT_SYMBOL(idr_init);
871 842
843static int idr_has_entry(int id, void *p, void *data)
844{
845 return 1;
846}
847
848bool idr_is_empty(struct idr *idp)
849{
850 return !idr_for_each(idp, idr_has_entry, NULL);
851}
852EXPORT_SYMBOL(idr_is_empty);
872 853
873/** 854/**
874 * DOC: IDA description 855 * DOC: IDA description
@@ -1033,6 +1014,9 @@ void ida_remove(struct ida *ida, int id)
1033 int n; 1014 int n;
1034 struct ida_bitmap *bitmap; 1015 struct ida_bitmap *bitmap;
1035 1016
1017 if (idr_id > idr_max(ida->idr.layers))
1018 goto err;
1019
1036 /* clear full bits while looking up the leaf idr_layer */ 1020 /* clear full bits while looking up the leaf idr_layer */
1037 while ((shift > 0) && p) { 1021 while ((shift > 0) && p) {
1038 n = (idr_id >> shift) & IDR_MASK; 1022 n = (idr_id >> shift) & IDR_MASK;
@@ -1048,7 +1032,7 @@ void ida_remove(struct ida *ida, int id)
1048 __clear_bit(n, p->bitmap); 1032 __clear_bit(n, p->bitmap);
1049 1033
1050 bitmap = (void *)p->ary[n]; 1034 bitmap = (void *)p->ary[n];
1051 if (!test_bit(offset, bitmap->bitmap)) 1035 if (!bitmap || !test_bit(offset, bitmap->bitmap))
1052 goto err; 1036 goto err;
1053 1037
1054 /* update bitmap and remove it if empty */ 1038 /* update bitmap and remove it if empty */
diff --git a/lib/iomap.c b/lib/iomap.c
index 2c08f36862eb..fc3dcb4b238e 100644
--- a/lib/iomap.c
+++ b/lib/iomap.c
@@ -224,7 +224,7 @@ EXPORT_SYMBOL(iowrite8_rep);
224EXPORT_SYMBOL(iowrite16_rep); 224EXPORT_SYMBOL(iowrite16_rep);
225EXPORT_SYMBOL(iowrite32_rep); 225EXPORT_SYMBOL(iowrite32_rep);
226 226
227#ifdef CONFIG_HAS_IOPORT 227#ifdef CONFIG_HAS_IOPORT_MAP
228/* Create a virtual mapping cookie for an IO port range */ 228/* Create a virtual mapping cookie for an IO port range */
229void __iomem *ioport_map(unsigned long port, unsigned int nr) 229void __iomem *ioport_map(unsigned long port, unsigned int nr)
230{ 230{
@@ -239,7 +239,7 @@ void ioport_unmap(void __iomem *addr)
239} 239}
240EXPORT_SYMBOL(ioport_map); 240EXPORT_SYMBOL(ioport_map);
241EXPORT_SYMBOL(ioport_unmap); 241EXPORT_SYMBOL(ioport_unmap);
242#endif /* CONFIG_HAS_IOPORT */ 242#endif /* CONFIG_HAS_IOPORT_MAP */
243 243
244#ifdef CONFIG_PCI 244#ifdef CONFIG_PCI
245/* Hide the details if this is a MMIO or PIO address space and just do what 245/* Hide the details if this is a MMIO or PIO address space and just do what
diff --git a/lib/kobject.c b/lib/kobject.c
index cb14aeac4cca..58751bb80a7c 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -94,7 +94,7 @@ static int create_dir(struct kobject *kobj)
94 BUG_ON(ops->type >= KOBJ_NS_TYPES); 94 BUG_ON(ops->type >= KOBJ_NS_TYPES);
95 BUG_ON(!kobj_ns_type_registered(ops->type)); 95 BUG_ON(!kobj_ns_type_registered(ops->type));
96 96
97 kernfs_enable_ns(kobj->sd); 97 sysfs_enable_ns(kobj->sd);
98 } 98 }
99 99
100 return 0; 100 return 0;
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 5f72767ddd9b..9ebf9e20de53 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -29,7 +29,9 @@
29 29
30 30
31u64 uevent_seqnum; 31u64 uevent_seqnum;
32#ifdef CONFIG_UEVENT_HELPER
32char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH; 33char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH;
34#endif
33#ifdef CONFIG_NET 35#ifdef CONFIG_NET
34struct uevent_sock { 36struct uevent_sock {
35 struct list_head list; 37 struct list_head list;
@@ -109,6 +111,7 @@ static int kobj_bcast_filter(struct sock *dsk, struct sk_buff *skb, void *data)
109} 111}
110#endif 112#endif
111 113
114#ifdef CONFIG_UEVENT_HELPER
112static int kobj_usermode_filter(struct kobject *kobj) 115static int kobj_usermode_filter(struct kobject *kobj)
113{ 116{
114 const struct kobj_ns_type_operations *ops; 117 const struct kobj_ns_type_operations *ops;
@@ -124,6 +127,31 @@ static int kobj_usermode_filter(struct kobject *kobj)
124 return 0; 127 return 0;
125} 128}
126 129
130static int init_uevent_argv(struct kobj_uevent_env *env, const char *subsystem)
131{
132 int len;
133
134 len = strlcpy(&env->buf[env->buflen], subsystem,
135 sizeof(env->buf) - env->buflen);
136 if (len >= (sizeof(env->buf) - env->buflen)) {
137 WARN(1, KERN_ERR "init_uevent_argv: buffer size too small\n");
138 return -ENOMEM;
139 }
140
141 env->argv[0] = uevent_helper;
142 env->argv[1] = &env->buf[env->buflen];
143 env->argv[2] = NULL;
144
145 env->buflen += len + 1;
146 return 0;
147}
148
149static void cleanup_uevent_env(struct subprocess_info *info)
150{
151 kfree(info->data);
152}
153#endif
154
127/** 155/**
128 * kobject_uevent_env - send an uevent with environmental data 156 * kobject_uevent_env - send an uevent with environmental data
129 * 157 *
@@ -299,13 +327,11 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
299#endif 327#endif
300 mutex_unlock(&uevent_sock_mutex); 328 mutex_unlock(&uevent_sock_mutex);
301 329
330#ifdef CONFIG_UEVENT_HELPER
302 /* call uevent_helper, usually only enabled during early boot */ 331 /* call uevent_helper, usually only enabled during early boot */
303 if (uevent_helper[0] && !kobj_usermode_filter(kobj)) { 332 if (uevent_helper[0] && !kobj_usermode_filter(kobj)) {
304 char *argv [3]; 333 struct subprocess_info *info;
305 334
306 argv [0] = uevent_helper;
307 argv [1] = (char *)subsystem;
308 argv [2] = NULL;
309 retval = add_uevent_var(env, "HOME=/"); 335 retval = add_uevent_var(env, "HOME=/");
310 if (retval) 336 if (retval)
311 goto exit; 337 goto exit;
@@ -313,10 +339,20 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
313 "PATH=/sbin:/bin:/usr/sbin:/usr/bin"); 339 "PATH=/sbin:/bin:/usr/sbin:/usr/bin");
314 if (retval) 340 if (retval)
315 goto exit; 341 goto exit;
342 retval = init_uevent_argv(env, subsystem);
343 if (retval)
344 goto exit;
316 345
317 retval = call_usermodehelper(argv[0], argv, 346 retval = -ENOMEM;
318 env->envp, UMH_WAIT_EXEC); 347 info = call_usermodehelper_setup(env->argv[0], env->argv,
348 env->envp, GFP_KERNEL,
349 NULL, cleanup_uevent_env, env);
350 if (info) {
351 retval = call_usermodehelper_exec(info, UMH_NO_WAIT);
352 env = NULL; /* freed by cleanup_uevent_env */
353 }
319 } 354 }
355#endif
320 356
321exit: 357exit:
322 kfree(devpath); 358 kfree(devpath);
diff --git a/lib/libcrc32c.c b/lib/libcrc32c.c
index 244f5480c898..b3131f5cf8a2 100644
--- a/lib/libcrc32c.c
+++ b/lib/libcrc32c.c
@@ -62,10 +62,7 @@ EXPORT_SYMBOL(crc32c);
62static int __init libcrc32c_mod_init(void) 62static int __init libcrc32c_mod_init(void)
63{ 63{
64 tfm = crypto_alloc_shash("crc32c", 0, 0); 64 tfm = crypto_alloc_shash("crc32c", 0, 0);
65 if (IS_ERR(tfm)) 65 return PTR_ERR_OR_ZERO(tfm);
66 return PTR_ERR(tfm);
67
68 return 0;
69} 66}
70 67
71static void __exit libcrc32c_mod_fini(void) 68static void __exit libcrc32c_mod_fini(void)
diff --git a/lib/nlattr.c b/lib/nlattr.c
index 18eca7809b08..9c3e85ff0a6c 100644
--- a/lib/nlattr.c
+++ b/lib/nlattr.c
@@ -136,6 +136,7 @@ int nla_validate(const struct nlattr *head, int len, int maxtype,
136errout: 136errout:
137 return err; 137 return err;
138} 138}
139EXPORT_SYMBOL(nla_validate);
139 140
140/** 141/**
141 * nla_policy_len - Determin the max. length of a policy 142 * nla_policy_len - Determin the max. length of a policy
@@ -162,6 +163,7 @@ nla_policy_len(const struct nla_policy *p, int n)
162 163
163 return len; 164 return len;
164} 165}
166EXPORT_SYMBOL(nla_policy_len);
165 167
166/** 168/**
167 * nla_parse - Parse a stream of attributes into a tb buffer 169 * nla_parse - Parse a stream of attributes into a tb buffer
@@ -201,13 +203,14 @@ int nla_parse(struct nlattr **tb, int maxtype, const struct nlattr *head,
201 } 203 }
202 204
203 if (unlikely(rem > 0)) 205 if (unlikely(rem > 0))
204 printk(KERN_WARNING "netlink: %d bytes leftover after parsing " 206 pr_warn_ratelimited("netlink: %d bytes leftover after parsing attributes in process `%s'.\n",
205 "attributes.\n", rem); 207 rem, current->comm);
206 208
207 err = 0; 209 err = 0;
208errout: 210errout:
209 return err; 211 return err;
210} 212}
213EXPORT_SYMBOL(nla_parse);
211 214
212/** 215/**
213 * nla_find - Find a specific attribute in a stream of attributes 216 * nla_find - Find a specific attribute in a stream of attributes
@@ -228,6 +231,7 @@ struct nlattr *nla_find(const struct nlattr *head, int len, int attrtype)
228 231
229 return NULL; 232 return NULL;
230} 233}
234EXPORT_SYMBOL(nla_find);
231 235
232/** 236/**
233 * nla_strlcpy - Copy string attribute payload into a sized buffer 237 * nla_strlcpy - Copy string attribute payload into a sized buffer
@@ -258,6 +262,7 @@ size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize)
258 262
259 return srclen; 263 return srclen;
260} 264}
265EXPORT_SYMBOL(nla_strlcpy);
261 266
262/** 267/**
263 * nla_memcpy - Copy a netlink attribute into another memory area 268 * nla_memcpy - Copy a netlink attribute into another memory area
@@ -278,6 +283,7 @@ int nla_memcpy(void *dest, const struct nlattr *src, int count)
278 283
279 return minlen; 284 return minlen;
280} 285}
286EXPORT_SYMBOL(nla_memcpy);
281 287
282/** 288/**
283 * nla_memcmp - Compare an attribute with sized memory area 289 * nla_memcmp - Compare an attribute with sized memory area
@@ -295,6 +301,7 @@ int nla_memcmp(const struct nlattr *nla, const void *data,
295 301
296 return d; 302 return d;
297} 303}
304EXPORT_SYMBOL(nla_memcmp);
298 305
299/** 306/**
300 * nla_strcmp - Compare a string attribute against a string 307 * nla_strcmp - Compare a string attribute against a string
@@ -303,14 +310,21 @@ int nla_memcmp(const struct nlattr *nla, const void *data,
303 */ 310 */
304int nla_strcmp(const struct nlattr *nla, const char *str) 311int nla_strcmp(const struct nlattr *nla, const char *str)
305{ 312{
306 int len = strlen(str) + 1; 313 int len = strlen(str);
307 int d = nla_len(nla) - len; 314 char *buf = nla_data(nla);
315 int attrlen = nla_len(nla);
316 int d;
308 317
318 if (attrlen > 0 && buf[attrlen - 1] == '\0')
319 attrlen--;
320
321 d = attrlen - len;
309 if (d == 0) 322 if (d == 0)
310 d = memcmp(nla_data(nla), str, len); 323 d = memcmp(nla_data(nla), str, len);
311 324
312 return d; 325 return d;
313} 326}
327EXPORT_SYMBOL(nla_strcmp);
314 328
315#ifdef CONFIG_NET 329#ifdef CONFIG_NET
316/** 330/**
@@ -496,12 +510,3 @@ int nla_append(struct sk_buff *skb, int attrlen, const void *data)
496} 510}
497EXPORT_SYMBOL(nla_append); 511EXPORT_SYMBOL(nla_append);
498#endif 512#endif
499
500EXPORT_SYMBOL(nla_validate);
501EXPORT_SYMBOL(nla_policy_len);
502EXPORT_SYMBOL(nla_parse);
503EXPORT_SYMBOL(nla_find);
504EXPORT_SYMBOL(nla_strlcpy);
505EXPORT_SYMBOL(nla_memcpy);
506EXPORT_SYMBOL(nla_memcmp);
507EXPORT_SYMBOL(nla_strcmp);
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index 8280a5dd1727..7dd33577b905 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -169,7 +169,7 @@ static int percpu_counter_hotcpu_callback(struct notifier_block *nb,
169 struct percpu_counter *fbc; 169 struct percpu_counter *fbc;
170 170
171 compute_batch_value(); 171 compute_batch_value();
172 if (action != CPU_DEAD) 172 if (action != CPU_DEAD && action != CPU_DEAD_FROZEN)
173 return NOTIFY_OK; 173 return NOTIFY_OK;
174 174
175 cpu = (unsigned long)hcpu; 175 cpu = (unsigned long)hcpu;
diff --git a/lib/plist.c b/lib/plist.c
index 1ebc95f7a46f..d408e774b746 100644
--- a/lib/plist.c
+++ b/lib/plist.c
@@ -134,6 +134,46 @@ void plist_del(struct plist_node *node, struct plist_head *head)
134 plist_check_head(head); 134 plist_check_head(head);
135} 135}
136 136
137/**
138 * plist_requeue - Requeue @node at end of same-prio entries.
139 *
140 * This is essentially an optimized plist_del() followed by
141 * plist_add(). It moves an entry already in the plist to
142 * after any other same-priority entries.
143 *
144 * @node: &struct plist_node pointer - entry to be moved
145 * @head: &struct plist_head pointer - list head
146 */
147void plist_requeue(struct plist_node *node, struct plist_head *head)
148{
149 struct plist_node *iter;
150 struct list_head *node_next = &head->node_list;
151
152 plist_check_head(head);
153 BUG_ON(plist_head_empty(head));
154 BUG_ON(plist_node_empty(node));
155
156 if (node == plist_last(head))
157 return;
158
159 iter = plist_next(node);
160
161 if (node->prio != iter->prio)
162 return;
163
164 plist_del(node, head);
165
166 plist_for_each_continue(iter, head) {
167 if (node->prio != iter->prio) {
168 node_next = &iter->node_list;
169 break;
170 }
171 }
172 list_add_tail(&node->node_list, node_next);
173
174 plist_check_head(head);
175}
176
137#ifdef CONFIG_DEBUG_PI_LIST 177#ifdef CONFIG_DEBUG_PI_LIST
138#include <linux/sched.h> 178#include <linux/sched.h>
139#include <linux/module.h> 179#include <linux/module.h>
@@ -170,12 +210,20 @@ static void __init plist_test_check(int nr_expect)
170 BUG_ON(prio_pos->prio_list.next != &first->prio_list); 210 BUG_ON(prio_pos->prio_list.next != &first->prio_list);
171} 211}
172 212
213static void __init plist_test_requeue(struct plist_node *node)
214{
215 plist_requeue(node, &test_head);
216
217 if (node != plist_last(&test_head))
218 BUG_ON(node->prio == plist_next(node)->prio);
219}
220
173static int __init plist_test(void) 221static int __init plist_test(void)
174{ 222{
175 int nr_expect = 0, i, loop; 223 int nr_expect = 0, i, loop;
176 unsigned int r = local_clock(); 224 unsigned int r = local_clock();
177 225
178 pr_debug("start plist test\n"); 226 printk(KERN_DEBUG "start plist test\n");
179 plist_head_init(&test_head); 227 plist_head_init(&test_head);
180 for (i = 0; i < ARRAY_SIZE(test_node); i++) 228 for (i = 0; i < ARRAY_SIZE(test_node); i++)
181 plist_node_init(test_node + i, 0); 229 plist_node_init(test_node + i, 0);
@@ -193,6 +241,10 @@ static int __init plist_test(void)
193 nr_expect--; 241 nr_expect--;
194 } 242 }
195 plist_test_check(nr_expect); 243 plist_test_check(nr_expect);
244 if (!plist_node_empty(test_node + i)) {
245 plist_test_requeue(test_node + i);
246 plist_test_check(nr_expect);
247 }
196 } 248 }
197 249
198 for (i = 0; i < ARRAY_SIZE(test_node); i++) { 250 for (i = 0; i < ARRAY_SIZE(test_node); i++) {
@@ -203,7 +255,7 @@ static int __init plist_test(void)
203 plist_test_check(nr_expect); 255 plist_test_check(nr_expect);
204 } 256 }
205 257
206 pr_debug("end plist test\n"); 258 printk(KERN_DEBUG "end plist test\n");
207 return 0; 259 return 0;
208} 260}
209 261
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index bd4a8dfdf0b8..3291a8e37490 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -27,6 +27,7 @@
27#include <linux/radix-tree.h> 27#include <linux/radix-tree.h>
28#include <linux/percpu.h> 28#include <linux/percpu.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/kmemleak.h>
30#include <linux/notifier.h> 31#include <linux/notifier.h>
31#include <linux/cpu.h> 32#include <linux/cpu.h>
32#include <linux/string.h> 33#include <linux/string.h>
@@ -35,33 +36,6 @@
35#include <linux/hardirq.h> /* in_interrupt() */ 36#include <linux/hardirq.h> /* in_interrupt() */
36 37
37 38
38#ifdef __KERNEL__
39#define RADIX_TREE_MAP_SHIFT (CONFIG_BASE_SMALL ? 4 : 6)
40#else
41#define RADIX_TREE_MAP_SHIFT 3 /* For more stressful testing */
42#endif
43
44#define RADIX_TREE_MAP_SIZE (1UL << RADIX_TREE_MAP_SHIFT)
45#define RADIX_TREE_MAP_MASK (RADIX_TREE_MAP_SIZE-1)
46
47#define RADIX_TREE_TAG_LONGS \
48 ((RADIX_TREE_MAP_SIZE + BITS_PER_LONG - 1) / BITS_PER_LONG)
49
50struct radix_tree_node {
51 unsigned int height; /* Height from the bottom */
52 unsigned int count;
53 union {
54 struct radix_tree_node *parent; /* Used when ascending tree */
55 struct rcu_head rcu_head; /* Used when freeing node */
56 };
57 void __rcu *slots[RADIX_TREE_MAP_SIZE];
58 unsigned long tags[RADIX_TREE_MAX_TAGS][RADIX_TREE_TAG_LONGS];
59};
60
61#define RADIX_TREE_INDEX_BITS (8 /* CHAR_BIT */ * sizeof(unsigned long))
62#define RADIX_TREE_MAX_PATH (DIV_ROUND_UP(RADIX_TREE_INDEX_BITS, \
63 RADIX_TREE_MAP_SHIFT))
64
65/* 39/*
66 * The height_to_maxindex array needs to be one deeper than the maximum 40 * The height_to_maxindex array needs to be one deeper than the maximum
67 * path as height 0 holds only 1 entry. 41 * path as height 0 holds only 1 entry.
@@ -221,12 +195,17 @@ radix_tree_node_alloc(struct radix_tree_root *root)
221 * succeed in getting a node here (and never reach 195 * succeed in getting a node here (and never reach
222 * kmem_cache_alloc) 196 * kmem_cache_alloc)
223 */ 197 */
224 rtp = &__get_cpu_var(radix_tree_preloads); 198 rtp = this_cpu_ptr(&radix_tree_preloads);
225 if (rtp->nr) { 199 if (rtp->nr) {
226 ret = rtp->nodes[rtp->nr - 1]; 200 ret = rtp->nodes[rtp->nr - 1];
227 rtp->nodes[rtp->nr - 1] = NULL; 201 rtp->nodes[rtp->nr - 1] = NULL;
228 rtp->nr--; 202 rtp->nr--;
229 } 203 }
204 /*
205 * Update the allocation stack trace as this is more useful
206 * for debugging.
207 */
208 kmemleak_update_trace(ret);
230 } 209 }
231 if (ret == NULL) 210 if (ret == NULL)
232 ret = kmem_cache_alloc(radix_tree_node_cachep, gfp_mask); 211 ret = kmem_cache_alloc(radix_tree_node_cachep, gfp_mask);
@@ -277,14 +256,14 @@ static int __radix_tree_preload(gfp_t gfp_mask)
277 int ret = -ENOMEM; 256 int ret = -ENOMEM;
278 257
279 preempt_disable(); 258 preempt_disable();
280 rtp = &__get_cpu_var(radix_tree_preloads); 259 rtp = this_cpu_ptr(&radix_tree_preloads);
281 while (rtp->nr < ARRAY_SIZE(rtp->nodes)) { 260 while (rtp->nr < ARRAY_SIZE(rtp->nodes)) {
282 preempt_enable(); 261 preempt_enable();
283 node = kmem_cache_alloc(radix_tree_node_cachep, gfp_mask); 262 node = kmem_cache_alloc(radix_tree_node_cachep, gfp_mask);
284 if (node == NULL) 263 if (node == NULL)
285 goto out; 264 goto out;
286 preempt_disable(); 265 preempt_disable();
287 rtp = &__get_cpu_var(radix_tree_preloads); 266 rtp = this_cpu_ptr(&radix_tree_preloads);
288 if (rtp->nr < ARRAY_SIZE(rtp->nodes)) 267 if (rtp->nr < ARRAY_SIZE(rtp->nodes))
289 rtp->nodes[rtp->nr++] = node; 268 rtp->nodes[rtp->nr++] = node;
290 else 269 else
@@ -369,7 +348,8 @@ static int radix_tree_extend(struct radix_tree_root *root, unsigned long index)
369 348
370 /* Increase the height. */ 349 /* Increase the height. */
371 newheight = root->height+1; 350 newheight = root->height+1;
372 node->height = newheight; 351 BUG_ON(newheight & ~RADIX_TREE_HEIGHT_MASK);
352 node->path = newheight;
373 node->count = 1; 353 node->count = 1;
374 node->parent = NULL; 354 node->parent = NULL;
375 slot = root->rnode; 355 slot = root->rnode;
@@ -387,23 +367,28 @@ out:
387} 367}
388 368
389/** 369/**
390 * radix_tree_insert - insert into a radix tree 370 * __radix_tree_create - create a slot in a radix tree
391 * @root: radix tree root 371 * @root: radix tree root
392 * @index: index key 372 * @index: index key
393 * @item: item to insert 373 * @nodep: returns node
374 * @slotp: returns slot
394 * 375 *
395 * Insert an item into the radix tree at position @index. 376 * Create, if necessary, and return the node and slot for an item
377 * at position @index in the radix tree @root.
378 *
379 * Until there is more than one item in the tree, no nodes are
380 * allocated and @root->rnode is used as a direct slot instead of
381 * pointing to a node, in which case *@nodep will be NULL.
382 *
383 * Returns -ENOMEM, or 0 for success.
396 */ 384 */
397int radix_tree_insert(struct radix_tree_root *root, 385int __radix_tree_create(struct radix_tree_root *root, unsigned long index,
398 unsigned long index, void *item) 386 struct radix_tree_node **nodep, void ***slotp)
399{ 387{
400 struct radix_tree_node *node = NULL, *slot; 388 struct radix_tree_node *node = NULL, *slot;
401 unsigned int height, shift; 389 unsigned int height, shift, offset;
402 int offset;
403 int error; 390 int error;
404 391
405 BUG_ON(radix_tree_is_indirect_ptr(item));
406
407 /* Make sure the tree is high enough. */ 392 /* Make sure the tree is high enough. */
408 if (index > radix_tree_maxindex(root->height)) { 393 if (index > radix_tree_maxindex(root->height)) {
409 error = radix_tree_extend(root, index); 394 error = radix_tree_extend(root, index);
@@ -422,11 +407,12 @@ int radix_tree_insert(struct radix_tree_root *root,
422 /* Have to add a child node. */ 407 /* Have to add a child node. */
423 if (!(slot = radix_tree_node_alloc(root))) 408 if (!(slot = radix_tree_node_alloc(root)))
424 return -ENOMEM; 409 return -ENOMEM;
425 slot->height = height; 410 slot->path = height;
426 slot->parent = node; 411 slot->parent = node;
427 if (node) { 412 if (node) {
428 rcu_assign_pointer(node->slots[offset], slot); 413 rcu_assign_pointer(node->slots[offset], slot);
429 node->count++; 414 node->count++;
415 slot->path |= offset << RADIX_TREE_HEIGHT_SHIFT;
430 } else 416 } else
431 rcu_assign_pointer(root->rnode, ptr_to_indirect(slot)); 417 rcu_assign_pointer(root->rnode, ptr_to_indirect(slot));
432 } 418 }
@@ -439,16 +425,42 @@ int radix_tree_insert(struct radix_tree_root *root,
439 height--; 425 height--;
440 } 426 }
441 427
442 if (slot != NULL) 428 if (nodep)
429 *nodep = node;
430 if (slotp)
431 *slotp = node ? node->slots + offset : (void **)&root->rnode;
432 return 0;
433}
434
435/**
436 * radix_tree_insert - insert into a radix tree
437 * @root: radix tree root
438 * @index: index key
439 * @item: item to insert
440 *
441 * Insert an item into the radix tree at position @index.
442 */
443int radix_tree_insert(struct radix_tree_root *root,
444 unsigned long index, void *item)
445{
446 struct radix_tree_node *node;
447 void **slot;
448 int error;
449
450 BUG_ON(radix_tree_is_indirect_ptr(item));
451
452 error = __radix_tree_create(root, index, &node, &slot);
453 if (error)
454 return error;
455 if (*slot != NULL)
443 return -EEXIST; 456 return -EEXIST;
457 rcu_assign_pointer(*slot, item);
444 458
445 if (node) { 459 if (node) {
446 node->count++; 460 node->count++;
447 rcu_assign_pointer(node->slots[offset], item); 461 BUG_ON(tag_get(node, 0, index & RADIX_TREE_MAP_MASK));
448 BUG_ON(tag_get(node, 0, offset)); 462 BUG_ON(tag_get(node, 1, index & RADIX_TREE_MAP_MASK));
449 BUG_ON(tag_get(node, 1, offset));
450 } else { 463 } else {
451 rcu_assign_pointer(root->rnode, item);
452 BUG_ON(root_tag_get(root, 0)); 464 BUG_ON(root_tag_get(root, 0));
453 BUG_ON(root_tag_get(root, 1)); 465 BUG_ON(root_tag_get(root, 1));
454 } 466 }
@@ -457,15 +469,26 @@ int radix_tree_insert(struct radix_tree_root *root,
457} 469}
458EXPORT_SYMBOL(radix_tree_insert); 470EXPORT_SYMBOL(radix_tree_insert);
459 471
460/* 472/**
461 * is_slot == 1 : search for the slot. 473 * __radix_tree_lookup - lookup an item in a radix tree
462 * is_slot == 0 : search for the node. 474 * @root: radix tree root
475 * @index: index key
476 * @nodep: returns node
477 * @slotp: returns slot
478 *
479 * Lookup and return the item at position @index in the radix
480 * tree @root.
481 *
482 * Until there is more than one item in the tree, no nodes are
483 * allocated and @root->rnode is used as a direct slot instead of
484 * pointing to a node, in which case *@nodep will be NULL.
463 */ 485 */
464static void *radix_tree_lookup_element(struct radix_tree_root *root, 486void *__radix_tree_lookup(struct radix_tree_root *root, unsigned long index,
465 unsigned long index, int is_slot) 487 struct radix_tree_node **nodep, void ***slotp)
466{ 488{
489 struct radix_tree_node *node, *parent;
467 unsigned int height, shift; 490 unsigned int height, shift;
468 struct radix_tree_node *node, **slot; 491 void **slot;
469 492
470 node = rcu_dereference_raw(root->rnode); 493 node = rcu_dereference_raw(root->rnode);
471 if (node == NULL) 494 if (node == NULL)
@@ -474,19 +497,24 @@ static void *radix_tree_lookup_element(struct radix_tree_root *root,
474 if (!radix_tree_is_indirect_ptr(node)) { 497 if (!radix_tree_is_indirect_ptr(node)) {
475 if (index > 0) 498 if (index > 0)
476 return NULL; 499 return NULL;
477 return is_slot ? (void *)&root->rnode : node; 500
501 if (nodep)
502 *nodep = NULL;
503 if (slotp)
504 *slotp = (void **)&root->rnode;
505 return node;
478 } 506 }
479 node = indirect_to_ptr(node); 507 node = indirect_to_ptr(node);
480 508
481 height = node->height; 509 height = node->path & RADIX_TREE_HEIGHT_MASK;
482 if (index > radix_tree_maxindex(height)) 510 if (index > radix_tree_maxindex(height))
483 return NULL; 511 return NULL;
484 512
485 shift = (height-1) * RADIX_TREE_MAP_SHIFT; 513 shift = (height-1) * RADIX_TREE_MAP_SHIFT;
486 514
487 do { 515 do {
488 slot = (struct radix_tree_node **) 516 parent = node;
489 (node->slots + ((index>>shift) & RADIX_TREE_MAP_MASK)); 517 slot = node->slots + ((index >> shift) & RADIX_TREE_MAP_MASK);
490 node = rcu_dereference_raw(*slot); 518 node = rcu_dereference_raw(*slot);
491 if (node == NULL) 519 if (node == NULL)
492 return NULL; 520 return NULL;
@@ -495,7 +523,11 @@ static void *radix_tree_lookup_element(struct radix_tree_root *root,
495 height--; 523 height--;
496 } while (height > 0); 524 } while (height > 0);
497 525
498 return is_slot ? (void *)slot : indirect_to_ptr(node); 526 if (nodep)
527 *nodep = parent;
528 if (slotp)
529 *slotp = slot;
530 return node;
499} 531}
500 532
501/** 533/**
@@ -513,7 +545,11 @@ static void *radix_tree_lookup_element(struct radix_tree_root *root,
513 */ 545 */
514void **radix_tree_lookup_slot(struct radix_tree_root *root, unsigned long index) 546void **radix_tree_lookup_slot(struct radix_tree_root *root, unsigned long index)
515{ 547{
516 return (void **)radix_tree_lookup_element(root, index, 1); 548 void **slot;
549
550 if (!__radix_tree_lookup(root, index, NULL, &slot))
551 return NULL;
552 return slot;
517} 553}
518EXPORT_SYMBOL(radix_tree_lookup_slot); 554EXPORT_SYMBOL(radix_tree_lookup_slot);
519 555
@@ -531,7 +567,7 @@ EXPORT_SYMBOL(radix_tree_lookup_slot);
531 */ 567 */
532void *radix_tree_lookup(struct radix_tree_root *root, unsigned long index) 568void *radix_tree_lookup(struct radix_tree_root *root, unsigned long index)
533{ 569{
534 return radix_tree_lookup_element(root, index, 0); 570 return __radix_tree_lookup(root, index, NULL, NULL);
535} 571}
536EXPORT_SYMBOL(radix_tree_lookup); 572EXPORT_SYMBOL(radix_tree_lookup);
537 573
@@ -676,7 +712,7 @@ int radix_tree_tag_get(struct radix_tree_root *root,
676 return (index == 0); 712 return (index == 0);
677 node = indirect_to_ptr(node); 713 node = indirect_to_ptr(node);
678 714
679 height = node->height; 715 height = node->path & RADIX_TREE_HEIGHT_MASK;
680 if (index > radix_tree_maxindex(height)) 716 if (index > radix_tree_maxindex(height))
681 return 0; 717 return 0;
682 718
@@ -713,7 +749,7 @@ void **radix_tree_next_chunk(struct radix_tree_root *root,
713{ 749{
714 unsigned shift, tag = flags & RADIX_TREE_ITER_TAG_MASK; 750 unsigned shift, tag = flags & RADIX_TREE_ITER_TAG_MASK;
715 struct radix_tree_node *rnode, *node; 751 struct radix_tree_node *rnode, *node;
716 unsigned long index, offset; 752 unsigned long index, offset, height;
717 753
718 if ((flags & RADIX_TREE_ITER_TAGGED) && !root_tag_get(root, tag)) 754 if ((flags & RADIX_TREE_ITER_TAGGED) && !root_tag_get(root, tag))
719 return NULL; 755 return NULL;
@@ -744,7 +780,8 @@ void **radix_tree_next_chunk(struct radix_tree_root *root,
744 return NULL; 780 return NULL;
745 781
746restart: 782restart:
747 shift = (rnode->height - 1) * RADIX_TREE_MAP_SHIFT; 783 height = rnode->path & RADIX_TREE_HEIGHT_MASK;
784 shift = (height - 1) * RADIX_TREE_MAP_SHIFT;
748 offset = index >> shift; 785 offset = index >> shift;
749 786
750 /* Index outside of the tree */ 787 /* Index outside of the tree */
@@ -946,81 +983,6 @@ next:
946} 983}
947EXPORT_SYMBOL(radix_tree_range_tag_if_tagged); 984EXPORT_SYMBOL(radix_tree_range_tag_if_tagged);
948 985
949
950/**
951 * radix_tree_next_hole - find the next hole (not-present entry)
952 * @root: tree root
953 * @index: index key
954 * @max_scan: maximum range to search
955 *
956 * Search the set [index, min(index+max_scan-1, MAX_INDEX)] for the lowest
957 * indexed hole.
958 *
959 * Returns: the index of the hole if found, otherwise returns an index
960 * outside of the set specified (in which case 'return - index >= max_scan'
961 * will be true). In rare cases of index wrap-around, 0 will be returned.
962 *
963 * radix_tree_next_hole may be called under rcu_read_lock. However, like
964 * radix_tree_gang_lookup, this will not atomically search a snapshot of
965 * the tree at a single point in time. For example, if a hole is created
966 * at index 5, then subsequently a hole is created at index 10,
967 * radix_tree_next_hole covering both indexes may return 10 if called
968 * under rcu_read_lock.
969 */
970unsigned long radix_tree_next_hole(struct radix_tree_root *root,
971 unsigned long index, unsigned long max_scan)
972{
973 unsigned long i;
974
975 for (i = 0; i < max_scan; i++) {
976 if (!radix_tree_lookup(root, index))
977 break;
978 index++;
979 if (index == 0)
980 break;
981 }
982
983 return index;
984}
985EXPORT_SYMBOL(radix_tree_next_hole);
986
987/**
988 * radix_tree_prev_hole - find the prev hole (not-present entry)
989 * @root: tree root
990 * @index: index key
991 * @max_scan: maximum range to search
992 *
993 * Search backwards in the range [max(index-max_scan+1, 0), index]
994 * for the first hole.
995 *
996 * Returns: the index of the hole if found, otherwise returns an index
997 * outside of the set specified (in which case 'index - return >= max_scan'
998 * will be true). In rare cases of wrap-around, ULONG_MAX will be returned.
999 *
1000 * radix_tree_next_hole may be called under rcu_read_lock. However, like
1001 * radix_tree_gang_lookup, this will not atomically search a snapshot of
1002 * the tree at a single point in time. For example, if a hole is created
1003 * at index 10, then subsequently a hole is created at index 5,
1004 * radix_tree_prev_hole covering both indexes may return 5 if called under
1005 * rcu_read_lock.
1006 */
1007unsigned long radix_tree_prev_hole(struct radix_tree_root *root,
1008 unsigned long index, unsigned long max_scan)
1009{
1010 unsigned long i;
1011
1012 for (i = 0; i < max_scan; i++) {
1013 if (!radix_tree_lookup(root, index))
1014 break;
1015 index--;
1016 if (index == ULONG_MAX)
1017 break;
1018 }
1019
1020 return index;
1021}
1022EXPORT_SYMBOL(radix_tree_prev_hole);
1023
1024/** 986/**
1025 * radix_tree_gang_lookup - perform multiple lookup on a radix tree 987 * radix_tree_gang_lookup - perform multiple lookup on a radix tree
1026 * @root: radix tree root 988 * @root: radix tree root
@@ -1189,7 +1151,7 @@ static unsigned long __locate(struct radix_tree_node *slot, void *item,
1189 unsigned int shift, height; 1151 unsigned int shift, height;
1190 unsigned long i; 1152 unsigned long i;
1191 1153
1192 height = slot->height; 1154 height = slot->path & RADIX_TREE_HEIGHT_MASK;
1193 shift = (height-1) * RADIX_TREE_MAP_SHIFT; 1155 shift = (height-1) * RADIX_TREE_MAP_SHIFT;
1194 1156
1195 for ( ; height > 1; height--) { 1157 for ( ; height > 1; height--) {
@@ -1252,7 +1214,8 @@ unsigned long radix_tree_locate_item(struct radix_tree_root *root, void *item)
1252 } 1214 }
1253 1215
1254 node = indirect_to_ptr(node); 1216 node = indirect_to_ptr(node);
1255 max_index = radix_tree_maxindex(node->height); 1217 max_index = radix_tree_maxindex(node->path &
1218 RADIX_TREE_HEIGHT_MASK);
1256 if (cur_index > max_index) { 1219 if (cur_index > max_index) {
1257 rcu_read_unlock(); 1220 rcu_read_unlock();
1258 break; 1221 break;
@@ -1337,48 +1300,89 @@ static inline void radix_tree_shrink(struct radix_tree_root *root)
1337} 1300}
1338 1301
1339/** 1302/**
1340 * radix_tree_delete - delete an item from a radix tree 1303 * __radix_tree_delete_node - try to free node after clearing a slot
1304 * @root: radix tree root
1305 * @node: node containing @index
1306 *
1307 * After clearing the slot at @index in @node from radix tree
1308 * rooted at @root, call this function to attempt freeing the
1309 * node and shrinking the tree.
1310 *
1311 * Returns %true if @node was freed, %false otherwise.
1312 */
1313bool __radix_tree_delete_node(struct radix_tree_root *root,
1314 struct radix_tree_node *node)
1315{
1316 bool deleted = false;
1317
1318 do {
1319 struct radix_tree_node *parent;
1320
1321 if (node->count) {
1322 if (node == indirect_to_ptr(root->rnode)) {
1323 radix_tree_shrink(root);
1324 if (root->height == 0)
1325 deleted = true;
1326 }
1327 return deleted;
1328 }
1329
1330 parent = node->parent;
1331 if (parent) {
1332 unsigned int offset;
1333
1334 offset = node->path >> RADIX_TREE_HEIGHT_SHIFT;
1335 parent->slots[offset] = NULL;
1336 parent->count--;
1337 } else {
1338 root_tag_clear_all(root);
1339 root->height = 0;
1340 root->rnode = NULL;
1341 }
1342
1343 radix_tree_node_free(node);
1344 deleted = true;
1345
1346 node = parent;
1347 } while (node);
1348
1349 return deleted;
1350}
1351
1352/**
1353 * radix_tree_delete_item - delete an item from a radix tree
1341 * @root: radix tree root 1354 * @root: radix tree root
1342 * @index: index key 1355 * @index: index key
1356 * @item: expected item
1343 * 1357 *
1344 * Remove the item at @index from the radix tree rooted at @root. 1358 * Remove @item at @index from the radix tree rooted at @root.
1345 * 1359 *
1346 * Returns the address of the deleted item, or NULL if it was not present. 1360 * Returns the address of the deleted item, or NULL if it was not present
1361 * or the entry at the given @index was not @item.
1347 */ 1362 */
1348void *radix_tree_delete(struct radix_tree_root *root, unsigned long index) 1363void *radix_tree_delete_item(struct radix_tree_root *root,
1364 unsigned long index, void *item)
1349{ 1365{
1350 struct radix_tree_node *node = NULL; 1366 struct radix_tree_node *node;
1351 struct radix_tree_node *slot = NULL; 1367 unsigned int offset;
1352 struct radix_tree_node *to_free; 1368 void **slot;
1353 unsigned int height, shift; 1369 void *entry;
1354 int tag; 1370 int tag;
1355 int uninitialized_var(offset);
1356 1371
1357 height = root->height; 1372 entry = __radix_tree_lookup(root, index, &node, &slot);
1358 if (index > radix_tree_maxindex(height)) 1373 if (!entry)
1359 goto out; 1374 return NULL;
1360 1375
1361 slot = root->rnode; 1376 if (item && entry != item)
1362 if (height == 0) { 1377 return NULL;
1378
1379 if (!node) {
1363 root_tag_clear_all(root); 1380 root_tag_clear_all(root);
1364 root->rnode = NULL; 1381 root->rnode = NULL;
1365 goto out; 1382 return entry;
1366 } 1383 }
1367 slot = indirect_to_ptr(slot);
1368 shift = height * RADIX_TREE_MAP_SHIFT;
1369 1384
1370 do { 1385 offset = index & RADIX_TREE_MAP_MASK;
1371 if (slot == NULL)
1372 goto out;
1373
1374 shift -= RADIX_TREE_MAP_SHIFT;
1375 offset = (index >> shift) & RADIX_TREE_MAP_MASK;
1376 node = slot;
1377 slot = slot->slots[offset];
1378 } while (shift);
1379
1380 if (slot == NULL)
1381 goto out;
1382 1386
1383 /* 1387 /*
1384 * Clear all tags associated with the item to be deleted. 1388 * Clear all tags associated with the item to be deleted.
@@ -1389,40 +1393,27 @@ void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
1389 radix_tree_tag_clear(root, index, tag); 1393 radix_tree_tag_clear(root, index, tag);
1390 } 1394 }
1391 1395
1392 to_free = NULL; 1396 node->slots[offset] = NULL;
1393 /* Now free the nodes we do not need anymore */ 1397 node->count--;
1394 while (node) {
1395 node->slots[offset] = NULL;
1396 node->count--;
1397 /*
1398 * Queue the node for deferred freeing after the
1399 * last reference to it disappears (set NULL, above).
1400 */
1401 if (to_free)
1402 radix_tree_node_free(to_free);
1403
1404 if (node->count) {
1405 if (node == indirect_to_ptr(root->rnode))
1406 radix_tree_shrink(root);
1407 goto out;
1408 }
1409
1410 /* Node with zero slots in use so free it */
1411 to_free = node;
1412 1398
1413 index >>= RADIX_TREE_MAP_SHIFT; 1399 __radix_tree_delete_node(root, node);
1414 offset = index & RADIX_TREE_MAP_MASK;
1415 node = node->parent;
1416 }
1417 1400
1418 root_tag_clear_all(root); 1401 return entry;
1419 root->height = 0; 1402}
1420 root->rnode = NULL; 1403EXPORT_SYMBOL(radix_tree_delete_item);
1421 if (to_free)
1422 radix_tree_node_free(to_free);
1423 1404
1424out: 1405/**
1425 return slot; 1406 * radix_tree_delete - delete an item from a radix tree
1407 * @root: radix tree root
1408 * @index: index key
1409 *
1410 * Remove the item at @index from the radix tree rooted at @root.
1411 *
1412 * Returns the address of the deleted item, or NULL if it was not present.
1413 */
1414void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
1415{
1416 return radix_tree_delete_item(root, index, NULL);
1426} 1417}
1427EXPORT_SYMBOL(radix_tree_delete); 1418EXPORT_SYMBOL(radix_tree_delete);
1428 1419
@@ -1438,9 +1429,12 @@ int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag)
1438EXPORT_SYMBOL(radix_tree_tagged); 1429EXPORT_SYMBOL(radix_tree_tagged);
1439 1430
1440static void 1431static void
1441radix_tree_node_ctor(void *node) 1432radix_tree_node_ctor(void *arg)
1442{ 1433{
1443 memset(node, 0, sizeof(struct radix_tree_node)); 1434 struct radix_tree_node *node = arg;
1435
1436 memset(node, 0, sizeof(*node));
1437 INIT_LIST_HEAD(&node->private_list);
1444} 1438}
1445 1439
1446static __init unsigned long __maxindex(unsigned int height) 1440static __init unsigned long __maxindex(unsigned int height)
diff --git a/lib/random32.c b/lib/random32.c
index 614896778700..fa5da61ce7ad 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -1,37 +1,35 @@
1/* 1/*
2 This is a maximally equidistributed combined Tausworthe generator 2 * This is a maximally equidistributed combined Tausworthe generator
3 based on code from GNU Scientific Library 1.5 (30 Jun 2004) 3 * based on code from GNU Scientific Library 1.5 (30 Jun 2004)
4 4 *
5 lfsr113 version: 5 * lfsr113 version:
6 6 *
7 x_n = (s1_n ^ s2_n ^ s3_n ^ s4_n) 7 * x_n = (s1_n ^ s2_n ^ s3_n ^ s4_n)
8 8 *
9 s1_{n+1} = (((s1_n & 4294967294) << 18) ^ (((s1_n << 6) ^ s1_n) >> 13)) 9 * s1_{n+1} = (((s1_n & 4294967294) << 18) ^ (((s1_n << 6) ^ s1_n) >> 13))
10 s2_{n+1} = (((s2_n & 4294967288) << 2) ^ (((s2_n << 2) ^ s2_n) >> 27)) 10 * s2_{n+1} = (((s2_n & 4294967288) << 2) ^ (((s2_n << 2) ^ s2_n) >> 27))
11 s3_{n+1} = (((s3_n & 4294967280) << 7) ^ (((s3_n << 13) ^ s3_n) >> 21)) 11 * s3_{n+1} = (((s3_n & 4294967280) << 7) ^ (((s3_n << 13) ^ s3_n) >> 21))
12 s4_{n+1} = (((s4_n & 4294967168) << 13) ^ (((s4_n << 3) ^ s4_n) >> 12)) 12 * s4_{n+1} = (((s4_n & 4294967168) << 13) ^ (((s4_n << 3) ^ s4_n) >> 12))
13 13 *
14 The period of this generator is about 2^113 (see erratum paper). 14 * The period of this generator is about 2^113 (see erratum paper).
15 15 *
16 From: P. L'Ecuyer, "Maximally Equidistributed Combined Tausworthe 16 * From: P. L'Ecuyer, "Maximally Equidistributed Combined Tausworthe
17 Generators", Mathematics of Computation, 65, 213 (1996), 203--213: 17 * Generators", Mathematics of Computation, 65, 213 (1996), 203--213:
18 http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme.ps 18 * http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme.ps
19 ftp://ftp.iro.umontreal.ca/pub/simulation/lecuyer/papers/tausme.ps 19 * ftp://ftp.iro.umontreal.ca/pub/simulation/lecuyer/papers/tausme.ps
20 20 *
21 There is an erratum in the paper "Tables of Maximally 21 * There is an erratum in the paper "Tables of Maximally Equidistributed
22 Equidistributed Combined LFSR Generators", Mathematics of 22 * Combined LFSR Generators", Mathematics of Computation, 68, 225 (1999),
23 Computation, 68, 225 (1999), 261--269: 23 * 261--269: http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme2.ps
24 http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme2.ps 24 *
25 25 * ... the k_j most significant bits of z_j must be non-zero,
26 ... the k_j most significant bits of z_j must be non- 26 * for each j. (Note: this restriction also applies to the
27 zero, for each j. (Note: this restriction also applies to the 27 * computer code given in [4], but was mistakenly not mentioned
28 computer code given in [4], but was mistakenly not mentioned in 28 * in that paper.)
29 that paper.) 29 *
30 30 * This affects the seeding procedure by imposing the requirement
31 This affects the seeding procedure by imposing the requirement 31 * s1 > 1, s2 > 7, s3 > 15, s4 > 127.
32 s1 > 1, s2 > 7, s3 > 15, s4 > 127. 32 */
33
34*/
35 33
36#include <linux/types.h> 34#include <linux/types.h>
37#include <linux/percpu.h> 35#include <linux/percpu.h>
@@ -75,15 +73,17 @@ EXPORT_SYMBOL(prandom_u32_state);
75 */ 73 */
76u32 prandom_u32(void) 74u32 prandom_u32(void)
77{ 75{
78 unsigned long r;
79 struct rnd_state *state = &get_cpu_var(net_rand_state); 76 struct rnd_state *state = &get_cpu_var(net_rand_state);
80 r = prandom_u32_state(state); 77 u32 res;
78
79 res = prandom_u32_state(state);
81 put_cpu_var(state); 80 put_cpu_var(state);
82 return r; 81
82 return res;
83} 83}
84EXPORT_SYMBOL(prandom_u32); 84EXPORT_SYMBOL(prandom_u32);
85 85
86/* 86/**
87 * prandom_bytes_state - get the requested number of pseudo-random bytes 87 * prandom_bytes_state - get the requested number of pseudo-random bytes
88 * 88 *
89 * @state: pointer to state structure holding seeded state. 89 * @state: pointer to state structure holding seeded state.
@@ -204,6 +204,7 @@ static int __init prandom_init(void)
204 prandom_seed_very_weak(state, (i + jiffies) ^ random_get_entropy()); 204 prandom_seed_very_weak(state, (i + jiffies) ^ random_get_entropy());
205 prandom_warmup(state); 205 prandom_warmup(state);
206 } 206 }
207
207 return 0; 208 return 0;
208} 209}
209core_initcall(prandom_init); 210core_initcall(prandom_init);
@@ -259,6 +260,7 @@ static void __prandom_reseed(bool late)
259 260
260 if (latch && !late) 261 if (latch && !late)
261 goto out; 262 goto out;
263
262 latch = true; 264 latch = true;
263 265
264 for_each_possible_cpu(i) { 266 for_each_possible_cpu(i) {
diff --git a/lib/smp_processor_id.c b/lib/smp_processor_id.c
index 04abe53f12a1..1afec32de6f2 100644
--- a/lib/smp_processor_id.c
+++ b/lib/smp_processor_id.c
@@ -7,7 +7,8 @@
7#include <linux/kallsyms.h> 7#include <linux/kallsyms.h>
8#include <linux/sched.h> 8#include <linux/sched.h>
9 9
10notrace unsigned int debug_smp_processor_id(void) 10notrace static unsigned int check_preemption_disabled(const char *what1,
11 const char *what2)
11{ 12{
12 int this_cpu = raw_smp_processor_id(); 13 int this_cpu = raw_smp_processor_id();
13 14
@@ -38,9 +39,9 @@ notrace unsigned int debug_smp_processor_id(void)
38 if (!printk_ratelimit()) 39 if (!printk_ratelimit())
39 goto out_enable; 40 goto out_enable;
40 41
41 printk(KERN_ERR "BUG: using smp_processor_id() in preemptible [%08x] " 42 printk(KERN_ERR "BUG: using %s%s() in preemptible [%08x] code: %s/%d\n",
42 "code: %s/%d\n", 43 what1, what2, preempt_count() - 1, current->comm, current->pid);
43 preempt_count() - 1, current->comm, current->pid); 44
44 print_symbol("caller is %s\n", (long)__builtin_return_address(0)); 45 print_symbol("caller is %s\n", (long)__builtin_return_address(0));
45 dump_stack(); 46 dump_stack();
46 47
@@ -50,5 +51,14 @@ out:
50 return this_cpu; 51 return this_cpu;
51} 52}
52 53
54notrace unsigned int debug_smp_processor_id(void)
55{
56 return check_preemption_disabled("smp_processor_id", "");
57}
53EXPORT_SYMBOL(debug_smp_processor_id); 58EXPORT_SYMBOL(debug_smp_processor_id);
54 59
60notrace void __this_cpu_preempt_check(const char *op)
61{
62 check_preemption_disabled("__this_cpu_", op);
63}
64EXPORT_SYMBOL(__this_cpu_preempt_check);
diff --git a/lib/string.c b/lib/string.c
index e5878de4f101..992bf30af759 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -107,7 +107,7 @@ EXPORT_SYMBOL(strcpy);
107 107
108#ifndef __HAVE_ARCH_STRNCPY 108#ifndef __HAVE_ARCH_STRNCPY
109/** 109/**
110 * strncpy - Copy a length-limited, %NUL-terminated string 110 * strncpy - Copy a length-limited, C-string
111 * @dest: Where to copy the string to 111 * @dest: Where to copy the string to
112 * @src: Where to copy the string from 112 * @src: Where to copy the string from
113 * @count: The maximum number of bytes to copy 113 * @count: The maximum number of bytes to copy
@@ -136,7 +136,7 @@ EXPORT_SYMBOL(strncpy);
136 136
137#ifndef __HAVE_ARCH_STRLCPY 137#ifndef __HAVE_ARCH_STRLCPY
138/** 138/**
139 * strlcpy - Copy a %NUL terminated string into a sized buffer 139 * strlcpy - Copy a C-string into a sized buffer
140 * @dest: Where to copy the string to 140 * @dest: Where to copy the string to
141 * @src: Where to copy the string from 141 * @src: Where to copy the string from
142 * @size: size of destination buffer 142 * @size: size of destination buffer
@@ -182,7 +182,7 @@ EXPORT_SYMBOL(strcat);
182 182
183#ifndef __HAVE_ARCH_STRNCAT 183#ifndef __HAVE_ARCH_STRNCAT
184/** 184/**
185 * strncat - Append a length-limited, %NUL-terminated string to another 185 * strncat - Append a length-limited, C-string to another
186 * @dest: The string to be appended to 186 * @dest: The string to be appended to
187 * @src: The string to append to it 187 * @src: The string to append to it
188 * @count: The maximum numbers of bytes to copy 188 * @count: The maximum numbers of bytes to copy
@@ -211,7 +211,7 @@ EXPORT_SYMBOL(strncat);
211 211
212#ifndef __HAVE_ARCH_STRLCAT 212#ifndef __HAVE_ARCH_STRLCAT
213/** 213/**
214 * strlcat - Append a length-limited, %NUL-terminated string to another 214 * strlcat - Append a length-limited, C-string to another
215 * @dest: The string to be appended to 215 * @dest: The string to be appended to
216 * @src: The string to append to it 216 * @src: The string to append to it
217 * @count: The size of the destination buffer. 217 * @count: The size of the destination buffer.
@@ -301,6 +301,24 @@ char *strchr(const char *s, int c)
301EXPORT_SYMBOL(strchr); 301EXPORT_SYMBOL(strchr);
302#endif 302#endif
303 303
304#ifndef __HAVE_ARCH_STRCHRNUL
305/**
306 * strchrnul - Find and return a character in a string, or end of string
307 * @s: The string to be searched
308 * @c: The character to search for
309 *
310 * Returns pointer to first occurrence of 'c' in s. If c is not found, then
311 * return a pointer to the null byte at the end of s.
312 */
313char *strchrnul(const char *s, int c)
314{
315 while (*s && *s != (char)c)
316 s++;
317 return (char *)s;
318}
319EXPORT_SYMBOL(strchrnul);
320#endif
321
304#ifndef __HAVE_ARCH_STRRCHR 322#ifndef __HAVE_ARCH_STRRCHR
305/** 323/**
306 * strrchr - Find the last occurrence of a character in a string 324 * strrchr - Find the last occurrence of a character in a string
@@ -648,7 +666,7 @@ EXPORT_SYMBOL(memmove);
648 * @count: The size of the area. 666 * @count: The size of the area.
649 */ 667 */
650#undef memcmp 668#undef memcmp
651int memcmp(const void *cs, const void *ct, size_t count) 669__visible int memcmp(const void *cs, const void *ct, size_t count)
652{ 670{
653 const unsigned char *su1, *su2; 671 const unsigned char *su1, *su2;
654 int res = 0; 672 int res = 0;
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index b604b831f4d1..649d097853a1 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -374,7 +374,7 @@ void __init swiotlb_free(void)
374 io_tlb_nslabs = 0; 374 io_tlb_nslabs = 0;
375} 375}
376 376
377static int is_swiotlb_buffer(phys_addr_t paddr) 377int is_swiotlb_buffer(phys_addr_t paddr)
378{ 378{
379 return paddr >= io_tlb_start && paddr < io_tlb_end; 379 return paddr >= io_tlb_start && paddr < io_tlb_end;
380} 380}
diff --git a/lib/syscall.c b/lib/syscall.c
index 58710eefeac8..e30e03932480 100644
--- a/lib/syscall.c
+++ b/lib/syscall.c
@@ -72,4 +72,3 @@ int task_current_syscall(struct task_struct *target, long *callno,
72 72
73 return 0; 73 return 0;
74} 74}
75EXPORT_SYMBOL_GPL(task_current_syscall);
diff --git a/lib/textsearch.c b/lib/textsearch.c
index e0cc0146ae62..0c7e9ab2d88f 100644
--- a/lib/textsearch.c
+++ b/lib/textsearch.c
@@ -159,6 +159,7 @@ errout:
159 spin_unlock(&ts_mod_lock); 159 spin_unlock(&ts_mod_lock);
160 return err; 160 return err;
161} 161}
162EXPORT_SYMBOL(textsearch_register);
162 163
163/** 164/**
164 * textsearch_unregister - unregister a textsearch module 165 * textsearch_unregister - unregister a textsearch module
@@ -190,6 +191,7 @@ out:
190 spin_unlock(&ts_mod_lock); 191 spin_unlock(&ts_mod_lock);
191 return err; 192 return err;
192} 193}
194EXPORT_SYMBOL(textsearch_unregister);
193 195
194struct ts_linear_state 196struct ts_linear_state
195{ 197{
@@ -236,6 +238,7 @@ unsigned int textsearch_find_continuous(struct ts_config *conf,
236 238
237 return textsearch_find(conf, state); 239 return textsearch_find(conf, state);
238} 240}
241EXPORT_SYMBOL(textsearch_find_continuous);
239 242
240/** 243/**
241 * textsearch_prepare - Prepare a search 244 * textsearch_prepare - Prepare a search
@@ -298,6 +301,7 @@ errout:
298 301
299 return ERR_PTR(err); 302 return ERR_PTR(err);
300} 303}
304EXPORT_SYMBOL(textsearch_prepare);
301 305
302/** 306/**
303 * textsearch_destroy - destroy a search configuration 307 * textsearch_destroy - destroy a search configuration
@@ -316,9 +320,4 @@ void textsearch_destroy(struct ts_config *conf)
316 320
317 kfree(conf); 321 kfree(conf);
318} 322}
319
320EXPORT_SYMBOL(textsearch_register);
321EXPORT_SYMBOL(textsearch_unregister);
322EXPORT_SYMBOL(textsearch_prepare);
323EXPORT_SYMBOL(textsearch_find_continuous);
324EXPORT_SYMBOL(textsearch_destroy); 323EXPORT_SYMBOL(textsearch_destroy);
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 185b6d300ebc..6fe2c84eb055 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -364,7 +364,6 @@ enum format_type {
364 FORMAT_TYPE_SHORT, 364 FORMAT_TYPE_SHORT,
365 FORMAT_TYPE_UINT, 365 FORMAT_TYPE_UINT,
366 FORMAT_TYPE_INT, 366 FORMAT_TYPE_INT,
367 FORMAT_TYPE_NRCHARS,
368 FORMAT_TYPE_SIZE_T, 367 FORMAT_TYPE_SIZE_T,
369 FORMAT_TYPE_PTRDIFF 368 FORMAT_TYPE_PTRDIFF
370}; 369};
@@ -719,10 +718,15 @@ char *resource_string(char *buf, char *end, struct resource *res,
719 specp = &mem_spec; 718 specp = &mem_spec;
720 decode = 0; 719 decode = 0;
721 } 720 }
722 p = number(p, pend, res->start, *specp); 721 if (decode && res->flags & IORESOURCE_UNSET) {
723 if (res->start != res->end) { 722 p = string(p, pend, "size ", str_spec);
724 *p++ = '-'; 723 p = number(p, pend, resource_size(res), *specp);
725 p = number(p, pend, res->end, *specp); 724 } else {
725 p = number(p, pend, res->start, *specp);
726 if (res->start != res->end) {
727 *p++ = '-';
728 p = number(p, pend, res->end, *specp);
729 }
726 } 730 }
727 if (decode) { 731 if (decode) {
728 if (res->flags & IORESOURCE_MEM_64) 732 if (res->flags & IORESOURCE_MEM_64)
@@ -1533,10 +1537,6 @@ qualifier:
1533 return fmt - start; 1537 return fmt - start;
1534 /* skip alnum */ 1538 /* skip alnum */
1535 1539
1536 case 'n':
1537 spec->type = FORMAT_TYPE_NRCHARS;
1538 return ++fmt - start;
1539
1540 case '%': 1540 case '%':
1541 spec->type = FORMAT_TYPE_PERCENT_CHAR; 1541 spec->type = FORMAT_TYPE_PERCENT_CHAR;
1542 return ++fmt - start; 1542 return ++fmt - start;
@@ -1559,6 +1559,15 @@ qualifier:
1559 case 'u': 1559 case 'u':
1560 break; 1560 break;
1561 1561
1562 case 'n':
1563 /*
1564 * Since %n poses a greater security risk than utility, treat
1565 * it as an invalid format specifier. Warn about its use so
1566 * that new instances don't get added.
1567 */
1568 WARN_ONCE(1, "Please remove ignored %%n in '%s'\n", fmt);
1569 /* Fall-through */
1570
1562 default: 1571 default:
1563 spec->type = FORMAT_TYPE_INVALID; 1572 spec->type = FORMAT_TYPE_INVALID;
1564 return fmt - start; 1573 return fmt - start;
@@ -1732,20 +1741,6 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
1732 ++str; 1741 ++str;
1733 break; 1742 break;
1734 1743
1735 case FORMAT_TYPE_NRCHARS: {
1736 /*
1737 * Since %n poses a greater security risk than
1738 * utility, ignore %n and skip its argument.
1739 */
1740 void *skip_arg;
1741
1742 WARN_ONCE(1, "Please remove ignored %%n in '%s'\n",
1743 old_fmt);
1744
1745 skip_arg = va_arg(args, void *);
1746 break;
1747 }
1748
1749 default: 1744 default:
1750 switch (spec.type) { 1745 switch (spec.type) {
1751 case FORMAT_TYPE_LONG_LONG: 1746 case FORMAT_TYPE_LONG_LONG:
@@ -2020,19 +2015,6 @@ do { \
2020 fmt++; 2015 fmt++;
2021 break; 2016 break;
2022 2017
2023 case FORMAT_TYPE_NRCHARS: {
2024 /* skip %n 's argument */
2025 u8 qualifier = spec.qualifier;
2026 void *skip_arg;
2027 if (qualifier == 'l')
2028 skip_arg = va_arg(args, long *);
2029 else if (_tolower(qualifier) == 'z')
2030 skip_arg = va_arg(args, size_t *);
2031 else
2032 skip_arg = va_arg(args, int *);
2033 break;
2034 }
2035
2036 default: 2018 default:
2037 switch (spec.type) { 2019 switch (spec.type) {
2038 2020
@@ -2191,10 +2173,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
2191 ++str; 2173 ++str;
2192 break; 2174 break;
2193 2175
2194 case FORMAT_TYPE_NRCHARS:
2195 /* skip */
2196 break;
2197
2198 default: { 2176 default: {
2199 unsigned long long num; 2177 unsigned long long num;
2200 2178
@@ -2369,7 +2347,7 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
2369 break; 2347 break;
2370 2348
2371 base = 10; 2349 base = 10;
2372 is_sign = 0; 2350 is_sign = false;
2373 2351
2374 switch (*fmt++) { 2352 switch (*fmt++) {
2375 case 'c': 2353 case 'c':
@@ -2408,7 +2386,7 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
2408 case 'i': 2386 case 'i':
2409 base = 0; 2387 base = 0;
2410 case 'd': 2388 case 'd':
2411 is_sign = 1; 2389 is_sign = true;
2412 case 'u': 2390 case 'u':
2413 break; 2391 break;
2414 case '%': 2392 case '%':
diff --git a/lib/xz/Kconfig b/lib/xz/Kconfig
index 08837db52d94..12d2d777f36b 100644
--- a/lib/xz/Kconfig
+++ b/lib/xz/Kconfig
@@ -9,33 +9,33 @@ config XZ_DEC
9if XZ_DEC 9if XZ_DEC
10 10
11config XZ_DEC_X86 11config XZ_DEC_X86
12 bool "x86 BCJ filter decoder" 12 bool "x86 BCJ filter decoder" if EXPERT
13 default y if X86 13 default y
14 select XZ_DEC_BCJ 14 select XZ_DEC_BCJ
15 15
16config XZ_DEC_POWERPC 16config XZ_DEC_POWERPC
17 bool "PowerPC BCJ filter decoder" 17 bool "PowerPC BCJ filter decoder" if EXPERT
18 default y if PPC 18 default y
19 select XZ_DEC_BCJ 19 select XZ_DEC_BCJ
20 20
21config XZ_DEC_IA64 21config XZ_DEC_IA64
22 bool "IA-64 BCJ filter decoder" 22 bool "IA-64 BCJ filter decoder" if EXPERT
23 default y if IA64 23 default y
24 select XZ_DEC_BCJ 24 select XZ_DEC_BCJ
25 25
26config XZ_DEC_ARM 26config XZ_DEC_ARM
27 bool "ARM BCJ filter decoder" 27 bool "ARM BCJ filter decoder" if EXPERT
28 default y if ARM 28 default y
29 select XZ_DEC_BCJ 29 select XZ_DEC_BCJ
30 30
31config XZ_DEC_ARMTHUMB 31config XZ_DEC_ARMTHUMB
32 bool "ARM-Thumb BCJ filter decoder" 32 bool "ARM-Thumb BCJ filter decoder" if EXPERT
33 default y if (ARM && ARM_THUMB) 33 default y
34 select XZ_DEC_BCJ 34 select XZ_DEC_BCJ
35 35
36config XZ_DEC_SPARC 36config XZ_DEC_SPARC
37 bool "SPARC BCJ filter decoder" 37 bool "SPARC BCJ filter decoder" if EXPERT
38 default y if SPARC 38 default y
39 select XZ_DEC_BCJ 39 select XZ_DEC_BCJ
40 40
41endif 41endif
diff --git a/lib/xz/xz_dec_lzma2.c b/lib/xz/xz_dec_lzma2.c
index a6cdc969ea42..08c3c8049998 100644
--- a/lib/xz/xz_dec_lzma2.c
+++ b/lib/xz/xz_dec_lzma2.c
@@ -1043,6 +1043,8 @@ XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s,
1043 1043
1044 s->lzma2.sequence = SEQ_LZMA_PREPARE; 1044 s->lzma2.sequence = SEQ_LZMA_PREPARE;
1045 1045
1046 /* Fall through */
1047
1046 case SEQ_LZMA_PREPARE: 1048 case SEQ_LZMA_PREPARE:
1047 if (s->lzma2.compressed < RC_INIT_BYTES) 1049 if (s->lzma2.compressed < RC_INIT_BYTES)
1048 return XZ_DATA_ERROR; 1050 return XZ_DATA_ERROR;
@@ -1053,6 +1055,8 @@ XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s,
1053 s->lzma2.compressed -= RC_INIT_BYTES; 1055 s->lzma2.compressed -= RC_INIT_BYTES;
1054 s->lzma2.sequence = SEQ_LZMA_RUN; 1056 s->lzma2.sequence = SEQ_LZMA_RUN;
1055 1057
1058 /* Fall through */
1059
1056 case SEQ_LZMA_RUN: 1060 case SEQ_LZMA_RUN:
1057 /* 1061 /*
1058 * Set dictionary limit to indicate how much we want 1062 * Set dictionary limit to indicate how much we want