diff options
Diffstat (limited to 'lib')
38 files changed, 912 insertions, 217 deletions
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 8e5ec5e1ab91..e722e9d62221 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
@@ -103,7 +103,8 @@ config HEADERS_CHECK | |||
103 | 103 | ||
104 | config DEBUG_SECTION_MISMATCH | 104 | config DEBUG_SECTION_MISMATCH |
105 | bool "Enable full Section mismatch analysis" | 105 | bool "Enable full Section mismatch analysis" |
106 | depends on UNDEFINED | 106 | depends on UNDEFINED || (BLACKFIN) |
107 | default y | ||
107 | # This option is on purpose disabled for now. | 108 | # This option is on purpose disabled for now. |
108 | # It will be enabled when we are down to a reasonable number | 109 | # It will be enabled when we are down to a reasonable number |
109 | # of section mismatch warnings (< 10 for an allyesconfig build) | 110 | # of section mismatch warnings (< 10 for an allyesconfig build) |
@@ -355,7 +356,7 @@ config SLUB_STATS | |||
355 | config DEBUG_KMEMLEAK | 356 | config DEBUG_KMEMLEAK |
356 | bool "Kernel memory leak detector" | 357 | bool "Kernel memory leak detector" |
357 | depends on DEBUG_KERNEL && EXPERIMENTAL && !MEMORY_HOTPLUG && \ | 358 | depends on DEBUG_KERNEL && EXPERIMENTAL && !MEMORY_HOTPLUG && \ |
358 | (X86 || ARM || PPC || S390 || SUPERH) | 359 | (X86 || ARM || PPC || S390 || SPARC64 || SUPERH || MICROBLAZE) |
359 | 360 | ||
360 | select DEBUG_FS if SYSFS | 361 | select DEBUG_FS if SYSFS |
361 | select STACKTRACE if STACKTRACE_SUPPORT | 362 | select STACKTRACE if STACKTRACE_SUPPORT |
@@ -511,6 +512,18 @@ config PROVE_RCU | |||
511 | 512 | ||
512 | Say N if you are unsure. | 513 | Say N if you are unsure. |
513 | 514 | ||
515 | config PROVE_RCU_REPEATEDLY | ||
516 | bool "RCU debugging: don't disable PROVE_RCU on first splat" | ||
517 | depends on PROVE_RCU | ||
518 | default n | ||
519 | help | ||
520 | By itself, PROVE_RCU will disable checking upon issuing the | ||
521 | first warning (or "splat"). This feature prevents such | ||
522 | disabling, allowing multiple RCU-lockdep warnings to be printed | ||
523 | on a single reboot. | ||
524 | |||
525 | Say N if you are unsure. | ||
526 | |||
514 | config LOCKDEP | 527 | config LOCKDEP |
515 | bool | 528 | bool |
516 | depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT | 529 | depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT |
@@ -792,7 +805,7 @@ config RCU_CPU_STALL_DETECTOR | |||
792 | config RCU_CPU_STALL_VERBOSE | 805 | config RCU_CPU_STALL_VERBOSE |
793 | bool "Print additional per-task information for RCU_CPU_STALL_DETECTOR" | 806 | bool "Print additional per-task information for RCU_CPU_STALL_DETECTOR" |
794 | depends on RCU_CPU_STALL_DETECTOR && TREE_PREEMPT_RCU | 807 | depends on RCU_CPU_STALL_DETECTOR && TREE_PREEMPT_RCU |
795 | default n | 808 | default y |
796 | help | 809 | help |
797 | This option causes RCU to printk detailed per-task information | 810 | This option causes RCU to printk detailed per-task information |
798 | for any tasks that are stalling the current RCU grace period. | 811 | for any tasks that are stalling the current RCU grace period. |
@@ -885,6 +898,18 @@ config LKDTM | |||
885 | Documentation on how to use the module can be found in | 898 | Documentation on how to use the module can be found in |
886 | Documentation/fault-injection/provoke-crashes.txt | 899 | Documentation/fault-injection/provoke-crashes.txt |
887 | 900 | ||
901 | config CPU_NOTIFIER_ERROR_INJECT | ||
902 | tristate "CPU notifier error injection module" | ||
903 | depends on HOTPLUG_CPU && DEBUG_KERNEL | ||
904 | help | ||
905 | This option provides a kernel module that can be used to test | ||
906 | the error handling of the cpu notifiers | ||
907 | |||
908 | To compile this code as a module, choose M here: the module will | ||
909 | be called cpu-notifier-error-inject. | ||
910 | |||
911 | If unsure, say N. | ||
912 | |||
888 | config FAULT_INJECTION | 913 | config FAULT_INJECTION |
889 | bool "Fault-injection framework" | 914 | bool "Fault-injection framework" |
890 | depends on DEBUG_KERNEL | 915 | depends on DEBUG_KERNEL |
@@ -1026,10 +1051,10 @@ config DYNAMIC_DEBUG | |||
1026 | 1051 | ||
1027 | Usage: | 1052 | Usage: |
1028 | 1053 | ||
1029 | Dynamic debugging is controlled via the 'dynamic_debug/ddebug' file, | 1054 | Dynamic debugging is controlled via the 'dynamic_debug/control' file, |
1030 | which is contained in the 'debugfs' filesystem. Thus, the debugfs | 1055 | which is contained in the 'debugfs' filesystem. Thus, the debugfs |
1031 | filesystem must first be mounted before making use of this feature. | 1056 | filesystem must first be mounted before making use of this feature. |
1032 | We refer the control file as: <debugfs>/dynamic_debug/ddebug. This | 1057 | We refer the control file as: <debugfs>/dynamic_debug/control. This |
1033 | file contains a list of the debug statements that can be enabled. The | 1058 | file contains a list of the debug statements that can be enabled. The |
1034 | format for each line of the file is: | 1059 | format for each line of the file is: |
1035 | 1060 | ||
@@ -1044,7 +1069,7 @@ config DYNAMIC_DEBUG | |||
1044 | 1069 | ||
1045 | From a live system: | 1070 | From a live system: |
1046 | 1071 | ||
1047 | nullarbor:~ # cat <debugfs>/dynamic_debug/ddebug | 1072 | nullarbor:~ # cat <debugfs>/dynamic_debug/control |
1048 | # filename:lineno [module]function flags format | 1073 | # filename:lineno [module]function flags format |
1049 | fs/aio.c:222 [aio]__put_ioctx - "__put_ioctx:\040freeing\040%p\012" | 1074 | fs/aio.c:222 [aio]__put_ioctx - "__put_ioctx:\040freeing\040%p\012" |
1050 | fs/aio.c:248 [aio]ioctx_alloc - "ENOMEM:\040nr_events\040too\040high\012" | 1075 | fs/aio.c:248 [aio]ioctx_alloc - "ENOMEM:\040nr_events\040too\040high\012" |
@@ -1054,23 +1079,23 @@ config DYNAMIC_DEBUG | |||
1054 | 1079 | ||
1055 | // enable the message at line 1603 of file svcsock.c | 1080 | // enable the message at line 1603 of file svcsock.c |
1056 | nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' > | 1081 | nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' > |
1057 | <debugfs>/dynamic_debug/ddebug | 1082 | <debugfs>/dynamic_debug/control |
1058 | 1083 | ||
1059 | // enable all the messages in file svcsock.c | 1084 | // enable all the messages in file svcsock.c |
1060 | nullarbor:~ # echo -n 'file svcsock.c +p' > | 1085 | nullarbor:~ # echo -n 'file svcsock.c +p' > |
1061 | <debugfs>/dynamic_debug/ddebug | 1086 | <debugfs>/dynamic_debug/control |
1062 | 1087 | ||
1063 | // enable all the messages in the NFS server module | 1088 | // enable all the messages in the NFS server module |
1064 | nullarbor:~ # echo -n 'module nfsd +p' > | 1089 | nullarbor:~ # echo -n 'module nfsd +p' > |
1065 | <debugfs>/dynamic_debug/ddebug | 1090 | <debugfs>/dynamic_debug/control |
1066 | 1091 | ||
1067 | // enable all 12 messages in the function svc_process() | 1092 | // enable all 12 messages in the function svc_process() |
1068 | nullarbor:~ # echo -n 'func svc_process +p' > | 1093 | nullarbor:~ # echo -n 'func svc_process +p' > |
1069 | <debugfs>/dynamic_debug/ddebug | 1094 | <debugfs>/dynamic_debug/control |
1070 | 1095 | ||
1071 | // disable all 12 messages in the function svc_process() | 1096 | // disable all 12 messages in the function svc_process() |
1072 | nullarbor:~ # echo -n 'func svc_process -p' > | 1097 | nullarbor:~ # echo -n 'func svc_process -p' > |
1073 | <debugfs>/dynamic_debug/ddebug | 1098 | <debugfs>/dynamic_debug/control |
1074 | 1099 | ||
1075 | See Documentation/dynamic-debug-howto.txt for additional information. | 1100 | See Documentation/dynamic-debug-howto.txt for additional information. |
1076 | 1101 | ||
@@ -1085,6 +1110,13 @@ config DMA_API_DEBUG | |||
1085 | This option causes a performance degredation. Use only if you want | 1110 | This option causes a performance degredation. Use only if you want |
1086 | to debug device drivers. If unsure, say N. | 1111 | to debug device drivers. If unsure, say N. |
1087 | 1112 | ||
1113 | config ATOMIC64_SELFTEST | ||
1114 | bool "Perform an atomic64_t self-test at boot" | ||
1115 | help | ||
1116 | Enable this option to test the atomic64_t functions at boot. | ||
1117 | |||
1118 | If unsure, say N. | ||
1119 | |||
1088 | source "samples/Kconfig" | 1120 | source "samples/Kconfig" |
1089 | 1121 | ||
1090 | source "lib/Kconfig.kgdb" | 1122 | source "lib/Kconfig.kgdb" |
diff --git a/lib/Kconfig.kgdb b/lib/Kconfig.kgdb index 9b5d1d7f2ef7..43cb93fa2651 100644 --- a/lib/Kconfig.kgdb +++ b/lib/Kconfig.kgdb | |||
@@ -3,7 +3,7 @@ config HAVE_ARCH_KGDB | |||
3 | bool | 3 | bool |
4 | 4 | ||
5 | menuconfig KGDB | 5 | menuconfig KGDB |
6 | bool "KGDB: kernel debugging with remote gdb" | 6 | bool "KGDB: kernel debugger" |
7 | depends on HAVE_ARCH_KGDB | 7 | depends on HAVE_ARCH_KGDB |
8 | depends on DEBUG_KERNEL && EXPERIMENTAL | 8 | depends on DEBUG_KERNEL && EXPERIMENTAL |
9 | help | 9 | help |
@@ -57,4 +57,26 @@ config KGDB_TESTS_BOOT_STRING | |||
57 | information about other strings you could use beyond the | 57 | information about other strings you could use beyond the |
58 | default of V1F100. | 58 | default of V1F100. |
59 | 59 | ||
60 | config KGDB_LOW_LEVEL_TRAP | ||
61 | bool "KGDB: Allow debugging with traps in notifiers" | ||
62 | depends on X86 || MIPS | ||
63 | default n | ||
64 | help | ||
65 | This will add an extra call back to kgdb for the breakpoint | ||
66 | exception handler on which will will allow kgdb to step | ||
67 | through a notify handler. | ||
68 | |||
69 | config KGDB_KDB | ||
70 | bool "KGDB_KDB: include kdb frontend for kgdb" | ||
71 | default n | ||
72 | help | ||
73 | KDB frontend for kernel | ||
74 | |||
75 | config KDB_KEYBOARD | ||
76 | bool "KGDB_KDB: keyboard as input device" | ||
77 | depends on VT && KGDB_KDB | ||
78 | default n | ||
79 | help | ||
80 | KDB can use a PS/2 type keyboard for an input device | ||
81 | |||
60 | endif # KGDB | 82 | endif # KGDB |
diff --git a/lib/Makefile b/lib/Makefile index 2e152aed7198..3f1062cbbff4 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -21,7 +21,7 @@ lib-y += kobject.o kref.o klist.o | |||
21 | 21 | ||
22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | 22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ | 23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ |
24 | string_helpers.o gcd.o list_sort.o | 24 | string_helpers.o gcd.o lcm.o list_sort.o uuid.o |
25 | 25 | ||
26 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) | 26 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) |
27 | CFLAGS_kobject.o += -DDEBUG | 27 | CFLAGS_kobject.o += -DDEBUG |
@@ -39,7 +39,10 @@ lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o | |||
39 | lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o | 39 | lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o |
40 | lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o | 40 | lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o |
41 | obj-$(CONFIG_GENERIC_FIND_LAST_BIT) += find_last_bit.o | 41 | obj-$(CONFIG_GENERIC_FIND_LAST_BIT) += find_last_bit.o |
42 | |||
43 | CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS)) | ||
42 | obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o | 44 | obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o |
45 | |||
43 | obj-$(CONFIG_LOCK_KERNEL) += kernel_lock.o | 46 | obj-$(CONFIG_LOCK_KERNEL) += kernel_lock.o |
44 | obj-$(CONFIG_BTREE) += btree.o | 47 | obj-$(CONFIG_BTREE) += btree.o |
45 | obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o | 48 | obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o |
@@ -82,6 +85,7 @@ obj-$(CONFIG_AUDIT_GENERIC) += audit.o | |||
82 | obj-$(CONFIG_SWIOTLB) += swiotlb.o | 85 | obj-$(CONFIG_SWIOTLB) += swiotlb.o |
83 | obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o | 86 | obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o |
84 | obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o | 87 | obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o |
88 | obj-$(CONFIG_CPU_NOTIFIER_ERROR_INJECT) += cpu-notifier-error-inject.o | ||
85 | 89 | ||
86 | lib-$(CONFIG_GENERIC_BUG) += bug.o | 90 | lib-$(CONFIG_GENERIC_BUG) += bug.o |
87 | 91 | ||
@@ -101,6 +105,8 @@ obj-$(CONFIG_GENERIC_CSUM) += checksum.o | |||
101 | 105 | ||
102 | obj-$(CONFIG_GENERIC_ATOMIC64) += atomic64.o | 106 | obj-$(CONFIG_GENERIC_ATOMIC64) += atomic64.o |
103 | 107 | ||
108 | obj-$(CONFIG_ATOMIC64_SELFTEST) += atomic64_test.o | ||
109 | |||
104 | hostprogs-y := gen_crc32table | 110 | hostprogs-y := gen_crc32table |
105 | clean-files := crc32table.h | 111 | clean-files := crc32table.h |
106 | 112 | ||
diff --git a/lib/atomic64.c b/lib/atomic64.c index 8bee16ec7524..a21c12bc727c 100644 --- a/lib/atomic64.c +++ b/lib/atomic64.c | |||
@@ -162,12 +162,12 @@ int atomic64_add_unless(atomic64_t *v, long long a, long long u) | |||
162 | { | 162 | { |
163 | unsigned long flags; | 163 | unsigned long flags; |
164 | spinlock_t *lock = lock_addr(v); | 164 | spinlock_t *lock = lock_addr(v); |
165 | int ret = 1; | 165 | int ret = 0; |
166 | 166 | ||
167 | spin_lock_irqsave(lock, flags); | 167 | spin_lock_irqsave(lock, flags); |
168 | if (v->counter != u) { | 168 | if (v->counter != u) { |
169 | v->counter += a; | 169 | v->counter += a; |
170 | ret = 0; | 170 | ret = 1; |
171 | } | 171 | } |
172 | spin_unlock_irqrestore(lock, flags); | 172 | spin_unlock_irqrestore(lock, flags); |
173 | return ret; | 173 | return ret; |
diff --git a/lib/atomic64_test.c b/lib/atomic64_test.c new file mode 100644 index 000000000000..9087d71537dd --- /dev/null +++ b/lib/atomic64_test.c | |||
@@ -0,0 +1,165 @@ | |||
1 | /* | ||
2 | * Testsuite for atomic64_t functions | ||
3 | * | ||
4 | * Copyright © 2010 Luca Barbieri | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | */ | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/kernel.h> | ||
13 | #include <asm/atomic.h> | ||
14 | |||
15 | #define INIT(c) do { atomic64_set(&v, c); r = c; } while (0) | ||
16 | static __init int test_atomic64(void) | ||
17 | { | ||
18 | long long v0 = 0xaaa31337c001d00dLL; | ||
19 | long long v1 = 0xdeadbeefdeafcafeLL; | ||
20 | long long v2 = 0xfaceabadf00df001LL; | ||
21 | long long onestwos = 0x1111111122222222LL; | ||
22 | long long one = 1LL; | ||
23 | |||
24 | atomic64_t v = ATOMIC64_INIT(v0); | ||
25 | long long r = v0; | ||
26 | BUG_ON(v.counter != r); | ||
27 | |||
28 | atomic64_set(&v, v1); | ||
29 | r = v1; | ||
30 | BUG_ON(v.counter != r); | ||
31 | BUG_ON(atomic64_read(&v) != r); | ||
32 | |||
33 | INIT(v0); | ||
34 | atomic64_add(onestwos, &v); | ||
35 | r += onestwos; | ||
36 | BUG_ON(v.counter != r); | ||
37 | |||
38 | INIT(v0); | ||
39 | atomic64_add(-one, &v); | ||
40 | r += -one; | ||
41 | BUG_ON(v.counter != r); | ||
42 | |||
43 | INIT(v0); | ||
44 | r += onestwos; | ||
45 | BUG_ON(atomic64_add_return(onestwos, &v) != r); | ||
46 | BUG_ON(v.counter != r); | ||
47 | |||
48 | INIT(v0); | ||
49 | r += -one; | ||
50 | BUG_ON(atomic64_add_return(-one, &v) != r); | ||
51 | BUG_ON(v.counter != r); | ||
52 | |||
53 | INIT(v0); | ||
54 | atomic64_sub(onestwos, &v); | ||
55 | r -= onestwos; | ||
56 | BUG_ON(v.counter != r); | ||
57 | |||
58 | INIT(v0); | ||
59 | atomic64_sub(-one, &v); | ||
60 | r -= -one; | ||
61 | BUG_ON(v.counter != r); | ||
62 | |||
63 | INIT(v0); | ||
64 | r -= onestwos; | ||
65 | BUG_ON(atomic64_sub_return(onestwos, &v) != r); | ||
66 | BUG_ON(v.counter != r); | ||
67 | |||
68 | INIT(v0); | ||
69 | r -= -one; | ||
70 | BUG_ON(atomic64_sub_return(-one, &v) != r); | ||
71 | BUG_ON(v.counter != r); | ||
72 | |||
73 | INIT(v0); | ||
74 | atomic64_inc(&v); | ||
75 | r += one; | ||
76 | BUG_ON(v.counter != r); | ||
77 | |||
78 | INIT(v0); | ||
79 | r += one; | ||
80 | BUG_ON(atomic64_inc_return(&v) != r); | ||
81 | BUG_ON(v.counter != r); | ||
82 | |||
83 | INIT(v0); | ||
84 | atomic64_dec(&v); | ||
85 | r -= one; | ||
86 | BUG_ON(v.counter != r); | ||
87 | |||
88 | INIT(v0); | ||
89 | r -= one; | ||
90 | BUG_ON(atomic64_dec_return(&v) != r); | ||
91 | BUG_ON(v.counter != r); | ||
92 | |||
93 | INIT(v0); | ||
94 | BUG_ON(atomic64_xchg(&v, v1) != v0); | ||
95 | r = v1; | ||
96 | BUG_ON(v.counter != r); | ||
97 | |||
98 | INIT(v0); | ||
99 | BUG_ON(atomic64_cmpxchg(&v, v0, v1) != v0); | ||
100 | r = v1; | ||
101 | BUG_ON(v.counter != r); | ||
102 | |||
103 | INIT(v0); | ||
104 | BUG_ON(atomic64_cmpxchg(&v, v2, v1) != v0); | ||
105 | BUG_ON(v.counter != r); | ||
106 | |||
107 | INIT(v0); | ||
108 | BUG_ON(atomic64_add_unless(&v, one, v0)); | ||
109 | BUG_ON(v.counter != r); | ||
110 | |||
111 | INIT(v0); | ||
112 | BUG_ON(!atomic64_add_unless(&v, one, v1)); | ||
113 | r += one; | ||
114 | BUG_ON(v.counter != r); | ||
115 | |||
116 | #if defined(CONFIG_X86) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(_ASM_GENERIC_ATOMIC64_H) | ||
117 | INIT(onestwos); | ||
118 | BUG_ON(atomic64_dec_if_positive(&v) != (onestwos - 1)); | ||
119 | r -= one; | ||
120 | BUG_ON(v.counter != r); | ||
121 | |||
122 | INIT(0); | ||
123 | BUG_ON(atomic64_dec_if_positive(&v) != -one); | ||
124 | BUG_ON(v.counter != r); | ||
125 | |||
126 | INIT(-one); | ||
127 | BUG_ON(atomic64_dec_if_positive(&v) != (-one - one)); | ||
128 | BUG_ON(v.counter != r); | ||
129 | #else | ||
130 | #warning Please implement atomic64_dec_if_positive for your architecture, and add it to the IF above | ||
131 | #endif | ||
132 | |||
133 | INIT(onestwos); | ||
134 | BUG_ON(!atomic64_inc_not_zero(&v)); | ||
135 | r += one; | ||
136 | BUG_ON(v.counter != r); | ||
137 | |||
138 | INIT(0); | ||
139 | BUG_ON(atomic64_inc_not_zero(&v)); | ||
140 | BUG_ON(v.counter != r); | ||
141 | |||
142 | INIT(-one); | ||
143 | BUG_ON(!atomic64_inc_not_zero(&v)); | ||
144 | r += one; | ||
145 | BUG_ON(v.counter != r); | ||
146 | |||
147 | #ifdef CONFIG_X86 | ||
148 | printk(KERN_INFO "atomic64 test passed for %s platform %s CX8 and %s SSE\n", | ||
149 | #ifdef CONFIG_X86_64 | ||
150 | "x86-64", | ||
151 | #elif defined(CONFIG_X86_CMPXCHG64) | ||
152 | "i586+", | ||
153 | #else | ||
154 | "i386+", | ||
155 | #endif | ||
156 | boot_cpu_has(X86_FEATURE_CX8) ? "with" : "without", | ||
157 | boot_cpu_has(X86_FEATURE_XMM) ? "with" : "without"); | ||
158 | #else | ||
159 | printk(KERN_INFO "atomic64 test passed\n"); | ||
160 | #endif | ||
161 | |||
162 | return 0; | ||
163 | } | ||
164 | |||
165 | core_initcall(test_atomic64); | ||
diff --git a/lib/btree.c b/lib/btree.c index 41859a820218..c9c6f0351526 100644 --- a/lib/btree.c +++ b/lib/btree.c | |||
@@ -95,7 +95,8 @@ static unsigned long *btree_node_alloc(struct btree_head *head, gfp_t gfp) | |||
95 | unsigned long *node; | 95 | unsigned long *node; |
96 | 96 | ||
97 | node = mempool_alloc(head->mempool, gfp); | 97 | node = mempool_alloc(head->mempool, gfp); |
98 | memset(node, 0, NODESIZE); | 98 | if (likely(node)) |
99 | memset(node, 0, NODESIZE); | ||
99 | return node; | 100 | return node; |
100 | } | 101 | } |
101 | 102 | ||
@@ -165,7 +165,7 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs) | |||
165 | (void *)bugaddr); | 165 | (void *)bugaddr); |
166 | 166 | ||
167 | show_regs(regs); | 167 | show_regs(regs); |
168 | add_taint(TAINT_WARN); | 168 | add_taint(BUG_GET_TAINT(bug)); |
169 | return BUG_TRAP_TYPE_WARN; | 169 | return BUG_TRAP_TYPE_WARN; |
170 | } | 170 | } |
171 | 171 | ||
diff --git a/lib/cpu-notifier-error-inject.c b/lib/cpu-notifier-error-inject.c new file mode 100644 index 000000000000..4dc20321b0d5 --- /dev/null +++ b/lib/cpu-notifier-error-inject.c | |||
@@ -0,0 +1,63 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/cpu.h> | ||
3 | #include <linux/module.h> | ||
4 | #include <linux/notifier.h> | ||
5 | |||
6 | static int priority; | ||
7 | static int cpu_up_prepare_error; | ||
8 | static int cpu_down_prepare_error; | ||
9 | |||
10 | module_param(priority, int, 0); | ||
11 | MODULE_PARM_DESC(priority, "specify cpu notifier priority"); | ||
12 | |||
13 | module_param(cpu_up_prepare_error, int, 0644); | ||
14 | MODULE_PARM_DESC(cpu_up_prepare_error, | ||
15 | "specify error code to inject CPU_UP_PREPARE action"); | ||
16 | |||
17 | module_param(cpu_down_prepare_error, int, 0644); | ||
18 | MODULE_PARM_DESC(cpu_down_prepare_error, | ||
19 | "specify error code to inject CPU_DOWN_PREPARE action"); | ||
20 | |||
21 | static int err_inject_cpu_callback(struct notifier_block *nfb, | ||
22 | unsigned long action, void *hcpu) | ||
23 | { | ||
24 | int err = 0; | ||
25 | |||
26 | switch (action) { | ||
27 | case CPU_UP_PREPARE: | ||
28 | case CPU_UP_PREPARE_FROZEN: | ||
29 | err = cpu_up_prepare_error; | ||
30 | break; | ||
31 | case CPU_DOWN_PREPARE: | ||
32 | case CPU_DOWN_PREPARE_FROZEN: | ||
33 | err = cpu_down_prepare_error; | ||
34 | break; | ||
35 | } | ||
36 | if (err) | ||
37 | printk(KERN_INFO "Injecting error (%d) at cpu notifier\n", err); | ||
38 | |||
39 | return notifier_from_errno(err); | ||
40 | } | ||
41 | |||
42 | static struct notifier_block err_inject_cpu_notifier = { | ||
43 | .notifier_call = err_inject_cpu_callback, | ||
44 | }; | ||
45 | |||
46 | static int err_inject_init(void) | ||
47 | { | ||
48 | err_inject_cpu_notifier.priority = priority; | ||
49 | |||
50 | return register_hotcpu_notifier(&err_inject_cpu_notifier); | ||
51 | } | ||
52 | |||
53 | static void err_inject_exit(void) | ||
54 | { | ||
55 | unregister_hotcpu_notifier(&err_inject_cpu_notifier); | ||
56 | } | ||
57 | |||
58 | module_init(err_inject_init); | ||
59 | module_exit(err_inject_exit); | ||
60 | |||
61 | MODULE_DESCRIPTION("CPU notifier error injection module"); | ||
62 | MODULE_LICENSE("GPL"); | ||
63 | MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>"); | ||
diff --git a/lib/cpumask.c b/lib/cpumask.c index 7bb4142a502f..05d6aca7fc19 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <linux/slab.h> | ||
1 | #include <linux/kernel.h> | 2 | #include <linux/kernel.h> |
2 | #include <linux/bitops.h> | 3 | #include <linux/bitops.h> |
3 | #include <linux/cpumask.h> | 4 | #include <linux/cpumask.h> |
diff --git a/lib/crc32.c b/lib/crc32.c index 0f45fbff34cb..4855995fcde9 100644 --- a/lib/crc32.c +++ b/lib/crc32.c | |||
@@ -25,7 +25,6 @@ | |||
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <linux/compiler.h> | 26 | #include <linux/compiler.h> |
27 | #include <linux/types.h> | 27 | #include <linux/types.h> |
28 | #include <linux/slab.h> | ||
29 | #include <linux/init.h> | 28 | #include <linux/init.h> |
30 | #include <asm/atomic.h> | 29 | #include <asm/atomic.h> |
31 | #include "crc32defs.h" | 30 | #include "crc32defs.h" |
@@ -49,12 +48,20 @@ MODULE_LICENSE("GPL"); | |||
49 | #if CRC_LE_BITS == 8 || CRC_BE_BITS == 8 | 48 | #if CRC_LE_BITS == 8 || CRC_BE_BITS == 8 |
50 | 49 | ||
51 | static inline u32 | 50 | static inline u32 |
52 | crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 *tab) | 51 | crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256]) |
53 | { | 52 | { |
54 | # ifdef __LITTLE_ENDIAN | 53 | # ifdef __LITTLE_ENDIAN |
55 | # define DO_CRC(x) crc = tab[(crc ^ (x)) & 255 ] ^ (crc >> 8) | 54 | # define DO_CRC(x) crc = tab[0][(crc ^ (x)) & 255] ^ (crc >> 8) |
55 | # define DO_CRC4 crc = tab[3][(crc) & 255] ^ \ | ||
56 | tab[2][(crc >> 8) & 255] ^ \ | ||
57 | tab[1][(crc >> 16) & 255] ^ \ | ||
58 | tab[0][(crc >> 24) & 255] | ||
56 | # else | 59 | # else |
57 | # define DO_CRC(x) crc = tab[((crc >> 24) ^ (x)) & 255] ^ (crc << 8) | 60 | # define DO_CRC(x) crc = tab[0][((crc >> 24) ^ (x)) & 255] ^ (crc << 8) |
61 | # define DO_CRC4 crc = tab[0][(crc) & 255] ^ \ | ||
62 | tab[1][(crc >> 8) & 255] ^ \ | ||
63 | tab[2][(crc >> 16) & 255] ^ \ | ||
64 | tab[3][(crc >> 24) & 255] | ||
58 | # endif | 65 | # endif |
59 | const u32 *b; | 66 | const u32 *b; |
60 | size_t rem_len; | 67 | size_t rem_len; |
@@ -71,10 +78,7 @@ crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 *tab) | |||
71 | b = (const u32 *)buf; | 78 | b = (const u32 *)buf; |
72 | for (--b; len; --len) { | 79 | for (--b; len; --len) { |
73 | crc ^= *++b; /* use pre increment for speed */ | 80 | crc ^= *++b; /* use pre increment for speed */ |
74 | DO_CRC(0); | 81 | DO_CRC4; |
75 | DO_CRC(0); | ||
76 | DO_CRC(0); | ||
77 | DO_CRC(0); | ||
78 | } | 82 | } |
79 | len = rem_len; | 83 | len = rem_len; |
80 | /* And the last few bytes */ | 84 | /* And the last few bytes */ |
@@ -86,6 +90,7 @@ crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 *tab) | |||
86 | } | 90 | } |
87 | return crc; | 91 | return crc; |
88 | #undef DO_CRC | 92 | #undef DO_CRC |
93 | #undef DO_CRC4 | ||
89 | } | 94 | } |
90 | #endif | 95 | #endif |
91 | /** | 96 | /** |
@@ -118,7 +123,7 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) | |||
118 | u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) | 123 | u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) |
119 | { | 124 | { |
120 | # if CRC_LE_BITS == 8 | 125 | # if CRC_LE_BITS == 8 |
121 | const u32 *tab = crc32table_le; | 126 | const u32 (*tab)[] = crc32table_le; |
122 | 127 | ||
123 | crc = __cpu_to_le32(crc); | 128 | crc = __cpu_to_le32(crc); |
124 | crc = crc32_body(crc, p, len, tab); | 129 | crc = crc32_body(crc, p, len, tab); |
@@ -175,7 +180,7 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) | |||
175 | u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) | 180 | u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) |
176 | { | 181 | { |
177 | # if CRC_BE_BITS == 8 | 182 | # if CRC_BE_BITS == 8 |
178 | const u32 *tab = crc32table_be; | 183 | const u32 (*tab)[] = crc32table_be; |
179 | 184 | ||
180 | crc = __cpu_to_be32(crc); | 185 | crc = __cpu_to_be32(crc); |
181 | crc = crc32_body(crc, p, len, tab); | 186 | crc = crc32_body(crc, p, len, tab); |
diff --git a/lib/debugobjects.c b/lib/debugobjects.c index a9a8996d286a..deebcc57d4e6 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/sched.h> | 12 | #include <linux/sched.h> |
13 | #include <linux/seq_file.h> | 13 | #include <linux/seq_file.h> |
14 | #include <linux/debugfs.h> | 14 | #include <linux/debugfs.h> |
15 | #include <linux/slab.h> | ||
15 | #include <linux/hash.h> | 16 | #include <linux/hash.h> |
16 | 17 | ||
17 | #define ODEBUG_HASH_BITS 14 | 18 | #define ODEBUG_HASH_BITS 14 |
@@ -140,6 +141,7 @@ alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr) | |||
140 | obj->object = addr; | 141 | obj->object = addr; |
141 | obj->descr = descr; | 142 | obj->descr = descr; |
142 | obj->state = ODEBUG_STATE_NONE; | 143 | obj->state = ODEBUG_STATE_NONE; |
144 | obj->astate = 0; | ||
143 | hlist_del(&obj->node); | 145 | hlist_del(&obj->node); |
144 | 146 | ||
145 | hlist_add_head(&obj->node, &b->list); | 147 | hlist_add_head(&obj->node, &b->list); |
@@ -251,8 +253,10 @@ static void debug_print_object(struct debug_obj *obj, char *msg) | |||
251 | 253 | ||
252 | if (limit < 5 && obj->descr != descr_test) { | 254 | if (limit < 5 && obj->descr != descr_test) { |
253 | limit++; | 255 | limit++; |
254 | WARN(1, KERN_ERR "ODEBUG: %s %s object type: %s\n", msg, | 256 | WARN(1, KERN_ERR "ODEBUG: %s %s (active state %u) " |
255 | obj_states[obj->state], obj->descr->name); | 257 | "object type: %s\n", |
258 | msg, obj_states[obj->state], obj->astate, | ||
259 | obj->descr->name); | ||
256 | } | 260 | } |
257 | debug_objects_warnings++; | 261 | debug_objects_warnings++; |
258 | } | 262 | } |
@@ -446,7 +450,10 @@ void debug_object_deactivate(void *addr, struct debug_obj_descr *descr) | |||
446 | case ODEBUG_STATE_INIT: | 450 | case ODEBUG_STATE_INIT: |
447 | case ODEBUG_STATE_INACTIVE: | 451 | case ODEBUG_STATE_INACTIVE: |
448 | case ODEBUG_STATE_ACTIVE: | 452 | case ODEBUG_STATE_ACTIVE: |
449 | obj->state = ODEBUG_STATE_INACTIVE; | 453 | if (!obj->astate) |
454 | obj->state = ODEBUG_STATE_INACTIVE; | ||
455 | else | ||
456 | debug_print_object(obj, "deactivate"); | ||
450 | break; | 457 | break; |
451 | 458 | ||
452 | case ODEBUG_STATE_DESTROYED: | 459 | case ODEBUG_STATE_DESTROYED: |
@@ -552,6 +559,53 @@ out_unlock: | |||
552 | raw_spin_unlock_irqrestore(&db->lock, flags); | 559 | raw_spin_unlock_irqrestore(&db->lock, flags); |
553 | } | 560 | } |
554 | 561 | ||
562 | /** | ||
563 | * debug_object_active_state - debug checks object usage state machine | ||
564 | * @addr: address of the object | ||
565 | * @descr: pointer to an object specific debug description structure | ||
566 | * @expect: expected state | ||
567 | * @next: state to move to if expected state is found | ||
568 | */ | ||
569 | void | ||
570 | debug_object_active_state(void *addr, struct debug_obj_descr *descr, | ||
571 | unsigned int expect, unsigned int next) | ||
572 | { | ||
573 | struct debug_bucket *db; | ||
574 | struct debug_obj *obj; | ||
575 | unsigned long flags; | ||
576 | |||
577 | if (!debug_objects_enabled) | ||
578 | return; | ||
579 | |||
580 | db = get_bucket((unsigned long) addr); | ||
581 | |||
582 | raw_spin_lock_irqsave(&db->lock, flags); | ||
583 | |||
584 | obj = lookup_object(addr, db); | ||
585 | if (obj) { | ||
586 | switch (obj->state) { | ||
587 | case ODEBUG_STATE_ACTIVE: | ||
588 | if (obj->astate == expect) | ||
589 | obj->astate = next; | ||
590 | else | ||
591 | debug_print_object(obj, "active_state"); | ||
592 | break; | ||
593 | |||
594 | default: | ||
595 | debug_print_object(obj, "active_state"); | ||
596 | break; | ||
597 | } | ||
598 | } else { | ||
599 | struct debug_obj o = { .object = addr, | ||
600 | .state = ODEBUG_STATE_NOTAVAILABLE, | ||
601 | .descr = descr }; | ||
602 | |||
603 | debug_print_object(&o, "active_state"); | ||
604 | } | ||
605 | |||
606 | raw_spin_unlock_irqrestore(&db->lock, flags); | ||
607 | } | ||
608 | |||
555 | #ifdef CONFIG_DEBUG_OBJECTS_FREE | 609 | #ifdef CONFIG_DEBUG_OBJECTS_FREE |
556 | static void __debug_check_no_obj_freed(const void *address, unsigned long size) | 610 | static void __debug_check_no_obj_freed(const void *address, unsigned long size) |
557 | { | 611 | { |
@@ -773,7 +827,7 @@ static int __init fixup_free(void *addr, enum debug_obj_state state) | |||
773 | } | 827 | } |
774 | } | 828 | } |
775 | 829 | ||
776 | static int | 830 | static int __init |
777 | check_results(void *addr, enum debug_obj_state state, int fixups, int warnings) | 831 | check_results(void *addr, enum debug_obj_state state, int fixups, int warnings) |
778 | { | 832 | { |
779 | struct debug_bucket *db; | 833 | struct debug_bucket *db; |
@@ -916,7 +970,7 @@ void __init debug_objects_early_init(void) | |||
916 | /* | 970 | /* |
917 | * Convert the statically allocated objects to dynamic ones: | 971 | * Convert the statically allocated objects to dynamic ones: |
918 | */ | 972 | */ |
919 | static int debug_objects_replace_static_objects(void) | 973 | static int __init debug_objects_replace_static_objects(void) |
920 | { | 974 | { |
921 | struct debug_bucket *db = obj_hash; | 975 | struct debug_bucket *db = obj_hash; |
922 | struct hlist_node *node, *tmp; | 976 | struct hlist_node *node, *tmp; |
diff --git a/lib/decompress_unlzo.c b/lib/decompress_unlzo.c index db521f45626e..bcb3a4bd68ff 100644 --- a/lib/decompress_unlzo.c +++ b/lib/decompress_unlzo.c | |||
@@ -97,7 +97,7 @@ STATIC inline int INIT unlzo(u8 *input, int in_len, | |||
97 | u32 src_len, dst_len; | 97 | u32 src_len, dst_len; |
98 | size_t tmp; | 98 | size_t tmp; |
99 | u8 *in_buf, *in_buf_save, *out_buf; | 99 | u8 *in_buf, *in_buf_save, *out_buf; |
100 | int obytes_processed = 0; | 100 | int ret = -1; |
101 | 101 | ||
102 | set_error_fn(error_fn); | 102 | set_error_fn(error_fn); |
103 | 103 | ||
@@ -174,15 +174,22 @@ STATIC inline int INIT unlzo(u8 *input, int in_len, | |||
174 | 174 | ||
175 | /* decompress */ | 175 | /* decompress */ |
176 | tmp = dst_len; | 176 | tmp = dst_len; |
177 | r = lzo1x_decompress_safe((u8 *) in_buf, src_len, | 177 | |
178 | /* When the input data is not compressed at all, | ||
179 | * lzo1x_decompress_safe will fail, so call memcpy() | ||
180 | * instead */ | ||
181 | if (unlikely(dst_len == src_len)) | ||
182 | memcpy(out_buf, in_buf, src_len); | ||
183 | else { | ||
184 | r = lzo1x_decompress_safe((u8 *) in_buf, src_len, | ||
178 | out_buf, &tmp); | 185 | out_buf, &tmp); |
179 | 186 | ||
180 | if (r != LZO_E_OK || dst_len != tmp) { | 187 | if (r != LZO_E_OK || dst_len != tmp) { |
181 | error("Compressed data violation"); | 188 | error("Compressed data violation"); |
182 | goto exit_2; | 189 | goto exit_2; |
190 | } | ||
183 | } | 191 | } |
184 | 192 | ||
185 | obytes_processed += dst_len; | ||
186 | if (flush) | 193 | if (flush) |
187 | flush(out_buf, dst_len); | 194 | flush(out_buf, dst_len); |
188 | if (output) | 195 | if (output) |
@@ -196,6 +203,7 @@ STATIC inline int INIT unlzo(u8 *input, int in_len, | |||
196 | in_buf += src_len; | 203 | in_buf += src_len; |
197 | } | 204 | } |
198 | 205 | ||
206 | ret = 0; | ||
199 | exit_2: | 207 | exit_2: |
200 | if (!input) | 208 | if (!input) |
201 | free(in_buf); | 209 | free(in_buf); |
@@ -203,7 +211,7 @@ exit_1: | |||
203 | if (!output) | 211 | if (!output) |
204 | free(out_buf); | 212 | free(out_buf); |
205 | exit: | 213 | exit: |
206 | return obytes_processed; | 214 | return ret; |
207 | } | 215 | } |
208 | 216 | ||
209 | #define decompress unlzo | 217 | #define decompress unlzo |
diff --git a/lib/devres.c b/lib/devres.c index 72c8909006da..49368608f988 100644 --- a/lib/devres.c +++ b/lib/devres.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include <linux/pci.h> | 1 | #include <linux/pci.h> |
2 | #include <linux/io.h> | 2 | #include <linux/io.h> |
3 | #include <linux/gfp.h> | ||
3 | #include <linux/module.h> | 4 | #include <linux/module.h> |
4 | 5 | ||
5 | void devm_ioremap_release(struct device *dev, void *res) | 6 | void devm_ioremap_release(struct device *dev, void *res) |
diff --git a/lib/dma-debug.c b/lib/dma-debug.c index ba8b67039d13..01e64270e246 100644 --- a/lib/dma-debug.c +++ b/lib/dma-debug.c | |||
@@ -570,7 +570,7 @@ static ssize_t filter_write(struct file *file, const char __user *userbuf, | |||
570 | * Now parse out the first token and use it as the name for the | 570 | * Now parse out the first token and use it as the name for the |
571 | * driver to filter for. | 571 | * driver to filter for. |
572 | */ | 572 | */ |
573 | for (i = 0; i < NAME_MAX_LEN; ++i) { | 573 | for (i = 0; i < NAME_MAX_LEN - 1; ++i) { |
574 | current_driver_name[i] = buf[i]; | 574 | current_driver_name[i] = buf[i]; |
575 | if (isspace(buf[i]) || buf[i] == ' ' || buf[i] == 0) | 575 | if (isspace(buf[i]) || buf[i] == ' ' || buf[i] == 0) |
576 | break; | 576 | break; |
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index f93502915988..3df8eb17a607 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/uaccess.h> | 25 | #include <linux/uaccess.h> |
26 | #include <linux/dynamic_debug.h> | 26 | #include <linux/dynamic_debug.h> |
27 | #include <linux/debugfs.h> | 27 | #include <linux/debugfs.h> |
28 | #include <linux/slab.h> | ||
28 | 29 | ||
29 | extern struct _ddebug __start___verbose[]; | 30 | extern struct _ddebug __start___verbose[]; |
30 | extern struct _ddebug __stop___verbose[]; | 31 | extern struct _ddebug __stop___verbose[]; |
@@ -455,7 +456,7 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, | |||
455 | __func__, (int)len); | 456 | __func__, (int)len); |
456 | 457 | ||
457 | nwords = ddebug_tokenize(tmpbuf, words, MAXWORDS); | 458 | nwords = ddebug_tokenize(tmpbuf, words, MAXWORDS); |
458 | if (nwords < 0) | 459 | if (nwords <= 0) |
459 | return -EINVAL; | 460 | return -EINVAL; |
460 | if (ddebug_parse_query(words, nwords-1, &query)) | 461 | if (ddebug_parse_query(words, nwords-1, &query)) |
461 | return -EINVAL; | 462 | return -EINVAL; |
diff --git a/lib/flex_array.c b/lib/flex_array.c index 66eef2e4483e..41b1804fa728 100644 --- a/lib/flex_array.c +++ b/lib/flex_array.c | |||
@@ -99,7 +99,7 @@ struct flex_array *flex_array_alloc(int element_size, unsigned int total, | |||
99 | ret->element_size = element_size; | 99 | ret->element_size = element_size; |
100 | ret->total_nr_elements = total; | 100 | ret->total_nr_elements = total; |
101 | if (elements_fit_in_base(ret) && !(flags & __GFP_ZERO)) | 101 | if (elements_fit_in_base(ret) && !(flags & __GFP_ZERO)) |
102 | memset(ret->parts[0], FLEX_ARRAY_FREE, | 102 | memset(&ret->parts[0], FLEX_ARRAY_FREE, |
103 | FLEX_ARRAY_BASE_BYTES_LEFT); | 103 | FLEX_ARRAY_BASE_BYTES_LEFT); |
104 | return ret; | 104 | return ret; |
105 | } | 105 | } |
diff --git a/lib/gen_crc32table.c b/lib/gen_crc32table.c index bea5d97df991..85d0e412a04f 100644 --- a/lib/gen_crc32table.c +++ b/lib/gen_crc32table.c | |||
@@ -7,8 +7,8 @@ | |||
7 | #define LE_TABLE_SIZE (1 << CRC_LE_BITS) | 7 | #define LE_TABLE_SIZE (1 << CRC_LE_BITS) |
8 | #define BE_TABLE_SIZE (1 << CRC_BE_BITS) | 8 | #define BE_TABLE_SIZE (1 << CRC_BE_BITS) |
9 | 9 | ||
10 | static uint32_t crc32table_le[LE_TABLE_SIZE]; | 10 | static uint32_t crc32table_le[4][LE_TABLE_SIZE]; |
11 | static uint32_t crc32table_be[BE_TABLE_SIZE]; | 11 | static uint32_t crc32table_be[4][BE_TABLE_SIZE]; |
12 | 12 | ||
13 | /** | 13 | /** |
14 | * crc32init_le() - allocate and initialize LE table data | 14 | * crc32init_le() - allocate and initialize LE table data |
@@ -22,12 +22,19 @@ static void crc32init_le(void) | |||
22 | unsigned i, j; | 22 | unsigned i, j; |
23 | uint32_t crc = 1; | 23 | uint32_t crc = 1; |
24 | 24 | ||
25 | crc32table_le[0] = 0; | 25 | crc32table_le[0][0] = 0; |
26 | 26 | ||
27 | for (i = 1 << (CRC_LE_BITS - 1); i; i >>= 1) { | 27 | for (i = 1 << (CRC_LE_BITS - 1); i; i >>= 1) { |
28 | crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); | 28 | crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); |
29 | for (j = 0; j < LE_TABLE_SIZE; j += 2 * i) | 29 | for (j = 0; j < LE_TABLE_SIZE; j += 2 * i) |
30 | crc32table_le[i + j] = crc ^ crc32table_le[j]; | 30 | crc32table_le[0][i + j] = crc ^ crc32table_le[0][j]; |
31 | } | ||
32 | for (i = 0; i < LE_TABLE_SIZE; i++) { | ||
33 | crc = crc32table_le[0][i]; | ||
34 | for (j = 1; j < 4; j++) { | ||
35 | crc = crc32table_le[0][crc & 0xff] ^ (crc >> 8); | ||
36 | crc32table_le[j][i] = crc; | ||
37 | } | ||
31 | } | 38 | } |
32 | } | 39 | } |
33 | 40 | ||
@@ -39,25 +46,35 @@ static void crc32init_be(void) | |||
39 | unsigned i, j; | 46 | unsigned i, j; |
40 | uint32_t crc = 0x80000000; | 47 | uint32_t crc = 0x80000000; |
41 | 48 | ||
42 | crc32table_be[0] = 0; | 49 | crc32table_be[0][0] = 0; |
43 | 50 | ||
44 | for (i = 1; i < BE_TABLE_SIZE; i <<= 1) { | 51 | for (i = 1; i < BE_TABLE_SIZE; i <<= 1) { |
45 | crc = (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 0); | 52 | crc = (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 0); |
46 | for (j = 0; j < i; j++) | 53 | for (j = 0; j < i; j++) |
47 | crc32table_be[i + j] = crc ^ crc32table_be[j]; | 54 | crc32table_be[0][i + j] = crc ^ crc32table_be[0][j]; |
55 | } | ||
56 | for (i = 0; i < BE_TABLE_SIZE; i++) { | ||
57 | crc = crc32table_be[0][i]; | ||
58 | for (j = 1; j < 4; j++) { | ||
59 | crc = crc32table_be[0][(crc >> 24) & 0xff] ^ (crc << 8); | ||
60 | crc32table_be[j][i] = crc; | ||
61 | } | ||
48 | } | 62 | } |
49 | } | 63 | } |
50 | 64 | ||
51 | static void output_table(uint32_t table[], int len, char *trans) | 65 | static void output_table(uint32_t table[4][256], int len, char *trans) |
52 | { | 66 | { |
53 | int i; | 67 | int i, j; |
54 | 68 | ||
55 | for (i = 0; i < len - 1; i++) { | 69 | for (j = 0 ; j < 4; j++) { |
56 | if (i % ENTRIES_PER_LINE == 0) | 70 | printf("{"); |
57 | printf("\n"); | 71 | for (i = 0; i < len - 1; i++) { |
58 | printf("%s(0x%8.8xL), ", trans, table[i]); | 72 | if (i % ENTRIES_PER_LINE == 0) |
73 | printf("\n"); | ||
74 | printf("%s(0x%8.8xL), ", trans, table[j][i]); | ||
75 | } | ||
76 | printf("%s(0x%8.8xL)},\n", trans, table[j][len - 1]); | ||
59 | } | 77 | } |
60 | printf("%s(0x%8.8xL)\n", trans, table[len - 1]); | ||
61 | } | 78 | } |
62 | 79 | ||
63 | int main(int argc, char** argv) | 80 | int main(int argc, char** argv) |
@@ -66,14 +83,14 @@ int main(int argc, char** argv) | |||
66 | 83 | ||
67 | if (CRC_LE_BITS > 1) { | 84 | if (CRC_LE_BITS > 1) { |
68 | crc32init_le(); | 85 | crc32init_le(); |
69 | printf("static const u32 crc32table_le[] = {"); | 86 | printf("static const u32 crc32table_le[4][256] = {"); |
70 | output_table(crc32table_le, LE_TABLE_SIZE, "tole"); | 87 | output_table(crc32table_le, LE_TABLE_SIZE, "tole"); |
71 | printf("};\n"); | 88 | printf("};\n"); |
72 | } | 89 | } |
73 | 90 | ||
74 | if (CRC_BE_BITS > 1) { | 91 | if (CRC_BE_BITS > 1) { |
75 | crc32init_be(); | 92 | crc32init_be(); |
76 | printf("static const u32 crc32table_be[] = {"); | 93 | printf("static const u32 crc32table_be[4][256] = {"); |
77 | output_table(crc32table_be, BE_TABLE_SIZE, "tobe"); | 94 | output_table(crc32table_be, BE_TABLE_SIZE, "tobe"); |
78 | printf("};\n"); | 95 | printf("};\n"); |
79 | } | 96 | } |
diff --git a/lib/genalloc.c b/lib/genalloc.c index e67f97495dd5..736c3b06398e 100644 --- a/lib/genalloc.c +++ b/lib/genalloc.c | |||
@@ -10,6 +10,7 @@ | |||
10 | * Version 2. See the file COPYING for more details. | 10 | * Version 2. See the file COPYING for more details. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/slab.h> | ||
13 | #include <linux/module.h> | 14 | #include <linux/module.h> |
14 | #include <linux/bitmap.h> | 15 | #include <linux/bitmap.h> |
15 | #include <linux/genalloc.h> | 16 | #include <linux/genalloc.h> |
diff --git a/lib/hexdump.c b/lib/hexdump.c index 39af2560f765..5d7a4802c562 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c | |||
@@ -16,6 +16,24 @@ const char hex_asc[] = "0123456789abcdef"; | |||
16 | EXPORT_SYMBOL(hex_asc); | 16 | EXPORT_SYMBOL(hex_asc); |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * hex_to_bin - convert a hex digit to its real value | ||
20 | * @ch: ascii character represents hex digit | ||
21 | * | ||
22 | * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad | ||
23 | * input. | ||
24 | */ | ||
25 | int hex_to_bin(char ch) | ||
26 | { | ||
27 | if ((ch >= '0') && (ch <= '9')) | ||
28 | return ch - '0'; | ||
29 | ch = tolower(ch); | ||
30 | if ((ch >= 'a') && (ch <= 'f')) | ||
31 | return ch - 'a' + 10; | ||
32 | return -1; | ||
33 | } | ||
34 | EXPORT_SYMBOL(hex_to_bin); | ||
35 | |||
36 | /** | ||
19 | * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory | 37 | * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory |
20 | * @buf: data blob to dump | 38 | * @buf: data blob to dump |
21 | * @len: number of bytes in the @buf | 39 | * @len: number of bytes in the @buf |
@@ -34,7 +52,7 @@ EXPORT_SYMBOL(hex_asc); | |||
34 | * | 52 | * |
35 | * E.g.: | 53 | * E.g.: |
36 | * hex_dump_to_buffer(frame->data, frame->len, 16, 1, | 54 | * hex_dump_to_buffer(frame->data, frame->len, 16, 1, |
37 | * linebuf, sizeof(linebuf), 1); | 55 | * linebuf, sizeof(linebuf), true); |
38 | * | 56 | * |
39 | * example output buffer: | 57 | * example output buffer: |
40 | * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO | 58 | * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO |
@@ -65,8 +83,8 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize, | |||
65 | 83 | ||
66 | for (j = 0; j < ngroups; j++) | 84 | for (j = 0; j < ngroups; j++) |
67 | lx += scnprintf(linebuf + lx, linebuflen - lx, | 85 | lx += scnprintf(linebuf + lx, linebuflen - lx, |
68 | "%s%16.16llx", j ? " " : "", | 86 | "%s%16.16llx", j ? " " : "", |
69 | (unsigned long long)*(ptr8 + j)); | 87 | (unsigned long long)*(ptr8 + j)); |
70 | ascii_column = 17 * ngroups + 2; | 88 | ascii_column = 17 * ngroups + 2; |
71 | break; | 89 | break; |
72 | } | 90 | } |
@@ -77,7 +95,7 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize, | |||
77 | 95 | ||
78 | for (j = 0; j < ngroups; j++) | 96 | for (j = 0; j < ngroups; j++) |
79 | lx += scnprintf(linebuf + lx, linebuflen - lx, | 97 | lx += scnprintf(linebuf + lx, linebuflen - lx, |
80 | "%s%8.8x", j ? " " : "", *(ptr4 + j)); | 98 | "%s%8.8x", j ? " " : "", *(ptr4 + j)); |
81 | ascii_column = 9 * ngroups + 2; | 99 | ascii_column = 9 * ngroups + 2; |
82 | break; | 100 | break; |
83 | } | 101 | } |
@@ -88,7 +106,7 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize, | |||
88 | 106 | ||
89 | for (j = 0; j < ngroups; j++) | 107 | for (j = 0; j < ngroups; j++) |
90 | lx += scnprintf(linebuf + lx, linebuflen - lx, | 108 | lx += scnprintf(linebuf + lx, linebuflen - lx, |
91 | "%s%4.4x", j ? " " : "", *(ptr2 + j)); | 109 | "%s%4.4x", j ? " " : "", *(ptr2 + j)); |
92 | ascii_column = 5 * ngroups + 2; | 110 | ascii_column = 5 * ngroups + 2; |
93 | break; | 111 | break; |
94 | } | 112 | } |
@@ -111,9 +129,10 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize, | |||
111 | 129 | ||
112 | while (lx < (linebuflen - 1) && lx < (ascii_column - 1)) | 130 | while (lx < (linebuflen - 1) && lx < (ascii_column - 1)) |
113 | linebuf[lx++] = ' '; | 131 | linebuf[lx++] = ' '; |
114 | for (j = 0; (j < len) && (lx + 2) < linebuflen; j++) | 132 | for (j = 0; (j < len) && (lx + 2) < linebuflen; j++) { |
115 | linebuf[lx++] = (isascii(ptr[j]) && isprint(ptr[j])) ? ptr[j] | 133 | ch = ptr[j]; |
116 | : '.'; | 134 | linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.'; |
135 | } | ||
117 | nil: | 136 | nil: |
118 | linebuf[lx++] = '\0'; | 137 | linebuf[lx++] = '\0'; |
119 | } | 138 | } |
@@ -143,7 +162,7 @@ EXPORT_SYMBOL(hex_dump_to_buffer); | |||
143 | * | 162 | * |
144 | * E.g.: | 163 | * E.g.: |
145 | * print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS, | 164 | * print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS, |
146 | * 16, 1, frame->data, frame->len, 1); | 165 | * 16, 1, frame->data, frame->len, true); |
147 | * | 166 | * |
148 | * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode: | 167 | * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode: |
149 | * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO | 168 | * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO |
@@ -151,12 +170,12 @@ EXPORT_SYMBOL(hex_dump_to_buffer); | |||
151 | * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~. | 170 | * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~. |
152 | */ | 171 | */ |
153 | void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, | 172 | void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, |
154 | int rowsize, int groupsize, | 173 | int rowsize, int groupsize, |
155 | const void *buf, size_t len, bool ascii) | 174 | const void *buf, size_t len, bool ascii) |
156 | { | 175 | { |
157 | const u8 *ptr = buf; | 176 | const u8 *ptr = buf; |
158 | int i, linelen, remaining = len; | 177 | int i, linelen, remaining = len; |
159 | unsigned char linebuf[200]; | 178 | unsigned char linebuf[32 * 3 + 2 + 32 + 1]; |
160 | 179 | ||
161 | if (rowsize != 16 && rowsize != 32) | 180 | if (rowsize != 16 && rowsize != 32) |
162 | rowsize = 16; | 181 | rowsize = 16; |
@@ -164,13 +183,14 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, | |||
164 | for (i = 0; i < len; i += rowsize) { | 183 | for (i = 0; i < len; i += rowsize) { |
165 | linelen = min(remaining, rowsize); | 184 | linelen = min(remaining, rowsize); |
166 | remaining -= rowsize; | 185 | remaining -= rowsize; |
186 | |||
167 | hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, | 187 | hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, |
168 | linebuf, sizeof(linebuf), ascii); | 188 | linebuf, sizeof(linebuf), ascii); |
169 | 189 | ||
170 | switch (prefix_type) { | 190 | switch (prefix_type) { |
171 | case DUMP_PREFIX_ADDRESS: | 191 | case DUMP_PREFIX_ADDRESS: |
172 | printk("%s%s%*p: %s\n", level, prefix_str, | 192 | printk("%s%s%p: %s\n", |
173 | (int)(2 * sizeof(void *)), ptr + i, linebuf); | 193 | level, prefix_str, ptr + i, linebuf); |
174 | break; | 194 | break; |
175 | case DUMP_PREFIX_OFFSET: | 195 | case DUMP_PREFIX_OFFSET: |
176 | printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf); | 196 | printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf); |
@@ -196,9 +216,9 @@ EXPORT_SYMBOL(print_hex_dump); | |||
196 | * rowsize of 16, groupsize of 1, and ASCII output included. | 216 | * rowsize of 16, groupsize of 1, and ASCII output included. |
197 | */ | 217 | */ |
198 | void print_hex_dump_bytes(const char *prefix_str, int prefix_type, | 218 | void print_hex_dump_bytes(const char *prefix_str, int prefix_type, |
199 | const void *buf, size_t len) | 219 | const void *buf, size_t len) |
200 | { | 220 | { |
201 | print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1, | 221 | print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1, |
202 | buf, len, 1); | 222 | buf, len, true); |
203 | } | 223 | } |
204 | EXPORT_SYMBOL(print_hex_dump_bytes); | 224 | EXPORT_SYMBOL(print_hex_dump_bytes); |
diff --git a/lib/hweight.c b/lib/hweight.c index 63ee4eb1228d..3c79d50814cf 100644 --- a/lib/hweight.c +++ b/lib/hweight.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * The Hamming Weight of a number is the total number of bits set in it. | 9 | * The Hamming Weight of a number is the total number of bits set in it. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | unsigned int hweight32(unsigned int w) | 12 | unsigned int __sw_hweight32(unsigned int w) |
13 | { | 13 | { |
14 | #ifdef ARCH_HAS_FAST_MULTIPLIER | 14 | #ifdef ARCH_HAS_FAST_MULTIPLIER |
15 | w -= (w >> 1) & 0x55555555; | 15 | w -= (w >> 1) & 0x55555555; |
@@ -24,29 +24,30 @@ unsigned int hweight32(unsigned int w) | |||
24 | return (res + (res >> 16)) & 0x000000FF; | 24 | return (res + (res >> 16)) & 0x000000FF; |
25 | #endif | 25 | #endif |
26 | } | 26 | } |
27 | EXPORT_SYMBOL(hweight32); | 27 | EXPORT_SYMBOL(__sw_hweight32); |
28 | 28 | ||
29 | unsigned int hweight16(unsigned int w) | 29 | unsigned int __sw_hweight16(unsigned int w) |
30 | { | 30 | { |
31 | unsigned int res = w - ((w >> 1) & 0x5555); | 31 | unsigned int res = w - ((w >> 1) & 0x5555); |
32 | res = (res & 0x3333) + ((res >> 2) & 0x3333); | 32 | res = (res & 0x3333) + ((res >> 2) & 0x3333); |
33 | res = (res + (res >> 4)) & 0x0F0F; | 33 | res = (res + (res >> 4)) & 0x0F0F; |
34 | return (res + (res >> 8)) & 0x00FF; | 34 | return (res + (res >> 8)) & 0x00FF; |
35 | } | 35 | } |
36 | EXPORT_SYMBOL(hweight16); | 36 | EXPORT_SYMBOL(__sw_hweight16); |
37 | 37 | ||
38 | unsigned int hweight8(unsigned int w) | 38 | unsigned int __sw_hweight8(unsigned int w) |
39 | { | 39 | { |
40 | unsigned int res = w - ((w >> 1) & 0x55); | 40 | unsigned int res = w - ((w >> 1) & 0x55); |
41 | res = (res & 0x33) + ((res >> 2) & 0x33); | 41 | res = (res & 0x33) + ((res >> 2) & 0x33); |
42 | return (res + (res >> 4)) & 0x0F; | 42 | return (res + (res >> 4)) & 0x0F; |
43 | } | 43 | } |
44 | EXPORT_SYMBOL(hweight8); | 44 | EXPORT_SYMBOL(__sw_hweight8); |
45 | 45 | ||
46 | unsigned long hweight64(__u64 w) | 46 | unsigned long __sw_hweight64(__u64 w) |
47 | { | 47 | { |
48 | #if BITS_PER_LONG == 32 | 48 | #if BITS_PER_LONG == 32 |
49 | return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w); | 49 | return __sw_hweight32((unsigned int)(w >> 32)) + |
50 | __sw_hweight32((unsigned int)w); | ||
50 | #elif BITS_PER_LONG == 64 | 51 | #elif BITS_PER_LONG == 64 |
51 | #ifdef ARCH_HAS_FAST_MULTIPLIER | 52 | #ifdef ARCH_HAS_FAST_MULTIPLIER |
52 | w -= (w >> 1) & 0x5555555555555555ul; | 53 | w -= (w >> 1) & 0x5555555555555555ul; |
@@ -63,4 +64,4 @@ unsigned long hweight64(__u64 w) | |||
63 | #endif | 64 | #endif |
64 | #endif | 65 | #endif |
65 | } | 66 | } |
66 | EXPORT_SYMBOL(hweight64); | 67 | EXPORT_SYMBOL(__sw_hweight64); |
@@ -445,6 +445,7 @@ EXPORT_SYMBOL(idr_remove); | |||
445 | void idr_remove_all(struct idr *idp) | 445 | void idr_remove_all(struct idr *idp) |
446 | { | 446 | { |
447 | int n, id, max; | 447 | int n, id, max; |
448 | int bt_mask; | ||
448 | struct idr_layer *p; | 449 | struct idr_layer *p; |
449 | struct idr_layer *pa[MAX_LEVEL]; | 450 | struct idr_layer *pa[MAX_LEVEL]; |
450 | struct idr_layer **paa = &pa[0]; | 451 | struct idr_layer **paa = &pa[0]; |
@@ -462,8 +463,10 @@ void idr_remove_all(struct idr *idp) | |||
462 | p = p->ary[(id >> n) & IDR_MASK]; | 463 | p = p->ary[(id >> n) & IDR_MASK]; |
463 | } | 464 | } |
464 | 465 | ||
466 | bt_mask = id; | ||
465 | id += 1 << n; | 467 | id += 1 << n; |
466 | while (n < fls(id)) { | 468 | /* Get the highest bit that the above add changed from 0->1. */ |
469 | while (n < fls(id ^ bt_mask)) { | ||
467 | if (p) | 470 | if (p) |
468 | free_layer(p); | 471 | free_layer(p); |
469 | n += IDR_BITS; | 472 | n += IDR_BITS; |
@@ -623,7 +626,7 @@ void *idr_get_next(struct idr *idp, int *nextidp) | |||
623 | } | 626 | } |
624 | return NULL; | 627 | return NULL; |
625 | } | 628 | } |
626 | 629 | EXPORT_SYMBOL(idr_get_next); | |
627 | 630 | ||
628 | 631 | ||
629 | /** | 632 | /** |
diff --git a/lib/inflate.c b/lib/inflate.c index d10255973a9f..677b738c2204 100644 --- a/lib/inflate.c +++ b/lib/inflate.c | |||
@@ -103,6 +103,7 @@ | |||
103 | the two sets of lengths. | 103 | the two sets of lengths. |
104 | */ | 104 | */ |
105 | #include <linux/compiler.h> | 105 | #include <linux/compiler.h> |
106 | #include <linux/slab.h> | ||
106 | 107 | ||
107 | #ifdef RCSID | 108 | #ifdef RCSID |
108 | static char rcsid[] = "#Id: inflate.c,v 0.14 1993/06/10 13:27:04 jloup Exp #"; | 109 | static char rcsid[] = "#Id: inflate.c,v 0.14 1993/06/10 13:27:04 jloup Exp #"; |
diff --git a/lib/kasprintf.c b/lib/kasprintf.c index c5ff1fd10030..9c4233b23783 100644 --- a/lib/kasprintf.c +++ b/lib/kasprintf.c | |||
@@ -6,6 +6,7 @@ | |||
6 | 6 | ||
7 | #include <stdarg.h> | 7 | #include <stdarg.h> |
8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
9 | #include <linux/slab.h> | ||
9 | #include <linux/types.h> | 10 | #include <linux/types.h> |
10 | #include <linux/string.h> | 11 | #include <linux/string.h> |
11 | 12 | ||
diff --git a/lib/kobject.c b/lib/kobject.c index 8115eb1bbf4d..f07c57252e82 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
@@ -850,6 +850,121 @@ struct kset *kset_create_and_add(const char *name, | |||
850 | } | 850 | } |
851 | EXPORT_SYMBOL_GPL(kset_create_and_add); | 851 | EXPORT_SYMBOL_GPL(kset_create_and_add); |
852 | 852 | ||
853 | |||
854 | static DEFINE_SPINLOCK(kobj_ns_type_lock); | ||
855 | static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES]; | ||
856 | |||
857 | int kobj_ns_type_register(const struct kobj_ns_type_operations *ops) | ||
858 | { | ||
859 | enum kobj_ns_type type = ops->type; | ||
860 | int error; | ||
861 | |||
862 | spin_lock(&kobj_ns_type_lock); | ||
863 | |||
864 | error = -EINVAL; | ||
865 | if (type >= KOBJ_NS_TYPES) | ||
866 | goto out; | ||
867 | |||
868 | error = -EINVAL; | ||
869 | if (type <= KOBJ_NS_TYPE_NONE) | ||
870 | goto out; | ||
871 | |||
872 | error = -EBUSY; | ||
873 | if (kobj_ns_ops_tbl[type]) | ||
874 | goto out; | ||
875 | |||
876 | error = 0; | ||
877 | kobj_ns_ops_tbl[type] = ops; | ||
878 | |||
879 | out: | ||
880 | spin_unlock(&kobj_ns_type_lock); | ||
881 | return error; | ||
882 | } | ||
883 | |||
884 | int kobj_ns_type_registered(enum kobj_ns_type type) | ||
885 | { | ||
886 | int registered = 0; | ||
887 | |||
888 | spin_lock(&kobj_ns_type_lock); | ||
889 | if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES)) | ||
890 | registered = kobj_ns_ops_tbl[type] != NULL; | ||
891 | spin_unlock(&kobj_ns_type_lock); | ||
892 | |||
893 | return registered; | ||
894 | } | ||
895 | |||
896 | const struct kobj_ns_type_operations *kobj_child_ns_ops(struct kobject *parent) | ||
897 | { | ||
898 | const struct kobj_ns_type_operations *ops = NULL; | ||
899 | |||
900 | if (parent && parent->ktype->child_ns_type) | ||
901 | ops = parent->ktype->child_ns_type(parent); | ||
902 | |||
903 | return ops; | ||
904 | } | ||
905 | |||
906 | const struct kobj_ns_type_operations *kobj_ns_ops(struct kobject *kobj) | ||
907 | { | ||
908 | return kobj_child_ns_ops(kobj->parent); | ||
909 | } | ||
910 | |||
911 | |||
912 | const void *kobj_ns_current(enum kobj_ns_type type) | ||
913 | { | ||
914 | const void *ns = NULL; | ||
915 | |||
916 | spin_lock(&kobj_ns_type_lock); | ||
917 | if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES) && | ||
918 | kobj_ns_ops_tbl[type]) | ||
919 | ns = kobj_ns_ops_tbl[type]->current_ns(); | ||
920 | spin_unlock(&kobj_ns_type_lock); | ||
921 | |||
922 | return ns; | ||
923 | } | ||
924 | |||
925 | const void *kobj_ns_netlink(enum kobj_ns_type type, struct sock *sk) | ||
926 | { | ||
927 | const void *ns = NULL; | ||
928 | |||
929 | spin_lock(&kobj_ns_type_lock); | ||
930 | if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES) && | ||
931 | kobj_ns_ops_tbl[type]) | ||
932 | ns = kobj_ns_ops_tbl[type]->netlink_ns(sk); | ||
933 | spin_unlock(&kobj_ns_type_lock); | ||
934 | |||
935 | return ns; | ||
936 | } | ||
937 | |||
938 | const void *kobj_ns_initial(enum kobj_ns_type type) | ||
939 | { | ||
940 | const void *ns = NULL; | ||
941 | |||
942 | spin_lock(&kobj_ns_type_lock); | ||
943 | if ((type > KOBJ_NS_TYPE_NONE) && (type < KOBJ_NS_TYPES) && | ||
944 | kobj_ns_ops_tbl[type]) | ||
945 | ns = kobj_ns_ops_tbl[type]->initial_ns(); | ||
946 | spin_unlock(&kobj_ns_type_lock); | ||
947 | |||
948 | return ns; | ||
949 | } | ||
950 | |||
951 | /* | ||
952 | * kobj_ns_exit - invalidate a namespace tag | ||
953 | * | ||
954 | * @type: the namespace type (i.e. KOBJ_NS_TYPE_NET) | ||
955 | * @ns: the actual namespace being invalidated | ||
956 | * | ||
957 | * This is called when a tag is no longer valid. For instance, | ||
958 | * when a network namespace exits, it uses this helper to | ||
959 | * make sure no sb's sysfs_info points to the now-invalidated | ||
960 | * netns. | ||
961 | */ | ||
962 | void kobj_ns_exit(enum kobj_ns_type type, const void *ns) | ||
963 | { | ||
964 | sysfs_exit_ns(type, ns); | ||
965 | } | ||
966 | |||
967 | |||
853 | EXPORT_SYMBOL(kobject_get); | 968 | EXPORT_SYMBOL(kobject_get); |
854 | EXPORT_SYMBOL(kobject_put); | 969 | EXPORT_SYMBOL(kobject_put); |
855 | EXPORT_SYMBOL(kobject_del); | 970 | EXPORT_SYMBOL(kobject_del); |
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c index c9d3a3e8405d..59c15511d58a 100644 --- a/lib/kobject_uevent.c +++ b/lib/kobject_uevent.c | |||
@@ -18,18 +18,25 @@ | |||
18 | #include <linux/string.h> | 18 | #include <linux/string.h> |
19 | #include <linux/kobject.h> | 19 | #include <linux/kobject.h> |
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | 21 | #include <linux/slab.h> | |
22 | #include <linux/user_namespace.h> | ||
22 | #include <linux/socket.h> | 23 | #include <linux/socket.h> |
23 | #include <linux/skbuff.h> | 24 | #include <linux/skbuff.h> |
24 | #include <linux/netlink.h> | 25 | #include <linux/netlink.h> |
25 | #include <net/sock.h> | 26 | #include <net/sock.h> |
27 | #include <net/net_namespace.h> | ||
26 | 28 | ||
27 | 29 | ||
28 | u64 uevent_seqnum; | 30 | u64 uevent_seqnum; |
29 | char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH; | 31 | char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH; |
30 | static DEFINE_SPINLOCK(sequence_lock); | 32 | static DEFINE_SPINLOCK(sequence_lock); |
31 | #if defined(CONFIG_NET) | 33 | #ifdef CONFIG_NET |
32 | static struct sock *uevent_sock; | 34 | struct uevent_sock { |
35 | struct list_head list; | ||
36 | struct sock *sk; | ||
37 | }; | ||
38 | static LIST_HEAD(uevent_sock_list); | ||
39 | static DEFINE_MUTEX(uevent_sock_mutex); | ||
33 | #endif | 40 | #endif |
34 | 41 | ||
35 | /* the strings here must match the enum in include/linux/kobject.h */ | 42 | /* the strings here must match the enum in include/linux/kobject.h */ |
@@ -76,6 +83,37 @@ out: | |||
76 | return ret; | 83 | return ret; |
77 | } | 84 | } |
78 | 85 | ||
86 | static int kobj_bcast_filter(struct sock *dsk, struct sk_buff *skb, void *data) | ||
87 | { | ||
88 | struct kobject *kobj = data; | ||
89 | const struct kobj_ns_type_operations *ops; | ||
90 | |||
91 | ops = kobj_ns_ops(kobj); | ||
92 | if (ops) { | ||
93 | const void *sock_ns, *ns; | ||
94 | ns = kobj->ktype->namespace(kobj); | ||
95 | sock_ns = ops->netlink_ns(dsk); | ||
96 | return sock_ns != ns; | ||
97 | } | ||
98 | |||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | static int kobj_usermode_filter(struct kobject *kobj) | ||
103 | { | ||
104 | const struct kobj_ns_type_operations *ops; | ||
105 | |||
106 | ops = kobj_ns_ops(kobj); | ||
107 | if (ops) { | ||
108 | const void *init_ns, *ns; | ||
109 | ns = kobj->ktype->namespace(kobj); | ||
110 | init_ns = ops->initial_ns(); | ||
111 | return ns != init_ns; | ||
112 | } | ||
113 | |||
114 | return 0; | ||
115 | } | ||
116 | |||
79 | /** | 117 | /** |
80 | * kobject_uevent_env - send an uevent with environmental data | 118 | * kobject_uevent_env - send an uevent with environmental data |
81 | * | 119 | * |
@@ -99,6 +137,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, | |||
99 | u64 seq; | 137 | u64 seq; |
100 | int i = 0; | 138 | int i = 0; |
101 | int retval = 0; | 139 | int retval = 0; |
140 | #ifdef CONFIG_NET | ||
141 | struct uevent_sock *ue_sk; | ||
142 | #endif | ||
102 | 143 | ||
103 | pr_debug("kobject: '%s' (%p): %s\n", | 144 | pr_debug("kobject: '%s' (%p): %s\n", |
104 | kobject_name(kobj), kobj, __func__); | 145 | kobject_name(kobj), kobj, __func__); |
@@ -210,7 +251,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, | |||
210 | 251 | ||
211 | #if defined(CONFIG_NET) | 252 | #if defined(CONFIG_NET) |
212 | /* send netlink message */ | 253 | /* send netlink message */ |
213 | if (uevent_sock) { | 254 | mutex_lock(&uevent_sock_mutex); |
255 | list_for_each_entry(ue_sk, &uevent_sock_list, list) { | ||
256 | struct sock *uevent_sock = ue_sk->sk; | ||
214 | struct sk_buff *skb; | 257 | struct sk_buff *skb; |
215 | size_t len; | 258 | size_t len; |
216 | 259 | ||
@@ -232,18 +275,21 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, | |||
232 | } | 275 | } |
233 | 276 | ||
234 | NETLINK_CB(skb).dst_group = 1; | 277 | NETLINK_CB(skb).dst_group = 1; |
235 | retval = netlink_broadcast(uevent_sock, skb, 0, 1, | 278 | retval = netlink_broadcast_filtered(uevent_sock, skb, |
236 | GFP_KERNEL); | 279 | 0, 1, GFP_KERNEL, |
280 | kobj_bcast_filter, | ||
281 | kobj); | ||
237 | /* ENOBUFS should be handled in userspace */ | 282 | /* ENOBUFS should be handled in userspace */ |
238 | if (retval == -ENOBUFS) | 283 | if (retval == -ENOBUFS) |
239 | retval = 0; | 284 | retval = 0; |
240 | } else | 285 | } else |
241 | retval = -ENOMEM; | 286 | retval = -ENOMEM; |
242 | } | 287 | } |
288 | mutex_unlock(&uevent_sock_mutex); | ||
243 | #endif | 289 | #endif |
244 | 290 | ||
245 | /* call uevent_helper, usually only enabled during early boot */ | 291 | /* call uevent_helper, usually only enabled during early boot */ |
246 | if (uevent_helper[0]) { | 292 | if (uevent_helper[0] && !kobj_usermode_filter(kobj)) { |
247 | char *argv [3]; | 293 | char *argv [3]; |
248 | 294 | ||
249 | argv [0] = uevent_helper; | 295 | argv [0] = uevent_helper; |
@@ -319,18 +365,58 @@ int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) | |||
319 | EXPORT_SYMBOL_GPL(add_uevent_var); | 365 | EXPORT_SYMBOL_GPL(add_uevent_var); |
320 | 366 | ||
321 | #if defined(CONFIG_NET) | 367 | #if defined(CONFIG_NET) |
322 | static int __init kobject_uevent_init(void) | 368 | static int uevent_net_init(struct net *net) |
323 | { | 369 | { |
324 | uevent_sock = netlink_kernel_create(&init_net, NETLINK_KOBJECT_UEVENT, | 370 | struct uevent_sock *ue_sk; |
325 | 1, NULL, NULL, THIS_MODULE); | 371 | |
326 | if (!uevent_sock) { | 372 | ue_sk = kzalloc(sizeof(*ue_sk), GFP_KERNEL); |
373 | if (!ue_sk) | ||
374 | return -ENOMEM; | ||
375 | |||
376 | ue_sk->sk = netlink_kernel_create(net, NETLINK_KOBJECT_UEVENT, | ||
377 | 1, NULL, NULL, THIS_MODULE); | ||
378 | if (!ue_sk->sk) { | ||
327 | printk(KERN_ERR | 379 | printk(KERN_ERR |
328 | "kobject_uevent: unable to create netlink socket!\n"); | 380 | "kobject_uevent: unable to create netlink socket!\n"); |
329 | return -ENODEV; | 381 | return -ENODEV; |
330 | } | 382 | } |
331 | netlink_set_nonroot(NETLINK_KOBJECT_UEVENT, NL_NONROOT_RECV); | 383 | mutex_lock(&uevent_sock_mutex); |
384 | list_add_tail(&ue_sk->list, &uevent_sock_list); | ||
385 | mutex_unlock(&uevent_sock_mutex); | ||
332 | return 0; | 386 | return 0; |
333 | } | 387 | } |
334 | 388 | ||
389 | static void uevent_net_exit(struct net *net) | ||
390 | { | ||
391 | struct uevent_sock *ue_sk; | ||
392 | |||
393 | mutex_lock(&uevent_sock_mutex); | ||
394 | list_for_each_entry(ue_sk, &uevent_sock_list, list) { | ||
395 | if (sock_net(ue_sk->sk) == net) | ||
396 | goto found; | ||
397 | } | ||
398 | mutex_unlock(&uevent_sock_mutex); | ||
399 | return; | ||
400 | |||
401 | found: | ||
402 | list_del(&ue_sk->list); | ||
403 | mutex_unlock(&uevent_sock_mutex); | ||
404 | |||
405 | netlink_kernel_release(ue_sk->sk); | ||
406 | kfree(ue_sk); | ||
407 | } | ||
408 | |||
409 | static struct pernet_operations uevent_net_ops = { | ||
410 | .init = uevent_net_init, | ||
411 | .exit = uevent_net_exit, | ||
412 | }; | ||
413 | |||
414 | static int __init kobject_uevent_init(void) | ||
415 | { | ||
416 | netlink_set_nonroot(NETLINK_KOBJECT_UEVENT, NL_NONROOT_RECV); | ||
417 | return register_pernet_subsys(&uevent_net_ops); | ||
418 | } | ||
419 | |||
420 | |||
335 | postcore_initcall(kobject_uevent_init); | 421 | postcore_initcall(kobject_uevent_init); |
336 | #endif | 422 | #endif |
diff --git a/lib/kref.c b/lib/kref.c index 9ecd6e865610..d3d227a08a4b 100644 --- a/lib/kref.c +++ b/lib/kref.c | |||
@@ -13,17 +13,7 @@ | |||
13 | 13 | ||
14 | #include <linux/kref.h> | 14 | #include <linux/kref.h> |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | 16 | #include <linux/slab.h> | |
17 | /** | ||
18 | * kref_set - initialize object and set refcount to requested number. | ||
19 | * @kref: object in question. | ||
20 | * @num: initial reference counter | ||
21 | */ | ||
22 | void kref_set(struct kref *kref, int num) | ||
23 | { | ||
24 | atomic_set(&kref->refcount, num); | ||
25 | smp_mb(); | ||
26 | } | ||
27 | 17 | ||
28 | /** | 18 | /** |
29 | * kref_init - initialize object. | 19 | * kref_init - initialize object. |
@@ -31,7 +21,8 @@ void kref_set(struct kref *kref, int num) | |||
31 | */ | 21 | */ |
32 | void kref_init(struct kref *kref) | 22 | void kref_init(struct kref *kref) |
33 | { | 23 | { |
34 | kref_set(kref, 1); | 24 | atomic_set(&kref->refcount, 1); |
25 | smp_mb(); | ||
35 | } | 26 | } |
36 | 27 | ||
37 | /** | 28 | /** |
@@ -71,7 +62,6 @@ int kref_put(struct kref *kref, void (*release)(struct kref *kref)) | |||
71 | return 0; | 62 | return 0; |
72 | } | 63 | } |
73 | 64 | ||
74 | EXPORT_SYMBOL(kref_set); | ||
75 | EXPORT_SYMBOL(kref_init); | 65 | EXPORT_SYMBOL(kref_init); |
76 | EXPORT_SYMBOL(kref_get); | 66 | EXPORT_SYMBOL(kref_get); |
77 | EXPORT_SYMBOL(kref_put); | 67 | EXPORT_SYMBOL(kref_put); |
diff --git a/lib/lcm.c b/lib/lcm.c new file mode 100644 index 000000000000..157cd88a6ffc --- /dev/null +++ b/lib/lcm.c | |||
@@ -0,0 +1,15 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/gcd.h> | ||
3 | #include <linux/module.h> | ||
4 | |||
5 | /* Lowest common multiple */ | ||
6 | unsigned long lcm(unsigned long a, unsigned long b) | ||
7 | { | ||
8 | if (a && b) | ||
9 | return (a * b) / gcd(a, b); | ||
10 | else if (b) | ||
11 | return b; | ||
12 | |||
13 | return a; | ||
14 | } | ||
15 | EXPORT_SYMBOL_GPL(lcm); | ||
diff --git a/lib/radix-tree.c b/lib/radix-tree.c index 6b9670d6bbf9..05da38bcc298 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
29 | #include <linux/notifier.h> | 29 | #include <linux/notifier.h> |
30 | #include <linux/cpu.h> | 30 | #include <linux/cpu.h> |
31 | #include <linux/gfp.h> | ||
32 | #include <linux/string.h> | 31 | #include <linux/string.h> |
33 | #include <linux/bitops.h> | 32 | #include <linux/bitops.h> |
34 | #include <linux/rcupdate.h> | 33 | #include <linux/rcupdate.h> |
@@ -556,6 +555,10 @@ EXPORT_SYMBOL(radix_tree_tag_clear); | |||
556 | * | 555 | * |
557 | * 0: tag not present or not set | 556 | * 0: tag not present or not set |
558 | * 1: tag set | 557 | * 1: tag set |
558 | * | ||
559 | * Note that the return value of this function may not be relied on, even if | ||
560 | * the RCU lock is held, unless tag modification and node deletion are excluded | ||
561 | * from concurrency. | ||
559 | */ | 562 | */ |
560 | int radix_tree_tag_get(struct radix_tree_root *root, | 563 | int radix_tree_tag_get(struct radix_tree_root *root, |
561 | unsigned long index, unsigned int tag) | 564 | unsigned long index, unsigned int tag) |
@@ -596,12 +599,8 @@ int radix_tree_tag_get(struct radix_tree_root *root, | |||
596 | */ | 599 | */ |
597 | if (!tag_get(node, tag, offset)) | 600 | if (!tag_get(node, tag, offset)) |
598 | saw_unset_tag = 1; | 601 | saw_unset_tag = 1; |
599 | if (height == 1) { | 602 | if (height == 1) |
600 | int ret = tag_get(node, tag, offset); | 603 | return !!tag_get(node, tag, offset); |
601 | |||
602 | BUG_ON(ret && saw_unset_tag); | ||
603 | return !!ret; | ||
604 | } | ||
605 | node = rcu_dereference_raw(node->slots[offset]); | 604 | node = rcu_dereference_raw(node->slots[offset]); |
606 | shift -= RADIX_TREE_MAP_SHIFT; | 605 | shift -= RADIX_TREE_MAP_SHIFT; |
607 | height--; | 606 | height--; |
@@ -657,7 +656,7 @@ EXPORT_SYMBOL(radix_tree_next_hole); | |||
657 | * | 656 | * |
658 | * Returns: the index of the hole if found, otherwise returns an index | 657 | * Returns: the index of the hole if found, otherwise returns an index |
659 | * outside of the set specified (in which case 'index - return >= max_scan' | 658 | * outside of the set specified (in which case 'index - return >= max_scan' |
660 | * will be true). In rare cases of wrap-around, LONG_MAX will be returned. | 659 | * will be true). In rare cases of wrap-around, ULONG_MAX will be returned. |
661 | * | 660 | * |
662 | * radix_tree_next_hole may be called under rcu_read_lock. However, like | 661 | * radix_tree_next_hole may be called under rcu_read_lock. However, like |
663 | * radix_tree_gang_lookup, this will not atomically search a snapshot of | 662 | * radix_tree_gang_lookup, this will not atomically search a snapshot of |
@@ -675,7 +674,7 @@ unsigned long radix_tree_prev_hole(struct radix_tree_root *root, | |||
675 | if (!radix_tree_lookup(root, index)) | 674 | if (!radix_tree_lookup(root, index)) |
676 | break; | 675 | break; |
677 | index--; | 676 | index--; |
678 | if (index == LONG_MAX) | 677 | if (index == ULONG_MAX) |
679 | break; | 678 | break; |
680 | } | 679 | } |
681 | 680 | ||
diff --git a/lib/random32.c b/lib/random32.c index 217d5c4b666d..870dc3fc0f0f 100644 --- a/lib/random32.c +++ b/lib/random32.c | |||
@@ -39,13 +39,16 @@ | |||
39 | #include <linux/jiffies.h> | 39 | #include <linux/jiffies.h> |
40 | #include <linux/random.h> | 40 | #include <linux/random.h> |
41 | 41 | ||
42 | struct rnd_state { | ||
43 | u32 s1, s2, s3; | ||
44 | }; | ||
45 | |||
46 | static DEFINE_PER_CPU(struct rnd_state, net_rand_state); | 42 | static DEFINE_PER_CPU(struct rnd_state, net_rand_state); |
47 | 43 | ||
48 | static u32 __random32(struct rnd_state *state) | 44 | /** |
45 | * prandom32 - seeded pseudo-random number generator. | ||
46 | * @state: pointer to state structure holding seeded state. | ||
47 | * | ||
48 | * This is used for pseudo-randomness with no outside seeding. | ||
49 | * For more random results, use random32(). | ||
50 | */ | ||
51 | u32 prandom32(struct rnd_state *state) | ||
49 | { | 52 | { |
50 | #define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b) | 53 | #define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b) |
51 | 54 | ||
@@ -55,14 +58,7 @@ static u32 __random32(struct rnd_state *state) | |||
55 | 58 | ||
56 | return (state->s1 ^ state->s2 ^ state->s3); | 59 | return (state->s1 ^ state->s2 ^ state->s3); |
57 | } | 60 | } |
58 | 61 | EXPORT_SYMBOL(prandom32); | |
59 | /* | ||
60 | * Handle minimum values for seeds | ||
61 | */ | ||
62 | static inline u32 __seed(u32 x, u32 m) | ||
63 | { | ||
64 | return (x < m) ? x + m : x; | ||
65 | } | ||
66 | 62 | ||
67 | /** | 63 | /** |
68 | * random32 - pseudo random number generator | 64 | * random32 - pseudo random number generator |
@@ -75,7 +71,7 @@ u32 random32(void) | |||
75 | { | 71 | { |
76 | unsigned long r; | 72 | unsigned long r; |
77 | struct rnd_state *state = &get_cpu_var(net_rand_state); | 73 | struct rnd_state *state = &get_cpu_var(net_rand_state); |
78 | r = __random32(state); | 74 | r = prandom32(state); |
79 | put_cpu_var(state); | 75 | put_cpu_var(state); |
80 | return r; | 76 | return r; |
81 | } | 77 | } |
@@ -118,12 +114,12 @@ static int __init random32_init(void) | |||
118 | state->s3 = __seed(LCG(state->s2), 15); | 114 | state->s3 = __seed(LCG(state->s2), 15); |
119 | 115 | ||
120 | /* "warm it up" */ | 116 | /* "warm it up" */ |
121 | __random32(state); | 117 | prandom32(state); |
122 | __random32(state); | 118 | prandom32(state); |
123 | __random32(state); | 119 | prandom32(state); |
124 | __random32(state); | 120 | prandom32(state); |
125 | __random32(state); | 121 | prandom32(state); |
126 | __random32(state); | 122 | prandom32(state); |
127 | } | 123 | } |
128 | return 0; | 124 | return 0; |
129 | } | 125 | } |
@@ -147,7 +143,7 @@ static int __init random32_reseed(void) | |||
147 | state->s3 = __seed(seeds[2], 15); | 143 | state->s3 = __seed(seeds[2], 15); |
148 | 144 | ||
149 | /* mix it in */ | 145 | /* mix it in */ |
150 | __random32(state); | 146 | prandom32(state); |
151 | } | 147 | } |
152 | return 0; | 148 | return 0; |
153 | } | 149 | } |
diff --git a/lib/ratelimit.c b/lib/ratelimit.c index 09f5ce1810dc..027a03f4c56d 100644 --- a/lib/ratelimit.c +++ b/lib/ratelimit.c | |||
@@ -16,9 +16,14 @@ | |||
16 | /* | 16 | /* |
17 | * __ratelimit - rate limiting | 17 | * __ratelimit - rate limiting |
18 | * @rs: ratelimit_state data | 18 | * @rs: ratelimit_state data |
19 | * @func: name of calling function | ||
19 | * | 20 | * |
20 | * This enforces a rate limit: not more than @rs->ratelimit_burst callbacks | 21 | * This enforces a rate limit: not more than @rs->burst callbacks |
21 | * in every @rs->ratelimit_jiffies | 22 | * in every @rs->interval |
23 | * | ||
24 | * RETURNS: | ||
25 | * 0 means callbacks will be suppressed. | ||
26 | * 1 means go ahead and do it. | ||
22 | */ | 27 | */ |
23 | int ___ratelimit(struct ratelimit_state *rs, const char *func) | 28 | int ___ratelimit(struct ratelimit_state *rs, const char *func) |
24 | { | 29 | { |
@@ -35,7 +40,7 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func) | |||
35 | * the entity that is holding the lock already: | 40 | * the entity that is holding the lock already: |
36 | */ | 41 | */ |
37 | if (!spin_trylock_irqsave(&rs->lock, flags)) | 42 | if (!spin_trylock_irqsave(&rs->lock, flags)) |
38 | return 1; | 43 | return 0; |
39 | 44 | ||
40 | if (!rs->begin) | 45 | if (!rs->begin) |
41 | rs->begin = jiffies; | 46 | rs->begin = jiffies; |
diff --git a/lib/rbtree.c b/lib/rbtree.c index e2aa3be29858..15e10b1afdd2 100644 --- a/lib/rbtree.c +++ b/lib/rbtree.c | |||
@@ -44,6 +44,11 @@ static void __rb_rotate_left(struct rb_node *node, struct rb_root *root) | |||
44 | else | 44 | else |
45 | root->rb_node = right; | 45 | root->rb_node = right; |
46 | rb_set_parent(node, right); | 46 | rb_set_parent(node, right); |
47 | |||
48 | if (root->augment_cb) { | ||
49 | root->augment_cb(node); | ||
50 | root->augment_cb(right); | ||
51 | } | ||
47 | } | 52 | } |
48 | 53 | ||
49 | static void __rb_rotate_right(struct rb_node *node, struct rb_root *root) | 54 | static void __rb_rotate_right(struct rb_node *node, struct rb_root *root) |
@@ -67,12 +72,20 @@ static void __rb_rotate_right(struct rb_node *node, struct rb_root *root) | |||
67 | else | 72 | else |
68 | root->rb_node = left; | 73 | root->rb_node = left; |
69 | rb_set_parent(node, left); | 74 | rb_set_parent(node, left); |
75 | |||
76 | if (root->augment_cb) { | ||
77 | root->augment_cb(node); | ||
78 | root->augment_cb(left); | ||
79 | } | ||
70 | } | 80 | } |
71 | 81 | ||
72 | void rb_insert_color(struct rb_node *node, struct rb_root *root) | 82 | void rb_insert_color(struct rb_node *node, struct rb_root *root) |
73 | { | 83 | { |
74 | struct rb_node *parent, *gparent; | 84 | struct rb_node *parent, *gparent; |
75 | 85 | ||
86 | if (root->augment_cb) | ||
87 | root->augment_cb(node); | ||
88 | |||
76 | while ((parent = rb_parent(node)) && rb_is_red(parent)) | 89 | while ((parent = rb_parent(node)) && rb_is_red(parent)) |
77 | { | 90 | { |
78 | gparent = rb_parent(parent); | 91 | gparent = rb_parent(parent); |
@@ -227,12 +240,15 @@ void rb_erase(struct rb_node *node, struct rb_root *root) | |||
227 | else | 240 | else |
228 | { | 241 | { |
229 | struct rb_node *old = node, *left; | 242 | struct rb_node *old = node, *left; |
243 | int old_parent_cb = 0; | ||
244 | int successor_parent_cb = 0; | ||
230 | 245 | ||
231 | node = node->rb_right; | 246 | node = node->rb_right; |
232 | while ((left = node->rb_left) != NULL) | 247 | while ((left = node->rb_left) != NULL) |
233 | node = left; | 248 | node = left; |
234 | 249 | ||
235 | if (rb_parent(old)) { | 250 | if (rb_parent(old)) { |
251 | old_parent_cb = 1; | ||
236 | if (rb_parent(old)->rb_left == old) | 252 | if (rb_parent(old)->rb_left == old) |
237 | rb_parent(old)->rb_left = node; | 253 | rb_parent(old)->rb_left = node; |
238 | else | 254 | else |
@@ -247,8 +263,10 @@ void rb_erase(struct rb_node *node, struct rb_root *root) | |||
247 | if (parent == old) { | 263 | if (parent == old) { |
248 | parent = node; | 264 | parent = node; |
249 | } else { | 265 | } else { |
266 | successor_parent_cb = 1; | ||
250 | if (child) | 267 | if (child) |
251 | rb_set_parent(child, parent); | 268 | rb_set_parent(child, parent); |
269 | |||
252 | parent->rb_left = child; | 270 | parent->rb_left = child; |
253 | 271 | ||
254 | node->rb_right = old->rb_right; | 272 | node->rb_right = old->rb_right; |
@@ -259,6 +277,24 @@ void rb_erase(struct rb_node *node, struct rb_root *root) | |||
259 | node->rb_left = old->rb_left; | 277 | node->rb_left = old->rb_left; |
260 | rb_set_parent(old->rb_left, node); | 278 | rb_set_parent(old->rb_left, node); |
261 | 279 | ||
280 | if (root->augment_cb) { | ||
281 | /* | ||
282 | * Here, three different nodes can have new children. | ||
283 | * The parent of the successor node that was selected | ||
284 | * to replace the node to be erased. | ||
285 | * The node that is getting erased and is now replaced | ||
286 | * by its successor. | ||
287 | * The parent of the node getting erased-replaced. | ||
288 | */ | ||
289 | if (successor_parent_cb) | ||
290 | root->augment_cb(parent); | ||
291 | |||
292 | root->augment_cb(node); | ||
293 | |||
294 | if (old_parent_cb) | ||
295 | root->augment_cb(rb_parent(old)); | ||
296 | } | ||
297 | |||
262 | goto color; | 298 | goto color; |
263 | } | 299 | } |
264 | 300 | ||
@@ -267,15 +303,19 @@ void rb_erase(struct rb_node *node, struct rb_root *root) | |||
267 | 303 | ||
268 | if (child) | 304 | if (child) |
269 | rb_set_parent(child, parent); | 305 | rb_set_parent(child, parent); |
270 | if (parent) | 306 | |
271 | { | 307 | if (parent) { |
272 | if (parent->rb_left == node) | 308 | if (parent->rb_left == node) |
273 | parent->rb_left = child; | 309 | parent->rb_left = child; |
274 | else | 310 | else |
275 | parent->rb_right = child; | 311 | parent->rb_right = child; |
276 | } | 312 | |
277 | else | 313 | if (root->augment_cb) |
314 | root->augment_cb(parent); | ||
315 | |||
316 | } else { | ||
278 | root->rb_node = child; | 317 | root->rb_node = child; |
318 | } | ||
279 | 319 | ||
280 | color: | 320 | color: |
281 | if (color == RB_BLACK) | 321 | if (color == RB_BLACK) |
diff --git a/lib/rwsem-spinlock.c b/lib/rwsem-spinlock.c index ccf95bff7984..ffc9fc7f3b05 100644 --- a/lib/rwsem-spinlock.c +++ b/lib/rwsem-spinlock.c | |||
@@ -143,13 +143,14 @@ void __sched __down_read(struct rw_semaphore *sem) | |||
143 | { | 143 | { |
144 | struct rwsem_waiter waiter; | 144 | struct rwsem_waiter waiter; |
145 | struct task_struct *tsk; | 145 | struct task_struct *tsk; |
146 | unsigned long flags; | ||
146 | 147 | ||
147 | spin_lock_irq(&sem->wait_lock); | 148 | spin_lock_irqsave(&sem->wait_lock, flags); |
148 | 149 | ||
149 | if (sem->activity >= 0 && list_empty(&sem->wait_list)) { | 150 | if (sem->activity >= 0 && list_empty(&sem->wait_list)) { |
150 | /* granted */ | 151 | /* granted */ |
151 | sem->activity++; | 152 | sem->activity++; |
152 | spin_unlock_irq(&sem->wait_lock); | 153 | spin_unlock_irqrestore(&sem->wait_lock, flags); |
153 | goto out; | 154 | goto out; |
154 | } | 155 | } |
155 | 156 | ||
@@ -164,7 +165,7 @@ void __sched __down_read(struct rw_semaphore *sem) | |||
164 | list_add_tail(&waiter.list, &sem->wait_list); | 165 | list_add_tail(&waiter.list, &sem->wait_list); |
165 | 166 | ||
166 | /* we don't need to touch the semaphore struct anymore */ | 167 | /* we don't need to touch the semaphore struct anymore */ |
167 | spin_unlock_irq(&sem->wait_lock); | 168 | spin_unlock_irqrestore(&sem->wait_lock, flags); |
168 | 169 | ||
169 | /* wait to be given the lock */ | 170 | /* wait to be given the lock */ |
170 | for (;;) { | 171 | for (;;) { |
@@ -209,13 +210,14 @@ void __sched __down_write_nested(struct rw_semaphore *sem, int subclass) | |||
209 | { | 210 | { |
210 | struct rwsem_waiter waiter; | 211 | struct rwsem_waiter waiter; |
211 | struct task_struct *tsk; | 212 | struct task_struct *tsk; |
213 | unsigned long flags; | ||
212 | 214 | ||
213 | spin_lock_irq(&sem->wait_lock); | 215 | spin_lock_irqsave(&sem->wait_lock, flags); |
214 | 216 | ||
215 | if (sem->activity == 0 && list_empty(&sem->wait_list)) { | 217 | if (sem->activity == 0 && list_empty(&sem->wait_list)) { |
216 | /* granted */ | 218 | /* granted */ |
217 | sem->activity = -1; | 219 | sem->activity = -1; |
218 | spin_unlock_irq(&sem->wait_lock); | 220 | spin_unlock_irqrestore(&sem->wait_lock, flags); |
219 | goto out; | 221 | goto out; |
220 | } | 222 | } |
221 | 223 | ||
@@ -230,7 +232,7 @@ void __sched __down_write_nested(struct rw_semaphore *sem, int subclass) | |||
230 | list_add_tail(&waiter.list, &sem->wait_list); | 232 | list_add_tail(&waiter.list, &sem->wait_list); |
231 | 233 | ||
232 | /* we don't need to touch the semaphore struct anymore */ | 234 | /* we don't need to touch the semaphore struct anymore */ |
233 | spin_unlock_irq(&sem->wait_lock); | 235 | spin_unlock_irqrestore(&sem->wait_lock, flags); |
234 | 236 | ||
235 | /* wait to be given the lock */ | 237 | /* wait to be given the lock */ |
236 | for (;;) { | 238 | for (;;) { |
diff --git a/lib/rwsem.c b/lib/rwsem.c index 3e3365e5665e..ceba8e28807a 100644 --- a/lib/rwsem.c +++ b/lib/rwsem.c | |||
@@ -136,9 +136,10 @@ __rwsem_do_wake(struct rw_semaphore *sem, int downgrading) | |||
136 | out: | 136 | out: |
137 | return sem; | 137 | return sem; |
138 | 138 | ||
139 | /* undo the change to count, but check for a transition 1->0 */ | 139 | /* undo the change to the active count, but check for a transition |
140 | * 1->0 */ | ||
140 | undo: | 141 | undo: |
141 | if (rwsem_atomic_update(-RWSEM_ACTIVE_BIAS, sem) != 0) | 142 | if (rwsem_atomic_update(-RWSEM_ACTIVE_BIAS, sem) & RWSEM_ACTIVE_MASK) |
142 | goto out; | 143 | goto out; |
143 | goto try_again; | 144 | goto try_again; |
144 | } | 145 | } |
diff --git a/lib/scatterlist.c b/lib/scatterlist.c index 0d475d8167bf..9afa25b52a83 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c | |||
@@ -7,6 +7,7 @@ | |||
7 | * Version 2. See the file COPYING for more details. | 7 | * Version 2. See the file COPYING for more details. |
8 | */ | 8 | */ |
9 | #include <linux/module.h> | 9 | #include <linux/module.h> |
10 | #include <linux/slab.h> | ||
10 | #include <linux/scatterlist.h> | 11 | #include <linux/scatterlist.h> |
11 | #include <linux/highmem.h> | 12 | #include <linux/highmem.h> |
12 | 13 | ||
diff --git a/lib/swiotlb.c b/lib/swiotlb.c index 437eedb5a53b..a009055140ec 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/types.h> | 28 | #include <linux/types.h> |
29 | #include <linux/ctype.h> | 29 | #include <linux/ctype.h> |
30 | #include <linux/highmem.h> | 30 | #include <linux/highmem.h> |
31 | #include <linux/gfp.h> | ||
31 | 32 | ||
32 | #include <asm/io.h> | 33 | #include <asm/io.h> |
33 | #include <asm/dma.h> | 34 | #include <asm/dma.h> |
@@ -756,37 +757,6 @@ swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, | |||
756 | EXPORT_SYMBOL(swiotlb_sync_single_for_device); | 757 | EXPORT_SYMBOL(swiotlb_sync_single_for_device); |
757 | 758 | ||
758 | /* | 759 | /* |
759 | * Same as above, but for a sub-range of the mapping. | ||
760 | */ | ||
761 | static void | ||
762 | swiotlb_sync_single_range(struct device *hwdev, dma_addr_t dev_addr, | ||
763 | unsigned long offset, size_t size, | ||
764 | int dir, int target) | ||
765 | { | ||
766 | swiotlb_sync_single(hwdev, dev_addr + offset, size, dir, target); | ||
767 | } | ||
768 | |||
769 | void | ||
770 | swiotlb_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dev_addr, | ||
771 | unsigned long offset, size_t size, | ||
772 | enum dma_data_direction dir) | ||
773 | { | ||
774 | swiotlb_sync_single_range(hwdev, dev_addr, offset, size, dir, | ||
775 | SYNC_FOR_CPU); | ||
776 | } | ||
777 | EXPORT_SYMBOL_GPL(swiotlb_sync_single_range_for_cpu); | ||
778 | |||
779 | void | ||
780 | swiotlb_sync_single_range_for_device(struct device *hwdev, dma_addr_t dev_addr, | ||
781 | unsigned long offset, size_t size, | ||
782 | enum dma_data_direction dir) | ||
783 | { | ||
784 | swiotlb_sync_single_range(hwdev, dev_addr, offset, size, dir, | ||
785 | SYNC_FOR_DEVICE); | ||
786 | } | ||
787 | EXPORT_SYMBOL_GPL(swiotlb_sync_single_range_for_device); | ||
788 | |||
789 | /* | ||
790 | * Map a set of buffers described by scatterlist in streaming mode for DMA. | 760 | * Map a set of buffers described by scatterlist in streaming mode for DMA. |
791 | * This is the scatter-gather version of the above swiotlb_map_page | 761 | * This is the scatter-gather version of the above swiotlb_map_page |
792 | * interface. Here the scatter gather list elements are each tagged with the | 762 | * interface. Here the scatter gather list elements are each tagged with the |
diff --git a/lib/textsearch.c b/lib/textsearch.c index 9fbcb44c554f..d608331b3e47 100644 --- a/lib/textsearch.c +++ b/lib/textsearch.c | |||
@@ -103,6 +103,7 @@ | |||
103 | #include <linux/rcupdate.h> | 103 | #include <linux/rcupdate.h> |
104 | #include <linux/err.h> | 104 | #include <linux/err.h> |
105 | #include <linux/textsearch.h> | 105 | #include <linux/textsearch.h> |
106 | #include <linux/slab.h> | ||
106 | 107 | ||
107 | static LIST_HEAD(ts_ops); | 108 | static LIST_HEAD(ts_ops); |
108 | static DEFINE_SPINLOCK(ts_mod_lock); | 109 | static DEFINE_SPINLOCK(ts_mod_lock); |
diff --git a/lib/uuid.c b/lib/uuid.c new file mode 100644 index 000000000000..8fadd7cef46c --- /dev/null +++ b/lib/uuid.c | |||
@@ -0,0 +1,53 @@ | |||
1 | /* | ||
2 | * Unified UUID/GUID definition | ||
3 | * | ||
4 | * Copyright (C) 2009, Intel Corp. | ||
5 | * Huang Ying <ying.huang@intel.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License version | ||
9 | * 2 as published by the Free Software Foundation; | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | */ | ||
20 | |||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/uuid.h> | ||
24 | #include <linux/random.h> | ||
25 | |||
26 | static void __uuid_gen_common(__u8 b[16]) | ||
27 | { | ||
28 | int i; | ||
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 */ | ||
36 | b[8] = (b[8] & 0x3F) | 0x80; | ||
37 | } | ||
38 | |||
39 | void uuid_le_gen(uuid_le *lu) | ||
40 | { | ||
41 | __uuid_gen_common(lu->b); | ||
42 | /* version 4 : random generation */ | ||
43 | lu->b[7] = (lu->b[7] & 0x0F) | 0x40; | ||
44 | } | ||
45 | EXPORT_SYMBOL_GPL(uuid_le_gen); | ||
46 | |||
47 | void uuid_be_gen(uuid_be *bu) | ||
48 | { | ||
49 | __uuid_gen_common(bu->b); | ||
50 | /* version 4 : random generation */ | ||
51 | bu->b[6] = (bu->b[6] & 0x0F) | 0x40; | ||
52 | } | ||
53 | EXPORT_SYMBOL_GPL(uuid_be_gen); | ||
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 24112e5a5780..b8a2f549ab0e 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -118,6 +118,7 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base) | |||
118 | 118 | ||
119 | return simple_strtoull(cp, endp, base); | 119 | return simple_strtoull(cp, endp, base); |
120 | } | 120 | } |
121 | EXPORT_SYMBOL(simple_strtoll); | ||
121 | 122 | ||
122 | /** | 123 | /** |
123 | * strict_strtoul - convert a string to an unsigned long strictly | 124 | * strict_strtoul - convert a string to an unsigned long strictly |
@@ -266,7 +267,8 @@ int strict_strtoll(const char *cp, unsigned int base, long long *res) | |||
266 | } | 267 | } |
267 | EXPORT_SYMBOL(strict_strtoll); | 268 | EXPORT_SYMBOL(strict_strtoll); |
268 | 269 | ||
269 | static int skip_atoi(const char **s) | 270 | static noinline_for_stack |
271 | int skip_atoi(const char **s) | ||
270 | { | 272 | { |
271 | int i = 0; | 273 | int i = 0; |
272 | 274 | ||
@@ -286,7 +288,8 @@ static int skip_atoi(const char **s) | |||
286 | /* Formats correctly any integer in [0,99999]. | 288 | /* Formats correctly any integer in [0,99999]. |
287 | * Outputs from one to five digits depending on input. | 289 | * Outputs from one to five digits depending on input. |
288 | * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ | 290 | * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ |
289 | static char *put_dec_trunc(char *buf, unsigned q) | 291 | static noinline_for_stack |
292 | char *put_dec_trunc(char *buf, unsigned q) | ||
290 | { | 293 | { |
291 | unsigned d3, d2, d1, d0; | 294 | unsigned d3, d2, d1, d0; |
292 | d1 = (q>>4) & 0xf; | 295 | d1 = (q>>4) & 0xf; |
@@ -323,7 +326,8 @@ static char *put_dec_trunc(char *buf, unsigned q) | |||
323 | return buf; | 326 | return buf; |
324 | } | 327 | } |
325 | /* Same with if's removed. Always emits five digits */ | 328 | /* Same with if's removed. Always emits five digits */ |
326 | static char *put_dec_full(char *buf, unsigned q) | 329 | static noinline_for_stack |
330 | char *put_dec_full(char *buf, unsigned q) | ||
327 | { | 331 | { |
328 | /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ | 332 | /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ |
329 | /* but anyway, gcc produces better code with full-sized ints */ | 333 | /* but anyway, gcc produces better code with full-sized ints */ |
@@ -365,7 +369,8 @@ static char *put_dec_full(char *buf, unsigned q) | |||
365 | return buf; | 369 | return buf; |
366 | } | 370 | } |
367 | /* No inlining helps gcc to use registers better */ | 371 | /* No inlining helps gcc to use registers better */ |
368 | static noinline char *put_dec(char *buf, unsigned long long num) | 372 | static noinline_for_stack |
373 | char *put_dec(char *buf, unsigned long long num) | ||
369 | { | 374 | { |
370 | while (1) { | 375 | while (1) { |
371 | unsigned rem; | 376 | unsigned rem; |
@@ -408,16 +413,17 @@ enum format_type { | |||
408 | }; | 413 | }; |
409 | 414 | ||
410 | struct printf_spec { | 415 | struct printf_spec { |
411 | u16 type; | 416 | u8 type; /* format_type enum */ |
412 | s16 field_width; /* width of output field */ | ||
413 | u8 flags; /* flags to number() */ | 417 | u8 flags; /* flags to number() */ |
414 | u8 base; | 418 | u8 base; /* number base, 8, 10 or 16 only */ |
415 | s8 precision; /* # of digits/chars */ | 419 | u8 qualifier; /* number qualifier, one of 'hHlLtzZ' */ |
416 | u8 qualifier; | 420 | s16 field_width; /* width of output field */ |
421 | s16 precision; /* # of digits/chars */ | ||
417 | }; | 422 | }; |
418 | 423 | ||
419 | static char *number(char *buf, char *end, unsigned long long num, | 424 | static noinline_for_stack |
420 | struct printf_spec spec) | 425 | char *number(char *buf, char *end, unsigned long long num, |
426 | struct printf_spec spec) | ||
421 | { | 427 | { |
422 | /* we are called with base 8, 10 or 16, only, thus don't need "G..." */ | 428 | /* we are called with base 8, 10 or 16, only, thus don't need "G..." */ |
423 | static const char digits[16] = "0123456789ABCDEF"; /* "GHIJKLMNOPQRSTUVWXYZ"; */ | 429 | static const char digits[16] = "0123456789ABCDEF"; /* "GHIJKLMNOPQRSTUVWXYZ"; */ |
@@ -536,7 +542,8 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
536 | return buf; | 542 | return buf; |
537 | } | 543 | } |
538 | 544 | ||
539 | static char *string(char *buf, char *end, const char *s, struct printf_spec spec) | 545 | static noinline_for_stack |
546 | char *string(char *buf, char *end, const char *s, struct printf_spec spec) | ||
540 | { | 547 | { |
541 | int len, i; | 548 | int len, i; |
542 | 549 | ||
@@ -566,8 +573,9 @@ static char *string(char *buf, char *end, const char *s, struct printf_spec spec | |||
566 | return buf; | 573 | return buf; |
567 | } | 574 | } |
568 | 575 | ||
569 | static char *symbol_string(char *buf, char *end, void *ptr, | 576 | static noinline_for_stack |
570 | struct printf_spec spec, char ext) | 577 | char *symbol_string(char *buf, char *end, void *ptr, |
578 | struct printf_spec spec, char ext) | ||
571 | { | 579 | { |
572 | unsigned long value = (unsigned long) ptr; | 580 | unsigned long value = (unsigned long) ptr; |
573 | #ifdef CONFIG_KALLSYMS | 581 | #ifdef CONFIG_KALLSYMS |
@@ -587,8 +595,9 @@ static char *symbol_string(char *buf, char *end, void *ptr, | |||
587 | #endif | 595 | #endif |
588 | } | 596 | } |
589 | 597 | ||
590 | static char *resource_string(char *buf, char *end, struct resource *res, | 598 | static noinline_for_stack |
591 | struct printf_spec spec, const char *fmt) | 599 | char *resource_string(char *buf, char *end, struct resource *res, |
600 | struct printf_spec spec, const char *fmt) | ||
592 | { | 601 | { |
593 | #ifndef IO_RSRC_PRINTK_SIZE | 602 | #ifndef IO_RSRC_PRINTK_SIZE |
594 | #define IO_RSRC_PRINTK_SIZE 6 | 603 | #define IO_RSRC_PRINTK_SIZE 6 |
@@ -689,8 +698,9 @@ static char *resource_string(char *buf, char *end, struct resource *res, | |||
689 | return string(buf, end, sym, spec); | 698 | return string(buf, end, sym, spec); |
690 | } | 699 | } |
691 | 700 | ||
692 | static char *mac_address_string(char *buf, char *end, u8 *addr, | 701 | static noinline_for_stack |
693 | struct printf_spec spec, const char *fmt) | 702 | char *mac_address_string(char *buf, char *end, u8 *addr, |
703 | struct printf_spec spec, const char *fmt) | ||
694 | { | 704 | { |
695 | char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")]; | 705 | char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")]; |
696 | char *p = mac_addr; | 706 | char *p = mac_addr; |
@@ -713,7 +723,8 @@ static char *mac_address_string(char *buf, char *end, u8 *addr, | |||
713 | return string(buf, end, mac_addr, spec); | 723 | return string(buf, end, mac_addr, spec); |
714 | } | 724 | } |
715 | 725 | ||
716 | static char *ip4_string(char *p, const u8 *addr, const char *fmt) | 726 | static noinline_for_stack |
727 | char *ip4_string(char *p, const u8 *addr, const char *fmt) | ||
717 | { | 728 | { |
718 | int i; | 729 | int i; |
719 | bool leading_zeros = (fmt[0] == 'i'); | 730 | bool leading_zeros = (fmt[0] == 'i'); |
@@ -762,7 +773,8 @@ static char *ip4_string(char *p, const u8 *addr, const char *fmt) | |||
762 | return p; | 773 | return p; |
763 | } | 774 | } |
764 | 775 | ||
765 | static char *ip6_compressed_string(char *p, const char *addr) | 776 | static noinline_for_stack |
777 | char *ip6_compressed_string(char *p, const char *addr) | ||
766 | { | 778 | { |
767 | int i, j, range; | 779 | int i, j, range; |
768 | unsigned char zerolength[8]; | 780 | unsigned char zerolength[8]; |
@@ -842,7 +854,8 @@ static char *ip6_compressed_string(char *p, const char *addr) | |||
842 | return p; | 854 | return p; |
843 | } | 855 | } |
844 | 856 | ||
845 | static char *ip6_string(char *p, const char *addr, const char *fmt) | 857 | static noinline_for_stack |
858 | char *ip6_string(char *p, const char *addr, const char *fmt) | ||
846 | { | 859 | { |
847 | int i; | 860 | int i; |
848 | 861 | ||
@@ -857,8 +870,9 @@ static char *ip6_string(char *p, const char *addr, const char *fmt) | |||
857 | return p; | 870 | return p; |
858 | } | 871 | } |
859 | 872 | ||
860 | static char *ip6_addr_string(char *buf, char *end, const u8 *addr, | 873 | static noinline_for_stack |
861 | struct printf_spec spec, const char *fmt) | 874 | char *ip6_addr_string(char *buf, char *end, const u8 *addr, |
875 | struct printf_spec spec, const char *fmt) | ||
862 | { | 876 | { |
863 | char ip6_addr[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")]; | 877 | char ip6_addr[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")]; |
864 | 878 | ||
@@ -870,8 +884,9 @@ static char *ip6_addr_string(char *buf, char *end, const u8 *addr, | |||
870 | return string(buf, end, ip6_addr, spec); | 884 | return string(buf, end, ip6_addr, spec); |
871 | } | 885 | } |
872 | 886 | ||
873 | static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | 887 | static noinline_for_stack |
874 | struct printf_spec spec, const char *fmt) | 888 | char *ip4_addr_string(char *buf, char *end, const u8 *addr, |
889 | struct printf_spec spec, const char *fmt) | ||
875 | { | 890 | { |
876 | char ip4_addr[sizeof("255.255.255.255")]; | 891 | char ip4_addr[sizeof("255.255.255.255")]; |
877 | 892 | ||
@@ -880,8 +895,9 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | |||
880 | return string(buf, end, ip4_addr, spec); | 895 | return string(buf, end, ip4_addr, spec); |
881 | } | 896 | } |
882 | 897 | ||
883 | static char *uuid_string(char *buf, char *end, const u8 *addr, | 898 | static noinline_for_stack |
884 | struct printf_spec spec, const char *fmt) | 899 | char *uuid_string(char *buf, char *end, const u8 *addr, |
900 | struct printf_spec spec, const char *fmt) | ||
885 | { | 901 | { |
886 | char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]; | 902 | char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]; |
887 | char *p = uuid; | 903 | char *p = uuid; |
@@ -969,8 +985,9 @@ static char *uuid_string(char *buf, char *end, const u8 *addr, | |||
969 | * function pointers are really function descriptors, which contain a | 985 | * function pointers are really function descriptors, which contain a |
970 | * pointer to the real address. | 986 | * pointer to the real address. |
971 | */ | 987 | */ |
972 | static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | 988 | static noinline_for_stack |
973 | struct printf_spec spec) | 989 | char *pointer(const char *fmt, char *buf, char *end, void *ptr, |
990 | struct printf_spec spec) | ||
974 | { | 991 | { |
975 | if (!ptr) | 992 | if (!ptr) |
976 | return string(buf, end, "(null)", spec); | 993 | return string(buf, end, "(null)", spec); |
@@ -1039,7 +1056,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
1039 | * @precision: precision of a number | 1056 | * @precision: precision of a number |
1040 | * @qualifier: qualifier of a number (long, size_t, ...) | 1057 | * @qualifier: qualifier of a number (long, size_t, ...) |
1041 | */ | 1058 | */ |
1042 | static int format_decode(const char *fmt, struct printf_spec *spec) | 1059 | static noinline_for_stack |
1060 | int format_decode(const char *fmt, struct printf_spec *spec) | ||
1043 | { | 1061 | { |
1044 | const char *start = fmt; | 1062 | const char *start = fmt; |
1045 | 1063 | ||
@@ -1979,7 +1997,7 @@ int vsscanf(const char *buf, const char *fmt, va_list args) | |||
1979 | { | 1997 | { |
1980 | char *s = (char *)va_arg(args, char *); | 1998 | char *s = (char *)va_arg(args, char *); |
1981 | if (field_width == -1) | 1999 | if (field_width == -1) |
1982 | field_width = SHORT_MAX; | 2000 | field_width = SHRT_MAX; |
1983 | /* first, skip leading white space in buffer */ | 2001 | /* first, skip leading white space in buffer */ |
1984 | str = skip_spaces(str); | 2002 | str = skip_spaces(str); |
1985 | 2003 | ||