aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2012-04-18 15:52:50 -0400
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2012-04-18 15:52:50 -0400
commit681e4a5e13c1c8315694eb4f44e0cdd84c9082d2 (patch)
tree699f14527c118859026e8ce0214e689d0b9c88cb /lib
parentb960d6c43a63ebd2d8518b328da3816b833ee8cc (diff)
parentc104f1fa1ecf4ee0fc06e31b1f77630b2551be81 (diff)
Merge commit 'c104f1fa1ecf4ee0fc06e31b1f77630b2551be81' into stable/for-linus-3.4
* commit 'c104f1fa1ecf4ee0fc06e31b1f77630b2551be81': (14566 commits) cpufreq: OMAP: fix build errors: depends on ARCH_OMAP2PLUS sparc64: Eliminate obsolete __handle_softirq() function sparc64: Fix bootup crash on sun4v. kconfig: delete last traces of __enabled_ from autoconf.h Revert "kconfig: fix __enabled_ macros definition for invisible and un-selected symbols" kconfig: fix IS_ENABLED to not require all options to be defined irq_domain: fix type mismatch in debugfs output format staging: android: fix mem leaks in __persistent_ram_init() staging: vt6656: Don't leak memory in drivers/staging/vt6656/ioctl.c::private_ioctl() staging: iio: hmc5843: Fix crash in probe function. panic: fix stack dump print on direct call to panic() drivers/rtc/rtc-pl031.c: enable clock on all ST variants Revert "mm: vmscan: fix misused nr_reclaimed in shrink_mem_cgroup_zone()" hugetlb: fix race condition in hugetlb_fault() drivers/rtc/rtc-twl.c: use static register while reading time drivers/rtc/rtc-s3c.c: add placeholder for driver private data drivers/rtc/rtc-s3c.c: fix compilation error MAINTAINERS: add PCDP console maintainer memcg: do not open code accesses to res_counter members drivers/rtc/rtc-efi.c: fix section mismatch warning ...
Diffstat (limited to 'lib')
-rw-r--r--lib/Kconfig96
-rw-r--r--lib/Kconfig.debug55
-rw-r--r--lib/Makefile4
-rw-r--r--lib/argv_split.c2
-rw-r--r--lib/atomic64.c2
-rw-r--r--lib/atomic64_test.c1
-rw-r--r--lib/average.c3
-rw-r--r--lib/bcd.c2
-rw-r--r--lib/bitmap.c4
-rw-r--r--lib/bsearch.c2
-rw-r--r--lib/bug.c2
-rw-r--r--lib/check_signature.c2
-rw-r--r--lib/checksum.c2
-rw-r--r--lib/clz_tab.c18
-rw-r--r--lib/cmdline.c2
-rw-r--r--lib/cpu_rmap.c2
-rw-r--r--lib/cpumask.c14
-rw-r--r--lib/crc32.c1287
-rw-r--r--lib/crc32defs.h56
-rw-r--r--lib/ctype.c3
-rw-r--r--lib/debug_locks.c2
-rw-r--r--lib/debugobjects.c14
-rw-r--r--lib/dec_and_lock.c2
-rw-r--r--lib/decompress_unlzo.c2
-rw-r--r--lib/devres.c2
-rw-r--r--lib/digsig.c52
-rw-r--r--lib/div64.c3
-rw-r--r--lib/dma-debug.c3
-rw-r--r--lib/dump_stack.c2
-rw-r--r--lib/dynamic_debug.c270
-rw-r--r--lib/dynamic_queue_limits.c1
-rw-r--r--lib/fault-inject.c2
-rw-r--r--lib/find_last_bit.c2
-rw-r--r--lib/find_next_bit.c2
-rw-r--r--lib/flex_array.c2
-rw-r--r--lib/gcd.c2
-rw-r--r--lib/gen_crc32table.c81
-rw-r--r--lib/genalloc.c2
-rw-r--r--lib/halfmd4.c2
-rw-r--r--lib/hexdump.c2
-rw-r--r--lib/hweight.c2
-rw-r--r--lib/idr.c10
-rw-r--r--lib/int_sqrt.c2
-rw-r--r--lib/iomap.c2
-rw-r--r--lib/iomap_copy.c2
-rw-r--r--lib/iommu-helper.c3
-rw-r--r--lib/ioremap.c2
-rw-r--r--lib/irq_regs.c3
-rw-r--r--lib/kasprintf.c2
-rw-r--r--lib/klist.c2
-rw-r--r--lib/kobject.c16
-rw-r--r--lib/kobject_uevent.c22
-rw-r--r--lib/kstrtox.c20
-rw-r--r--lib/lcm.c2
-rw-r--r--lib/list_debug.c4
-rw-r--r--lib/llist.c3
-rw-r--r--lib/locking-selftest.c1
-rw-r--r--lib/md5.c2
-rw-r--r--lib/mpi/longlong.h44
-rw-r--r--lib/mpi/mpi-bit.c19
-rw-r--r--lib/mpi/mpi-div.c5
-rw-r--r--lib/mpi/mpi-pow.c2
-rw-r--r--lib/mpi/mpicoder.c93
-rw-r--r--lib/mpi/mpih-div.c4
-rw-r--r--lib/mpi/mpiutil.c5
-rw-r--r--lib/nlattr.c2
-rw-r--r--lib/parser.c3
-rw-r--r--lib/pci_iomap.c2
-rw-r--r--lib/plist.c1
-rw-r--r--lib/prio_tree.c156
-rw-r--r--lib/radix-tree.c598
-rw-r--r--lib/raid6/altivec.uc2
-rw-r--r--lib/random32.c2
-rw-r--r--lib/ratelimit.c2
-rw-r--r--lib/rational.c3
-rw-r--r--lib/rbtree.c2
-rw-r--r--lib/rwsem-spinlock.c2
-rw-r--r--lib/rwsem.c2
-rw-r--r--lib/scatterlist.c6
-rw-r--r--lib/sha1.c2
-rw-r--r--lib/smp_processor_id.c2
-rw-r--r--lib/spinlock_debug.c2
-rw-r--r--lib/string.c25
-rw-r--r--lib/string_helpers.c2
-rw-r--r--lib/swiotlb.c7
-rw-r--r--lib/syscall.c2
-rw-r--r--lib/timerqueue.c3
-rw-r--r--lib/uuid.c2
-rw-r--r--lib/vsprintf.c34
89 files changed, 1977 insertions, 1168 deletions
diff --git a/lib/Kconfig b/lib/Kconfig
index 201e1b33d721..4a8aba2e5cc0 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -19,6 +19,9 @@ config RATIONAL
19config GENERIC_FIND_FIRST_BIT 19config GENERIC_FIND_FIRST_BIT
20 bool 20 bool
21 21
22config NO_GENERIC_PCI_IOPORT_MAP
23 bool
24
22config GENERIC_PCI_IOMAP 25config GENERIC_PCI_IOMAP
23 bool 26 bool
24 27
@@ -26,6 +29,10 @@ config GENERIC_IOMAP
26 bool 29 bool
27 select GENERIC_PCI_IOMAP 30 select GENERIC_PCI_IOMAP
28 31
32config GENERIC_IO
33 boolean
34 default n
35
29config CRC_CCITT 36config CRC_CCITT
30 tristate "CRC-CCITT functions" 37 tristate "CRC-CCITT functions"
31 help 38 help
@@ -58,14 +65,71 @@ config CRC_ITU_T
58 functions require M here. 65 functions require M here.
59 66
60config CRC32 67config CRC32
61 tristate "CRC32 functions" 68 tristate "CRC32/CRC32c functions"
62 default y 69 default y
63 select BITREVERSE 70 select BITREVERSE
64 help 71 help
65 This option is provided for the case where no in-kernel-tree 72 This option is provided for the case where no in-kernel-tree
66 modules require CRC32 functions, but a module built outside the 73 modules require CRC32/CRC32c functions, but a module built outside
67 kernel tree does. Such modules that use library CRC32 functions 74 the kernel tree does. Such modules that use library CRC32/CRC32c
68 require M here. 75 functions require M here.
76
77config CRC32_SELFTEST
78 bool "CRC32 perform self test on init"
79 default n
80 depends on CRC32
81 help
82 This option enables the CRC32 library functions to perform a
83 self test on initialization. The self test computes crc32_le
84 and crc32_be over byte strings with random alignment and length
85 and computes the total elapsed time and number of bytes processed.
86
87choice
88 prompt "CRC32 implementation"
89 depends on CRC32
90 default CRC32_SLICEBY8
91 help
92 This option allows a kernel builder to override the default choice
93 of CRC32 algorithm. Choose the default ("slice by 8") unless you
94 know that you need one of the others.
95
96config CRC32_SLICEBY8
97 bool "Slice by 8 bytes"
98 help
99 Calculate checksum 8 bytes at a time with a clever slicing algorithm.
100 This is the fastest algorithm, but comes with a 8KiB lookup table.
101 Most modern processors have enough cache to hold this table without
102 thrashing the cache.
103
104 This is the default implementation choice. Choose this one unless
105 you have a good reason not to.
106
107config CRC32_SLICEBY4
108 bool "Slice by 4 bytes"
109 help
110 Calculate checksum 4 bytes at a time with a clever slicing algorithm.
111 This is a bit slower than slice by 8, but has a smaller 4KiB lookup
112 table.
113
114 Only choose this option if you know what you are doing.
115
116config CRC32_SARWATE
117 bool "Sarwate's Algorithm (one byte at a time)"
118 help
119 Calculate checksum a byte at a time using Sarwate's algorithm. This
120 is not particularly fast, but has a small 256 byte lookup table.
121
122 Only choose this option if you know what you are doing.
123
124config CRC32_BIT
125 bool "Classic Algorithm (one bit at a time)"
126 help
127 Calculate checksum one bit at a time. This is VERY slow, but has
128 no lookup table. This is provided as a debugging option.
129
130 Only choose this option if you are debugging crc32.
131
132endchoice
69 133
70config CRC7 134config CRC7
71 tristate "CRC7 functions" 135 tristate "CRC7 functions"
@@ -221,6 +285,7 @@ config BTREE
221config HAS_IOMEM 285config HAS_IOMEM
222 boolean 286 boolean
223 depends on !NO_IOMEM 287 depends on !NO_IOMEM
288 select GENERIC_IO
224 default y 289 default y
225 290
226config HAS_IOPORT 291config HAS_IOPORT
@@ -279,6 +344,9 @@ config AVERAGE
279 344
280 If unsure, say N. 345 If unsure, say N.
281 346
347config CLZ_TAB
348 bool
349
282config CORDIC 350config CORDIC
283 tristate "CORDIC algorithm" 351 tristate "CORDIC algorithm"
284 help 352 help
@@ -286,25 +354,25 @@ config CORDIC
286 calculations are in fixed point. Module will be called cordic. 354 calculations are in fixed point. Module will be called cordic.
287 355
288config MPILIB 356config MPILIB
289 tristate "Multiprecision maths library" 357 tristate
358 select CLZ_TAB
290 help 359 help
291 Multiprecision maths library from GnuPG. 360 Multiprecision maths library from GnuPG.
292 It is used to implement RSA digital signature verification, 361 It is used to implement RSA digital signature verification,
293 which is used by IMA/EVM digital signature extension. 362 which is used by IMA/EVM digital signature extension.
294 363
295config MPILIB_EXTRA 364config MPILIB_EXTRA
296 bool "Multiprecision maths library - additional sources" 365 bool
297 depends on MPILIB 366 depends on MPILIB
298 help 367 help
299 Multiprecision maths library from GnuPG. 368 Additional sources of multiprecision maths library from GnuPG.
300 It is used to implement RSA digital signature verification, 369 This code is unnecessary for RSA digital signature verification,
301 which is used by IMA/EVM digital signature extension. 370 but can be compiled if needed.
302 This code in unnecessary for RSA digital signature verification,
303 and can be compiled if needed.
304 371
305config DIGSIG 372config SIGNATURE
306 tristate "In-kernel signature checker" 373 tristate
307 depends on KEYS 374 depends on KEYS && CRYPTO
375 select CRYPTO_SHA1
308 select MPILIB 376 select MPILIB
309 help 377 help
310 Digital signature verification. Currently only RSA is supported. 378 Digital signature verification. Currently only RSA is supported.
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 82928f5ea049..6777153f18f3 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -166,22 +166,25 @@ config LOCKUP_DETECTOR
166 hard and soft lockups. 166 hard and soft lockups.
167 167
168 Softlockups are bugs that cause the kernel to loop in kernel 168 Softlockups are bugs that cause the kernel to loop in kernel
169 mode for more than 60 seconds, without giving other tasks a 169 mode for more than 20 seconds, without giving other tasks a
170 chance to run. The current stack trace is displayed upon 170 chance to run. The current stack trace is displayed upon
171 detection and the system will stay locked up. 171 detection and the system will stay locked up.
172 172
173 Hardlockups are bugs that cause the CPU to loop in kernel mode 173 Hardlockups are bugs that cause the CPU to loop in kernel mode
174 for more than 60 seconds, without letting other interrupts have a 174 for more than 10 seconds, without letting other interrupts have a
175 chance to run. The current stack trace is displayed upon detection 175 chance to run. The current stack trace is displayed upon detection
176 and the system will stay locked up. 176 and the system will stay locked up.
177 177
178 The overhead should be minimal. A periodic hrtimer runs to 178 The overhead should be minimal. A periodic hrtimer runs to
179 generate interrupts and kick the watchdog task every 10-12 seconds. 179 generate interrupts and kick the watchdog task every 4 seconds.
180 An NMI is generated every 60 seconds or so to check for hardlockups. 180 An NMI is generated every 10 seconds or so to check for hardlockups.
181
182 The frequency of hrtimer and NMI events and the soft and hard lockup
183 thresholds can be controlled through the sysctl watchdog_thresh.
181 184
182config HARDLOCKUP_DETECTOR 185config HARDLOCKUP_DETECTOR
183 def_bool LOCKUP_DETECTOR && PERF_EVENTS && HAVE_PERF_EVENTS_NMI && \ 186 def_bool LOCKUP_DETECTOR && PERF_EVENTS && HAVE_PERF_EVENTS_NMI && \
184 !ARCH_HAS_NMI_WATCHDOG 187 !HAVE_NMI_WATCHDOG
185 188
186config BOOTPARAM_HARDLOCKUP_PANIC 189config BOOTPARAM_HARDLOCKUP_PANIC
187 bool "Panic (Reboot) On Hard Lockups" 190 bool "Panic (Reboot) On Hard Lockups"
@@ -189,7 +192,8 @@ config BOOTPARAM_HARDLOCKUP_PANIC
189 help 192 help
190 Say Y here to enable the kernel to panic on "hard lockups", 193 Say Y here to enable the kernel to panic on "hard lockups",
191 which are bugs that cause the kernel to loop in kernel 194 which are bugs that cause the kernel to loop in kernel
192 mode with interrupts disabled for more than 60 seconds. 195 mode with interrupts disabled for more than 10 seconds (configurable
196 using the watchdog_thresh sysctl).
193 197
194 Say N if unsure. 198 Say N if unsure.
195 199
@@ -206,8 +210,8 @@ config BOOTPARAM_SOFTLOCKUP_PANIC
206 help 210 help
207 Say Y here to enable the kernel to panic on "soft lockups", 211 Say Y here to enable the kernel to panic on "soft lockups",
208 which are bugs that cause the kernel to loop in kernel 212 which are bugs that cause the kernel to loop in kernel
209 mode for more than 60 seconds, without giving other tasks a 213 mode for more than 20 seconds (configurable using the watchdog_thresh
210 chance to run. 214 sysctl), without giving other tasks a chance to run.
211 215
212 The panic can be used in combination with panic_timeout, 216 The panic can be used in combination with panic_timeout,
213 to cause the system to reboot automatically after a 217 to cause the system to reboot automatically after a
@@ -414,7 +418,7 @@ config SLUB_STATS
414 418
415config DEBUG_KMEMLEAK 419config DEBUG_KMEMLEAK
416 bool "Kernel memory leak detector" 420 bool "Kernel memory leak detector"
417 depends on DEBUG_KERNEL && EXPERIMENTAL && !MEMORY_HOTPLUG && \ 421 depends on DEBUG_KERNEL && EXPERIMENTAL && \
418 (X86 || ARM || PPC || MIPS || S390 || SPARC64 || SUPERH || MICROBLAZE || TILE) 422 (X86 || ARM || PPC || MIPS || S390 || SPARC64 || SUPERH || MICROBLAZE || TILE)
419 423
420 select DEBUG_FS 424 select DEBUG_FS
@@ -495,6 +499,7 @@ config RT_MUTEX_TESTER
495config DEBUG_SPINLOCK 499config DEBUG_SPINLOCK
496 bool "Spinlock and rw-lock debugging: basic checks" 500 bool "Spinlock and rw-lock debugging: basic checks"
497 depends on DEBUG_KERNEL 501 depends on DEBUG_KERNEL
502 select UNINLINE_SPIN_UNLOCK
498 help 503 help
499 Say Y here and build SMP to catch missing spinlock initialization 504 Say Y here and build SMP to catch missing spinlock initialization
500 and certain other kinds of spinlock errors commonly made. This is 505 and certain other kinds of spinlock errors commonly made. This is
@@ -927,6 +932,30 @@ config RCU_CPU_STALL_VERBOSE
927 932
928 Say Y if you want to enable such checks. 933 Say Y if you want to enable such checks.
929 934
935config RCU_CPU_STALL_INFO
936 bool "Print additional diagnostics on RCU CPU stall"
937 depends on (TREE_RCU || TREE_PREEMPT_RCU) && DEBUG_KERNEL
938 default n
939 help
940 For each stalled CPU that is aware of the current RCU grace
941 period, print out additional per-CPU diagnostic information
942 regarding scheduling-clock ticks, idle state, and,
943 for RCU_FAST_NO_HZ kernels, idle-entry state.
944
945 Say N if you are unsure.
946
947 Say Y if you want to enable such diagnostics.
948
949config RCU_TRACE
950 bool "Enable tracing for RCU"
951 depends on DEBUG_KERNEL
952 help
953 This option provides tracing in RCU which presents stats
954 in debugfs for debugging RCU implementation.
955
956 Say Y here if you want to enable RCU tracing
957 Say N if you are unsure.
958
930config KPROBES_SANITY_TEST 959config KPROBES_SANITY_TEST
931 bool "Kprobes sanity tests" 960 bool "Kprobes sanity tests"
932 depends on DEBUG_KERNEL 961 depends on DEBUG_KERNEL
@@ -1113,14 +1142,6 @@ config LATENCYTOP
1113 Enable this option if you want to use the LatencyTOP tool 1142 Enable this option if you want to use the LatencyTOP tool
1114 to find out which userspace is blocking on what kernel operations. 1143 to find out which userspace is blocking on what kernel operations.
1115 1144
1116config SYSCTL_SYSCALL_CHECK
1117 bool "Sysctl checks"
1118 depends on SYSCTL
1119 ---help---
1120 sys_sysctl uses binary paths that have been found challenging
1121 to properly maintain and use. This enables checks that help
1122 you to keep things correct.
1123
1124source mm/Kconfig.debug 1145source mm/Kconfig.debug
1125source kernel/trace/Kconfig 1146source kernel/trace/Kconfig
1126 1147
diff --git a/lib/Makefile b/lib/Makefile
index dace162c7e1c..18515f0267c4 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -119,7 +119,9 @@ obj-$(CONFIG_CORDIC) += cordic.o
119obj-$(CONFIG_DQL) += dynamic_queue_limits.o 119obj-$(CONFIG_DQL) += dynamic_queue_limits.o
120 120
121obj-$(CONFIG_MPILIB) += mpi/ 121obj-$(CONFIG_MPILIB) += mpi/
122obj-$(CONFIG_DIGSIG) += digsig.o 122obj-$(CONFIG_SIGNATURE) += digsig.o
123
124obj-$(CONFIG_CLZ_TAB) += clz_tab.o
123 125
124hostprogs-y := gen_crc32table 126hostprogs-y := gen_crc32table
125clean-files := crc32table.h 127clean-files := crc32table.h
diff --git a/lib/argv_split.c b/lib/argv_split.c
index 4b1b083f219c..1e9a6cbc3689 100644
--- a/lib/argv_split.c
+++ b/lib/argv_split.c
@@ -6,7 +6,7 @@
6#include <linux/ctype.h> 6#include <linux/ctype.h>
7#include <linux/string.h> 7#include <linux/string.h>
8#include <linux/slab.h> 8#include <linux/slab.h>
9#include <linux/module.h> 9#include <linux/export.h>
10 10
11static const char *skip_arg(const char *cp) 11static const char *skip_arg(const char *cp)
12{ 12{
diff --git a/lib/atomic64.c b/lib/atomic64.c
index 3975470caf4f..978537809d84 100644
--- a/lib/atomic64.c
+++ b/lib/atomic64.c
@@ -13,7 +13,7 @@
13#include <linux/cache.h> 13#include <linux/cache.h>
14#include <linux/spinlock.h> 14#include <linux/spinlock.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/module.h> 16#include <linux/export.h>
17#include <linux/atomic.h> 17#include <linux/atomic.h>
18 18
19/* 19/*
diff --git a/lib/atomic64_test.c b/lib/atomic64_test.c
index 0c33cde2a1e6..cb99b91c3a1d 100644
--- a/lib/atomic64_test.c
+++ b/lib/atomic64_test.c
@@ -9,6 +9,7 @@
9 * (at your option) any later version. 9 * (at your option) any later version.
10 */ 10 */
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/bug.h>
12#include <linux/kernel.h> 13#include <linux/kernel.h>
13#include <linux/atomic.h> 14#include <linux/atomic.h>
14 15
diff --git a/lib/average.c b/lib/average.c
index 5576c2841496..99a67e662b3c 100644
--- a/lib/average.c
+++ b/lib/average.c
@@ -5,8 +5,9 @@
5 * Version 2. See the file COPYING for more details. 5 * Version 2. See the file COPYING for more details.
6 */ 6 */
7 7
8#include <linux/module.h> 8#include <linux/export.h>
9#include <linux/average.h> 9#include <linux/average.h>
10#include <linux/kernel.h>
10#include <linux/bug.h> 11#include <linux/bug.h>
11#include <linux/log2.h> 12#include <linux/log2.h>
12 13
diff --git a/lib/bcd.c b/lib/bcd.c
index d74257fd0fe7..55efaf742346 100644
--- a/lib/bcd.c
+++ b/lib/bcd.c
@@ -1,5 +1,5 @@
1#include <linux/bcd.h> 1#include <linux/bcd.h>
2#include <linux/module.h> 2#include <linux/export.h>
3 3
4unsigned bcd2bin(unsigned char val) 4unsigned bcd2bin(unsigned char val)
5{ 5{
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 0d4a127dd9b3..b5a8b6ad2454 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -5,11 +5,13 @@
5 * This source code is licensed under the GNU General Public License, 5 * This source code is licensed under the GNU General Public License,
6 * Version 2. See the file COPYING for more details. 6 * Version 2. See the file COPYING for more details.
7 */ 7 */
8#include <linux/module.h> 8#include <linux/export.h>
9#include <linux/thread_info.h>
9#include <linux/ctype.h> 10#include <linux/ctype.h>
10#include <linux/errno.h> 11#include <linux/errno.h>
11#include <linux/bitmap.h> 12#include <linux/bitmap.h>
12#include <linux/bitops.h> 13#include <linux/bitops.h>
14#include <linux/bug.h>
13#include <asm/uaccess.h> 15#include <asm/uaccess.h>
14 16
15/* 17/*
diff --git a/lib/bsearch.c b/lib/bsearch.c
index 5b54758e2afb..e33c179089db 100644
--- a/lib/bsearch.c
+++ b/lib/bsearch.c
@@ -9,7 +9,7 @@
9 * published by the Free Software Foundation; version 2. 9 * published by the Free Software Foundation; version 2.
10 */ 10 */
11 11
12#include <linux/module.h> 12#include <linux/export.h>
13#include <linux/bsearch.h> 13#include <linux/bsearch.h>
14 14
15/* 15/*
diff --git a/lib/bug.c b/lib/bug.c
index 19552096d16b..a28c1415357c 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -169,7 +169,7 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
169 return BUG_TRAP_TYPE_WARN; 169 return BUG_TRAP_TYPE_WARN;
170 } 170 }
171 171
172 printk(KERN_EMERG "------------[ cut here ]------------\n"); 172 printk(KERN_DEFAULT "------------[ cut here ]------------\n");
173 173
174 if (file) 174 if (file)
175 printk(KERN_CRIT "kernel BUG at %s:%u!\n", 175 printk(KERN_CRIT "kernel BUG at %s:%u!\n",
diff --git a/lib/check_signature.c b/lib/check_signature.c
index fd6af199247b..6b49797980c4 100644
--- a/lib/check_signature.c
+++ b/lib/check_signature.c
@@ -1,5 +1,5 @@
1#include <linux/io.h> 1#include <linux/io.h>
2#include <linux/module.h> 2#include <linux/export.h>
3 3
4/** 4/**
5 * check_signature - find BIOS signatures 5 * check_signature - find BIOS signatures
diff --git a/lib/checksum.c b/lib/checksum.c
index 8df2f91e6d98..12dceb27ff20 100644
--- a/lib/checksum.c
+++ b/lib/checksum.c
@@ -32,7 +32,7 @@
32/* Revised by Kenneth Albanowski for m68knommu. Basic problem: unaligned access 32/* Revised by Kenneth Albanowski for m68knommu. Basic problem: unaligned access
33 kills, so most of the assembly has to go. */ 33 kills, so most of the assembly has to go. */
34 34
35#include <linux/module.h> 35#include <linux/export.h>
36#include <net/checksum.h> 36#include <net/checksum.h>
37 37
38#include <asm/byteorder.h> 38#include <asm/byteorder.h>
diff --git a/lib/clz_tab.c b/lib/clz_tab.c
new file mode 100644
index 000000000000..7287b4a991a7
--- /dev/null
+++ b/lib/clz_tab.c
@@ -0,0 +1,18 @@
1const unsigned char __clz_tab[] = {
2 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
3 5, 5, 5, 5, 5, 5, 5, 5,
4 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
5 6, 6, 6, 6, 6, 6, 6, 6,
6 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7 7, 7, 7, 7, 7, 7, 7, 7,
8 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
9 7, 7, 7, 7, 7, 7, 7, 7,
10 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
11 8, 8, 8, 8, 8, 8, 8, 8,
12 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
13 8, 8, 8, 8, 8, 8, 8, 8,
14 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
15 8, 8, 8, 8, 8, 8, 8, 8,
16 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
17 8, 8, 8, 8, 8, 8, 8, 8,
18};
diff --git a/lib/cmdline.c b/lib/cmdline.c
index f5f3ad8b62ff..eb6791188cf5 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -12,7 +12,7 @@
12 * 12 *
13 */ 13 */
14 14
15#include <linux/module.h> 15#include <linux/export.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/string.h> 17#include <linux/string.h>
18 18
diff --git a/lib/cpu_rmap.c b/lib/cpu_rmap.c
index 987acfafeb83..145dec5267c9 100644
--- a/lib/cpu_rmap.c
+++ b/lib/cpu_rmap.c
@@ -11,7 +11,7 @@
11#ifdef CONFIG_GENERIC_HARDIRQS 11#ifdef CONFIG_GENERIC_HARDIRQS
12#include <linux/interrupt.h> 12#include <linux/interrupt.h>
13#endif 13#endif
14#include <linux/module.h> 14#include <linux/export.h>
15 15
16/* 16/*
17 * These functions maintain a mapping from CPUs to some ordered set of 17 * These functions maintain a mapping from CPUs to some ordered set of
diff --git a/lib/cpumask.c b/lib/cpumask.c
index af3e5817de98..402a54ac35cb 100644
--- a/lib/cpumask.c
+++ b/lib/cpumask.c
@@ -2,7 +2,7 @@
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/bitops.h> 3#include <linux/bitops.h>
4#include <linux/cpumask.h> 4#include <linux/cpumask.h>
5#include <linux/module.h> 5#include <linux/export.h>
6#include <linux/bootmem.h> 6#include <linux/bootmem.h>
7 7
8int __first_cpu(const cpumask_t *srcp) 8int __first_cpu(const cpumask_t *srcp)
@@ -26,18 +26,6 @@ int __next_cpu_nr(int n, const cpumask_t *srcp)
26EXPORT_SYMBOL(__next_cpu_nr); 26EXPORT_SYMBOL(__next_cpu_nr);
27#endif 27#endif
28 28
29int __any_online_cpu(const cpumask_t *mask)
30{
31 int cpu;
32
33 for_each_cpu(cpu, mask) {
34 if (cpu_online(cpu))
35 break;
36 }
37 return cpu;
38}
39EXPORT_SYMBOL(__any_online_cpu);
40
41/** 29/**
42 * cpumask_next_and - get the next cpu in *src1p & *src2p 30 * cpumask_next_and - get the next cpu in *src1p & *src2p
43 * @n: the cpu prior to the place to search (ie. return will be > @n) 31 * @n: the cpu prior to the place to search (ie. return will be > @n)
diff --git a/lib/crc32.c b/lib/crc32.c
index 4b35d2b4437c..b0d278fb1d91 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -1,4 +1,8 @@
1/* 1/*
2 * Aug 8, 2011 Bob Pearson with help from Joakim Tjernlund and George Spelvin
3 * cleaned up code to current version of sparse and added the slicing-by-8
4 * algorithm to the closely similar existing slicing-by-4 algorithm.
5 *
2 * Oct 15, 2000 Matt Domsch <Matt_Domsch@dell.com> 6 * Oct 15, 2000 Matt Domsch <Matt_Domsch@dell.com>
3 * Nicer crc32 functions/docs submitted by linux@horizon.com. Thanks! 7 * Nicer crc32 functions/docs submitted by linux@horizon.com. Thanks!
4 * Code was from the public domain, copyright abandoned. Code was 8 * Code was from the public domain, copyright abandoned. Code was
@@ -20,52 +24,58 @@
20 * Version 2. See the file COPYING for more details. 24 * Version 2. See the file COPYING for more details.
21 */ 25 */
22 26
27/* see: Documentation/crc32.txt for a description of algorithms */
28
23#include <linux/crc32.h> 29#include <linux/crc32.h>
24#include <linux/kernel.h>
25#include <linux/module.h> 30#include <linux/module.h>
26#include <linux/compiler.h>
27#include <linux/types.h> 31#include <linux/types.h>
28#include <linux/init.h>
29#include <linux/atomic.h>
30#include "crc32defs.h" 32#include "crc32defs.h"
31#if CRC_LE_BITS == 8 33
32# define tole(x) __constant_cpu_to_le32(x) 34#if CRC_LE_BITS > 8
35# define tole(x) ((__force u32) __constant_cpu_to_le32(x))
33#else 36#else
34# define tole(x) (x) 37# define tole(x) (x)
35#endif 38#endif
36 39
37#if CRC_BE_BITS == 8 40#if CRC_BE_BITS > 8
38# define tobe(x) __constant_cpu_to_be32(x) 41# define tobe(x) ((__force u32) __constant_cpu_to_be32(x))
39#else 42#else
40# define tobe(x) (x) 43# define tobe(x) (x)
41#endif 44#endif
45
42#include "crc32table.h" 46#include "crc32table.h"
43 47
44MODULE_AUTHOR("Matt Domsch <Matt_Domsch@dell.com>"); 48MODULE_AUTHOR("Matt Domsch <Matt_Domsch@dell.com>");
45MODULE_DESCRIPTION("Ethernet CRC32 calculations"); 49MODULE_DESCRIPTION("Various CRC32 calculations");
46MODULE_LICENSE("GPL"); 50MODULE_LICENSE("GPL");
47 51
48#if CRC_LE_BITS == 8 || CRC_BE_BITS == 8 52#if CRC_LE_BITS > 8 || CRC_BE_BITS > 8
49 53
54/* implements slicing-by-4 or slicing-by-8 algorithm */
50static inline u32 55static inline u32
51crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256]) 56crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256])
52{ 57{
53# ifdef __LITTLE_ENDIAN 58# ifdef __LITTLE_ENDIAN
54# define DO_CRC(x) crc = t0[(crc ^ (x)) & 255] ^ (crc >> 8) 59# define DO_CRC(x) crc = t0[(crc ^ (x)) & 255] ^ (crc >> 8)
55# define DO_CRC4 crc = t3[(crc) & 255] ^ \ 60# define DO_CRC4 (t3[(q) & 255] ^ t2[(q >> 8) & 255] ^ \
56 t2[(crc >> 8) & 255] ^ \ 61 t1[(q >> 16) & 255] ^ t0[(q >> 24) & 255])
57 t1[(crc >> 16) & 255] ^ \ 62# define DO_CRC8 (t7[(q) & 255] ^ t6[(q >> 8) & 255] ^ \
58 t0[(crc >> 24) & 255] 63 t5[(q >> 16) & 255] ^ t4[(q >> 24) & 255])
59# else 64# else
60# define DO_CRC(x) crc = t0[((crc >> 24) ^ (x)) & 255] ^ (crc << 8) 65# define DO_CRC(x) crc = t0[((crc >> 24) ^ (x)) & 255] ^ (crc << 8)
61# define DO_CRC4 crc = t0[(crc) & 255] ^ \ 66# define DO_CRC4 (t0[(q) & 255] ^ t1[(q >> 8) & 255] ^ \
62 t1[(crc >> 8) & 255] ^ \ 67 t2[(q >> 16) & 255] ^ t3[(q >> 24) & 255])
63 t2[(crc >> 16) & 255] ^ \ 68# define DO_CRC8 (t4[(q) & 255] ^ t5[(q >> 8) & 255] ^ \
64 t3[(crc >> 24) & 255] 69 t6[(q >> 16) & 255] ^ t7[(q >> 24) & 255])
65# endif 70# endif
66 const u32 *b; 71 const u32 *b;
67 size_t rem_len; 72 size_t rem_len;
73# ifdef CONFIG_X86
74 size_t i;
75# endif
68 const u32 *t0=tab[0], *t1=tab[1], *t2=tab[2], *t3=tab[3]; 76 const u32 *t0=tab[0], *t1=tab[1], *t2=tab[2], *t3=tab[3];
77 const u32 *t4 = tab[4], *t5 = tab[5], *t6 = tab[6], *t7 = tab[7];
78 u32 q;
69 79
70 /* Align it */ 80 /* Align it */
71 if (unlikely((long)buf & 3 && len)) { 81 if (unlikely((long)buf & 3 && len)) {
@@ -73,27 +83,51 @@ crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256])
73 DO_CRC(*buf++); 83 DO_CRC(*buf++);
74 } while ((--len) && ((long)buf)&3); 84 } while ((--len) && ((long)buf)&3);
75 } 85 }
86
87# if CRC_LE_BITS == 32
76 rem_len = len & 3; 88 rem_len = len & 3;
77 /* load data 32 bits wide, xor data 32 bits wide. */
78 len = len >> 2; 89 len = len >> 2;
90# else
91 rem_len = len & 7;
92 len = len >> 3;
93# endif
94
79 b = (const u32 *)buf; 95 b = (const u32 *)buf;
96# ifdef CONFIG_X86
97 --b;
98 for (i = 0; i < len; i++) {
99# else
80 for (--b; len; --len) { 100 for (--b; len; --len) {
81 crc ^= *++b; /* use pre increment for speed */ 101# endif
82 DO_CRC4; 102 q = crc ^ *++b; /* use pre increment for speed */
103# if CRC_LE_BITS == 32
104 crc = DO_CRC4;
105# else
106 crc = DO_CRC8;
107 q = *++b;
108 crc ^= DO_CRC4;
109# endif
83 } 110 }
84 len = rem_len; 111 len = rem_len;
85 /* And the last few bytes */ 112 /* And the last few bytes */
86 if (len) { 113 if (len) {
87 u8 *p = (u8 *)(b + 1) - 1; 114 u8 *p = (u8 *)(b + 1) - 1;
115# ifdef CONFIG_X86
116 for (i = 0; i < len; i++)
117 DO_CRC(*++p); /* use pre increment for speed */
118# else
88 do { 119 do {
89 DO_CRC(*++p); /* use pre increment for speed */ 120 DO_CRC(*++p); /* use pre increment for speed */
90 } while (--len); 121 } while (--len);
122# endif
91 } 123 }
92 return crc; 124 return crc;
93#undef DO_CRC 125#undef DO_CRC
94#undef DO_CRC4 126#undef DO_CRC4
127#undef DO_CRC8
95} 128}
96#endif 129#endif
130
97/** 131/**
98 * crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32 132 * crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32
99 * @crc: seed value for computation. ~0 for Ethernet, sometimes 0 for 133 * @crc: seed value for computation. ~0 for Ethernet, sometimes 0 for
@@ -101,53 +135,66 @@ crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256])
101 * @p: pointer to buffer over which CRC is run 135 * @p: pointer to buffer over which CRC is run
102 * @len: length of buffer @p 136 * @len: length of buffer @p
103 */ 137 */
104u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len); 138static inline u32 __pure crc32_le_generic(u32 crc, unsigned char const *p,
105 139 size_t len, const u32 (*tab)[256],
106#if CRC_LE_BITS == 1 140 u32 polynomial)
107/*
108 * In fact, the table-based code will work in this case, but it can be
109 * simplified by inlining the table in ?: form.
110 */
111
112u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)
113{ 141{
142#if CRC_LE_BITS == 1
114 int i; 143 int i;
115 while (len--) { 144 while (len--) {
116 crc ^= *p++; 145 crc ^= *p++;
117 for (i = 0; i < 8; i++) 146 for (i = 0; i < 8; i++)
118 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); 147 crc = (crc >> 1) ^ ((crc & 1) ? polynomial : 0);
148 }
149# elif CRC_LE_BITS == 2
150 while (len--) {
151 crc ^= *p++;
152 crc = (crc >> 2) ^ tab[0][crc & 3];
153 crc = (crc >> 2) ^ tab[0][crc & 3];
154 crc = (crc >> 2) ^ tab[0][crc & 3];
155 crc = (crc >> 2) ^ tab[0][crc & 3];
119 } 156 }
120 return crc;
121}
122#else /* Table-based approach */
123
124u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)
125{
126# if CRC_LE_BITS == 8
127 const u32 (*tab)[] = crc32table_le;
128
129 crc = __cpu_to_le32(crc);
130 crc = crc32_body(crc, p, len, tab);
131 return __le32_to_cpu(crc);
132# elif CRC_LE_BITS == 4 157# elif CRC_LE_BITS == 4
133 while (len--) { 158 while (len--) {
134 crc ^= *p++; 159 crc ^= *p++;
135 crc = (crc >> 4) ^ crc32table_le[crc & 15]; 160 crc = (crc >> 4) ^ tab[0][crc & 15];
136 crc = (crc >> 4) ^ crc32table_le[crc & 15]; 161 crc = (crc >> 4) ^ tab[0][crc & 15];
137 } 162 }
138 return crc; 163# elif CRC_LE_BITS == 8
139# elif CRC_LE_BITS == 2 164 /* aka Sarwate algorithm */
140 while (len--) { 165 while (len--) {
141 crc ^= *p++; 166 crc ^= *p++;
142 crc = (crc >> 2) ^ crc32table_le[crc & 3]; 167 crc = (crc >> 8) ^ tab[0][crc & 255];
143 crc = (crc >> 2) ^ crc32table_le[crc & 3];
144 crc = (crc >> 2) ^ crc32table_le[crc & 3];
145 crc = (crc >> 2) ^ crc32table_le[crc & 3];
146 } 168 }
169# else
170 crc = (__force u32) __cpu_to_le32(crc);
171 crc = crc32_body(crc, p, len, tab);
172 crc = __le32_to_cpu((__force __le32)crc);
173#endif
147 return crc; 174 return crc;
148# endif 175}
176
177#if CRC_LE_BITS == 1
178u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)
179{
180 return crc32_le_generic(crc, p, len, NULL, CRCPOLY_LE);
181}
182u32 __pure __crc32c_le(u32 crc, unsigned char const *p, size_t len)
183{
184 return crc32_le_generic(crc, p, len, NULL, CRC32C_POLY_LE);
185}
186#else
187u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)
188{
189 return crc32_le_generic(crc, p, len, crc32table_le, CRCPOLY_LE);
190}
191u32 __pure __crc32c_le(u32 crc, unsigned char const *p, size_t len)
192{
193 return crc32_le_generic(crc, p, len, crc32ctable_le, CRC32C_POLY_LE);
149} 194}
150#endif 195#endif
196EXPORT_SYMBOL(crc32_le);
197EXPORT_SYMBOL(__crc32c_le);
151 198
152/** 199/**
153 * crc32_be() - Calculate bitwise big-endian Ethernet AUTODIN II CRC32 200 * crc32_be() - Calculate bitwise big-endian Ethernet AUTODIN II CRC32
@@ -156,317 +203,913 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)
156 * @p: pointer to buffer over which CRC is run 203 * @p: pointer to buffer over which CRC is run
157 * @len: length of buffer @p 204 * @len: length of buffer @p
158 */ 205 */
159u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len); 206static inline u32 __pure crc32_be_generic(u32 crc, unsigned char const *p,
160 207 size_t len, const u32 (*tab)[256],
161#if CRC_BE_BITS == 1 208 u32 polynomial)
162/*
163 * In fact, the table-based code will work in this case, but it can be
164 * simplified by inlining the table in ?: form.
165 */
166
167u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
168{ 209{
210#if CRC_BE_BITS == 1
169 int i; 211 int i;
170 while (len--) { 212 while (len--) {
171 crc ^= *p++ << 24; 213 crc ^= *p++ << 24;
172 for (i = 0; i < 8; i++) 214 for (i = 0; i < 8; i++)
173 crc = 215 crc =
174 (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 216 (crc << 1) ^ ((crc & 0x80000000) ? polynomial :
175 0); 217 0);
176 } 218 }
177 return crc; 219# elif CRC_BE_BITS == 2
178} 220 while (len--) {
179 221 crc ^= *p++ << 24;
180#else /* Table-based approach */ 222 crc = (crc << 2) ^ tab[0][crc >> 30];
181u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) 223 crc = (crc << 2) ^ tab[0][crc >> 30];
182{ 224 crc = (crc << 2) ^ tab[0][crc >> 30];
183# if CRC_BE_BITS == 8 225 crc = (crc << 2) ^ tab[0][crc >> 30];
184 const u32 (*tab)[] = crc32table_be; 226 }
185
186 crc = __cpu_to_be32(crc);
187 crc = crc32_body(crc, p, len, tab);
188 return __be32_to_cpu(crc);
189# elif CRC_BE_BITS == 4 227# elif CRC_BE_BITS == 4
190 while (len--) { 228 while (len--) {
191 crc ^= *p++ << 24; 229 crc ^= *p++ << 24;
192 crc = (crc << 4) ^ crc32table_be[crc >> 28]; 230 crc = (crc << 4) ^ tab[0][crc >> 28];
193 crc = (crc << 4) ^ crc32table_be[crc >> 28]; 231 crc = (crc << 4) ^ tab[0][crc >> 28];
194 } 232 }
195 return crc; 233# elif CRC_BE_BITS == 8
196# elif CRC_BE_BITS == 2
197 while (len--) { 234 while (len--) {
198 crc ^= *p++ << 24; 235 crc ^= *p++ << 24;
199 crc = (crc << 2) ^ crc32table_be[crc >> 30]; 236 crc = (crc << 8) ^ tab[0][crc >> 24];
200 crc = (crc << 2) ^ crc32table_be[crc >> 30];
201 crc = (crc << 2) ^ crc32table_be[crc >> 30];
202 crc = (crc << 2) ^ crc32table_be[crc >> 30];
203 } 237 }
204 return crc; 238# else
239 crc = (__force u32) __cpu_to_be32(crc);
240 crc = crc32_body(crc, p, len, tab);
241 crc = __be32_to_cpu((__force __be32)crc);
205# endif 242# endif
243 return crc;
206} 244}
207#endif
208 245
209EXPORT_SYMBOL(crc32_le); 246#if CRC_LE_BITS == 1
247u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
248{
249 return crc32_be_generic(crc, p, len, NULL, CRCPOLY_BE);
250}
251#else
252u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
253{
254 return crc32_be_generic(crc, p, len, crc32table_be, CRCPOLY_BE);
255}
256#endif
210EXPORT_SYMBOL(crc32_be); 257EXPORT_SYMBOL(crc32_be);
211 258
212/* 259#ifdef CONFIG_CRC32_SELFTEST
213 * A brief CRC tutorial.
214 *
215 * A CRC is a long-division remainder. You add the CRC to the message,
216 * and the whole thing (message+CRC) is a multiple of the given
217 * CRC polynomial. To check the CRC, you can either check that the
218 * CRC matches the recomputed value, *or* you can check that the
219 * remainder computed on the message+CRC is 0. This latter approach
220 * is used by a lot of hardware implementations, and is why so many
221 * protocols put the end-of-frame flag after the CRC.
222 *
223 * It's actually the same long division you learned in school, except that
224 * - We're working in binary, so the digits are only 0 and 1, and
225 * - When dividing polynomials, there are no carries. Rather than add and
226 * subtract, we just xor. Thus, we tend to get a bit sloppy about
227 * the difference between adding and subtracting.
228 *
229 * A 32-bit CRC polynomial is actually 33 bits long. But since it's
230 * 33 bits long, bit 32 is always going to be set, so usually the CRC
231 * is written in hex with the most significant bit omitted. (If you're
232 * familiar with the IEEE 754 floating-point format, it's the same idea.)
233 *
234 * Note that a CRC is computed over a string of *bits*, so you have
235 * to decide on the endianness of the bits within each byte. To get
236 * the best error-detecting properties, this should correspond to the
237 * order they're actually sent. For example, standard RS-232 serial is
238 * little-endian; the most significant bit (sometimes used for parity)
239 * is sent last. And when appending a CRC word to a message, you should
240 * do it in the right order, matching the endianness.
241 *
242 * Just like with ordinary division, the remainder is always smaller than
243 * the divisor (the CRC polynomial) you're dividing by. Each step of the
244 * division, you take one more digit (bit) of the dividend and append it
245 * to the current remainder. Then you figure out the appropriate multiple
246 * of the divisor to subtract to being the remainder back into range.
247 * In binary, it's easy - it has to be either 0 or 1, and to make the
248 * XOR cancel, it's just a copy of bit 32 of the remainder.
249 *
250 * When computing a CRC, we don't care about the quotient, so we can
251 * throw the quotient bit away, but subtract the appropriate multiple of
252 * the polynomial from the remainder and we're back to where we started,
253 * ready to process the next bit.
254 *
255 * A big-endian CRC written this way would be coded like:
256 * for (i = 0; i < input_bits; i++) {
257 * multiple = remainder & 0x80000000 ? CRCPOLY : 0;
258 * remainder = (remainder << 1 | next_input_bit()) ^ multiple;
259 * }
260 * Notice how, to get at bit 32 of the shifted remainder, we look
261 * at bit 31 of the remainder *before* shifting it.
262 *
263 * But also notice how the next_input_bit() bits we're shifting into
264 * the remainder don't actually affect any decision-making until
265 * 32 bits later. Thus, the first 32 cycles of this are pretty boring.
266 * Also, to add the CRC to a message, we need a 32-bit-long hole for it at
267 * the end, so we have to add 32 extra cycles shifting in zeros at the
268 * end of every message,
269 *
270 * So the standard trick is to rearrage merging in the next_input_bit()
271 * until the moment it's needed. Then the first 32 cycles can be precomputed,
272 * and merging in the final 32 zero bits to make room for the CRC can be
273 * skipped entirely.
274 * This changes the code to:
275 * for (i = 0; i < input_bits; i++) {
276 * remainder ^= next_input_bit() << 31;
277 * multiple = (remainder & 0x80000000) ? CRCPOLY : 0;
278 * remainder = (remainder << 1) ^ multiple;
279 * }
280 * With this optimization, the little-endian code is simpler:
281 * for (i = 0; i < input_bits; i++) {
282 * remainder ^= next_input_bit();
283 * multiple = (remainder & 1) ? CRCPOLY : 0;
284 * remainder = (remainder >> 1) ^ multiple;
285 * }
286 *
287 * Note that the other details of endianness have been hidden in CRCPOLY
288 * (which must be bit-reversed) and next_input_bit().
289 *
290 * However, as long as next_input_bit is returning the bits in a sensible
291 * order, we can actually do the merging 8 or more bits at a time rather
292 * than one bit at a time:
293 * for (i = 0; i < input_bytes; i++) {
294 * remainder ^= next_input_byte() << 24;
295 * for (j = 0; j < 8; j++) {
296 * multiple = (remainder & 0x80000000) ? CRCPOLY : 0;
297 * remainder = (remainder << 1) ^ multiple;
298 * }
299 * }
300 * Or in little-endian:
301 * for (i = 0; i < input_bytes; i++) {
302 * remainder ^= next_input_byte();
303 * for (j = 0; j < 8; j++) {
304 * multiple = (remainder & 1) ? CRCPOLY : 0;
305 * remainder = (remainder << 1) ^ multiple;
306 * }
307 * }
308 * If the input is a multiple of 32 bits, you can even XOR in a 32-bit
309 * word at a time and increase the inner loop count to 32.
310 *
311 * You can also mix and match the two loop styles, for example doing the
312 * bulk of a message byte-at-a-time and adding bit-at-a-time processing
313 * for any fractional bytes at the end.
314 *
315 * The only remaining optimization is to the byte-at-a-time table method.
316 * Here, rather than just shifting one bit of the remainder to decide
317 * in the correct multiple to subtract, we can shift a byte at a time.
318 * This produces a 40-bit (rather than a 33-bit) intermediate remainder,
319 * but again the multiple of the polynomial to subtract depends only on
320 * the high bits, the high 8 bits in this case.
321 *
322 * The multiple we need in that case is the low 32 bits of a 40-bit
323 * value whose high 8 bits are given, and which is a multiple of the
324 * generator polynomial. This is simply the CRC-32 of the given
325 * one-byte message.
326 *
327 * Two more details: normally, appending zero bits to a message which
328 * is already a multiple of a polynomial produces a larger multiple of that
329 * polynomial. To enable a CRC to detect this condition, it's common to
330 * invert the CRC before appending it. This makes the remainder of the
331 * message+crc come out not as zero, but some fixed non-zero value.
332 *
333 * The same problem applies to zero bits prepended to the message, and
334 * a similar solution is used. Instead of starting with a remainder of
335 * 0, an initial remainder of all ones is used. As long as you start
336 * the same way on decoding, it doesn't make a difference.
337 */
338
339#ifdef UNITTEST
340 260
341#include <stdlib.h> 261/* 4096 random bytes */
342#include <stdio.h> 262static u8 __attribute__((__aligned__(8))) test_buf[] =
263{
264 0x5b, 0x85, 0x21, 0xcb, 0x09, 0x68, 0x7d, 0x30,
265 0xc7, 0x69, 0xd7, 0x30, 0x92, 0xde, 0x59, 0xe4,
266 0xc9, 0x6e, 0x8b, 0xdb, 0x98, 0x6b, 0xaa, 0x60,
267 0xa8, 0xb5, 0xbc, 0x6c, 0xa9, 0xb1, 0x5b, 0x2c,
268 0xea, 0xb4, 0x92, 0x6a, 0x3f, 0x79, 0x91, 0xe4,
269 0xe9, 0x70, 0x51, 0x8c, 0x7f, 0x95, 0x6f, 0x1a,
270 0x56, 0xa1, 0x5c, 0x27, 0x03, 0x67, 0x9f, 0x3a,
271 0xe2, 0x31, 0x11, 0x29, 0x6b, 0x98, 0xfc, 0xc4,
272 0x53, 0x24, 0xc5, 0x8b, 0xce, 0x47, 0xb2, 0xb9,
273 0x32, 0xcb, 0xc1, 0xd0, 0x03, 0x57, 0x4e, 0xd4,
274 0xe9, 0x3c, 0xa1, 0x63, 0xcf, 0x12, 0x0e, 0xca,
275 0xe1, 0x13, 0xd1, 0x93, 0xa6, 0x88, 0x5c, 0x61,
276 0x5b, 0xbb, 0xf0, 0x19, 0x46, 0xb4, 0xcf, 0x9e,
277 0xb6, 0x6b, 0x4c, 0x3a, 0xcf, 0x60, 0xf9, 0x7a,
278 0x8d, 0x07, 0x63, 0xdb, 0x40, 0xe9, 0x0b, 0x6f,
279 0xad, 0x97, 0xf1, 0xed, 0xd0, 0x1e, 0x26, 0xfd,
280 0xbf, 0xb7, 0xc8, 0x04, 0x94, 0xf8, 0x8b, 0x8c,
281 0xf1, 0xab, 0x7a, 0xd4, 0xdd, 0xf3, 0xe8, 0x88,
282 0xc3, 0xed, 0x17, 0x8a, 0x9b, 0x40, 0x0d, 0x53,
283 0x62, 0x12, 0x03, 0x5f, 0x1b, 0x35, 0x32, 0x1f,
284 0xb4, 0x7b, 0x93, 0x78, 0x0d, 0xdb, 0xce, 0xa4,
285 0xc0, 0x47, 0xd5, 0xbf, 0x68, 0xe8, 0x5d, 0x74,
286 0x8f, 0x8e, 0x75, 0x1c, 0xb2, 0x4f, 0x9a, 0x60,
287 0xd1, 0xbe, 0x10, 0xf4, 0x5c, 0xa1, 0x53, 0x09,
288 0xa5, 0xe0, 0x09, 0x54, 0x85, 0x5c, 0xdc, 0x07,
289 0xe7, 0x21, 0x69, 0x7b, 0x8a, 0xfd, 0x90, 0xf1,
290 0x22, 0xd0, 0xb4, 0x36, 0x28, 0xe6, 0xb8, 0x0f,
291 0x39, 0xde, 0xc8, 0xf3, 0x86, 0x60, 0x34, 0xd2,
292 0x5e, 0xdf, 0xfd, 0xcf, 0x0f, 0xa9, 0x65, 0xf0,
293 0xd5, 0x4d, 0x96, 0x40, 0xe3, 0xdf, 0x3f, 0x95,
294 0x5a, 0x39, 0x19, 0x93, 0xf4, 0x75, 0xce, 0x22,
295 0x00, 0x1c, 0x93, 0xe2, 0x03, 0x66, 0xf4, 0x93,
296 0x73, 0x86, 0x81, 0x8e, 0x29, 0x44, 0x48, 0x86,
297 0x61, 0x7c, 0x48, 0xa3, 0x43, 0xd2, 0x9c, 0x8d,
298 0xd4, 0x95, 0xdd, 0xe1, 0x22, 0x89, 0x3a, 0x40,
299 0x4c, 0x1b, 0x8a, 0x04, 0xa8, 0x09, 0x69, 0x8b,
300 0xea, 0xc6, 0x55, 0x8e, 0x57, 0xe6, 0x64, 0x35,
301 0xf0, 0xc7, 0x16, 0x9f, 0x5d, 0x5e, 0x86, 0x40,
302 0x46, 0xbb, 0xe5, 0x45, 0x88, 0xfe, 0xc9, 0x63,
303 0x15, 0xfb, 0xf5, 0xbd, 0x71, 0x61, 0xeb, 0x7b,
304 0x78, 0x70, 0x07, 0x31, 0x03, 0x9f, 0xb2, 0xc8,
305 0xa7, 0xab, 0x47, 0xfd, 0xdf, 0xa0, 0x78, 0x72,
306 0xa4, 0x2a, 0xe4, 0xb6, 0xba, 0xc0, 0x1e, 0x86,
307 0x71, 0xe6, 0x3d, 0x18, 0x37, 0x70, 0xe6, 0xff,
308 0xe0, 0xbc, 0x0b, 0x22, 0xa0, 0x1f, 0xd3, 0xed,
309 0xa2, 0x55, 0x39, 0xab, 0xa8, 0x13, 0x73, 0x7c,
310 0x3f, 0xb2, 0xd6, 0x19, 0xac, 0xff, 0x99, 0xed,
311 0xe8, 0xe6, 0xa6, 0x22, 0xe3, 0x9c, 0xf1, 0x30,
312 0xdc, 0x01, 0x0a, 0x56, 0xfa, 0xe4, 0xc9, 0x99,
313 0xdd, 0xa8, 0xd8, 0xda, 0x35, 0x51, 0x73, 0xb4,
314 0x40, 0x86, 0x85, 0xdb, 0x5c, 0xd5, 0x85, 0x80,
315 0x14, 0x9c, 0xfd, 0x98, 0xa9, 0x82, 0xc5, 0x37,
316 0xff, 0x32, 0x5d, 0xd0, 0x0b, 0xfa, 0xdc, 0x04,
317 0x5e, 0x09, 0xd2, 0xca, 0x17, 0x4b, 0x1a, 0x8e,
318 0x15, 0xe1, 0xcc, 0x4e, 0x52, 0x88, 0x35, 0xbd,
319 0x48, 0xfe, 0x15, 0xa0, 0x91, 0xfd, 0x7e, 0x6c,
320 0x0e, 0x5d, 0x79, 0x1b, 0x81, 0x79, 0xd2, 0x09,
321 0x34, 0x70, 0x3d, 0x81, 0xec, 0xf6, 0x24, 0xbb,
322 0xfb, 0xf1, 0x7b, 0xdf, 0x54, 0xea, 0x80, 0x9b,
323 0xc7, 0x99, 0x9e, 0xbd, 0x16, 0x78, 0x12, 0x53,
324 0x5e, 0x01, 0xa7, 0x4e, 0xbd, 0x67, 0xe1, 0x9b,
325 0x4c, 0x0e, 0x61, 0x45, 0x97, 0xd2, 0xf0, 0x0f,
326 0xfe, 0x15, 0x08, 0xb7, 0x11, 0x4c, 0xe7, 0xff,
327 0x81, 0x53, 0xff, 0x91, 0x25, 0x38, 0x7e, 0x40,
328 0x94, 0xe5, 0xe0, 0xad, 0xe6, 0xd9, 0x79, 0xb6,
329 0x92, 0xc9, 0xfc, 0xde, 0xc3, 0x1a, 0x23, 0xbb,
330 0xdd, 0xc8, 0x51, 0x0c, 0x3a, 0x72, 0xfa, 0x73,
331 0x6f, 0xb7, 0xee, 0x61, 0x39, 0x03, 0x01, 0x3f,
332 0x7f, 0x94, 0x2e, 0x2e, 0xba, 0x3a, 0xbb, 0xb4,
333 0xfa, 0x6a, 0x17, 0xfe, 0xea, 0xef, 0x5e, 0x66,
334 0x97, 0x3f, 0x32, 0x3d, 0xd7, 0x3e, 0xb1, 0xf1,
335 0x6c, 0x14, 0x4c, 0xfd, 0x37, 0xd3, 0x38, 0x80,
336 0xfb, 0xde, 0xa6, 0x24, 0x1e, 0xc8, 0xca, 0x7f,
337 0x3a, 0x93, 0xd8, 0x8b, 0x18, 0x13, 0xb2, 0xe5,
338 0xe4, 0x93, 0x05, 0x53, 0x4f, 0x84, 0x66, 0xa7,
339 0x58, 0x5c, 0x7b, 0x86, 0x52, 0x6d, 0x0d, 0xce,
340 0xa4, 0x30, 0x7d, 0xb6, 0x18, 0x9f, 0xeb, 0xff,
341 0x22, 0xbb, 0x72, 0x29, 0xb9, 0x44, 0x0b, 0x48,
342 0x1e, 0x84, 0x71, 0x81, 0xe3, 0x6d, 0x73, 0x26,
343 0x92, 0xb4, 0x4d, 0x2a, 0x29, 0xb8, 0x1f, 0x72,
344 0xed, 0xd0, 0xe1, 0x64, 0x77, 0xea, 0x8e, 0x88,
345 0x0f, 0xef, 0x3f, 0xb1, 0x3b, 0xad, 0xf9, 0xc9,
346 0x8b, 0xd0, 0xac, 0xc6, 0xcc, 0xa9, 0x40, 0xcc,
347 0x76, 0xf6, 0x3b, 0x53, 0xb5, 0x88, 0xcb, 0xc8,
348 0x37, 0xf1, 0xa2, 0xba, 0x23, 0x15, 0x99, 0x09,
349 0xcc, 0xe7, 0x7a, 0x3b, 0x37, 0xf7, 0x58, 0xc8,
350 0x46, 0x8c, 0x2b, 0x2f, 0x4e, 0x0e, 0xa6, 0x5c,
351 0xea, 0x85, 0x55, 0xba, 0x02, 0x0e, 0x0e, 0x48,
352 0xbc, 0xe1, 0xb1, 0x01, 0x35, 0x79, 0x13, 0x3d,
353 0x1b, 0xc0, 0x53, 0x68, 0x11, 0xe7, 0x95, 0x0f,
354 0x9d, 0x3f, 0x4c, 0x47, 0x7b, 0x4d, 0x1c, 0xae,
355 0x50, 0x9b, 0xcb, 0xdd, 0x05, 0x8d, 0x9a, 0x97,
356 0xfd, 0x8c, 0xef, 0x0c, 0x1d, 0x67, 0x73, 0xa8,
357 0x28, 0x36, 0xd5, 0xb6, 0x92, 0x33, 0x40, 0x75,
358 0x0b, 0x51, 0xc3, 0x64, 0xba, 0x1d, 0xc2, 0xcc,
359 0xee, 0x7d, 0x54, 0x0f, 0x27, 0x69, 0xa7, 0x27,
360 0x63, 0x30, 0x29, 0xd9, 0xc8, 0x84, 0xd8, 0xdf,
361 0x9f, 0x68, 0x8d, 0x04, 0xca, 0xa6, 0xc5, 0xc7,
362 0x7a, 0x5c, 0xc8, 0xd1, 0xcb, 0x4a, 0xec, 0xd0,
363 0xd8, 0x20, 0x69, 0xc5, 0x17, 0xcd, 0x78, 0xc8,
364 0x75, 0x23, 0x30, 0x69, 0xc9, 0xd4, 0xea, 0x5c,
365 0x4f, 0x6b, 0x86, 0x3f, 0x8b, 0xfe, 0xee, 0x44,
366 0xc9, 0x7c, 0xb7, 0xdd, 0x3e, 0xe5, 0xec, 0x54,
367 0x03, 0x3e, 0xaa, 0x82, 0xc6, 0xdf, 0xb2, 0x38,
368 0x0e, 0x5d, 0xb3, 0x88, 0xd9, 0xd3, 0x69, 0x5f,
369 0x8f, 0x70, 0x8a, 0x7e, 0x11, 0xd9, 0x1e, 0x7b,
370 0x38, 0xf1, 0x42, 0x1a, 0xc0, 0x35, 0xf5, 0xc7,
371 0x36, 0x85, 0xf5, 0xf7, 0xb8, 0x7e, 0xc7, 0xef,
372 0x18, 0xf1, 0x63, 0xd6, 0x7a, 0xc6, 0xc9, 0x0e,
373 0x4d, 0x69, 0x4f, 0x84, 0xef, 0x26, 0x41, 0x0c,
374 0xec, 0xc7, 0xe0, 0x7e, 0x3c, 0x67, 0x01, 0x4c,
375 0x62, 0x1a, 0x20, 0x6f, 0xee, 0x47, 0x4d, 0xc0,
376 0x99, 0x13, 0x8d, 0x91, 0x4a, 0x26, 0xd4, 0x37,
377 0x28, 0x90, 0x58, 0x75, 0x66, 0x2b, 0x0a, 0xdf,
378 0xda, 0xee, 0x92, 0x25, 0x90, 0x62, 0x39, 0x9e,
379 0x44, 0x98, 0xad, 0xc1, 0x88, 0xed, 0xe4, 0xb4,
380 0xaf, 0xf5, 0x8c, 0x9b, 0x48, 0x4d, 0x56, 0x60,
381 0x97, 0x0f, 0x61, 0x59, 0x9e, 0xa6, 0x27, 0xfe,
382 0xc1, 0x91, 0x15, 0x38, 0xb8, 0x0f, 0xae, 0x61,
383 0x7d, 0x26, 0x13, 0x5a, 0x73, 0xff, 0x1c, 0xa3,
384 0x61, 0x04, 0x58, 0x48, 0x55, 0x44, 0x11, 0xfe,
385 0x15, 0xca, 0xc3, 0xbd, 0xca, 0xc5, 0xb4, 0x40,
386 0x5d, 0x1b, 0x7f, 0x39, 0xb5, 0x9c, 0x35, 0xec,
387 0x61, 0x15, 0x32, 0x32, 0xb8, 0x4e, 0x40, 0x9f,
388 0x17, 0x1f, 0x0a, 0x4d, 0xa9, 0x91, 0xef, 0xb7,
389 0xb0, 0xeb, 0xc2, 0x83, 0x9a, 0x6c, 0xd2, 0x79,
390 0x43, 0x78, 0x5e, 0x2f, 0xe5, 0xdd, 0x1a, 0x3c,
391 0x45, 0xab, 0x29, 0x40, 0x3a, 0x37, 0x5b, 0x6f,
392 0xd7, 0xfc, 0x48, 0x64, 0x3c, 0x49, 0xfb, 0x21,
393 0xbe, 0xc3, 0xff, 0x07, 0xfb, 0x17, 0xe9, 0xc9,
394 0x0c, 0x4c, 0x5c, 0x15, 0x9e, 0x8e, 0x22, 0x30,
395 0x0a, 0xde, 0x48, 0x7f, 0xdb, 0x0d, 0xd1, 0x2b,
396 0x87, 0x38, 0x9e, 0xcc, 0x5a, 0x01, 0x16, 0xee,
397 0x75, 0x49, 0x0d, 0x30, 0x01, 0x34, 0x6a, 0xb6,
398 0x9a, 0x5a, 0x2a, 0xec, 0xbb, 0x48, 0xac, 0xd3,
399 0x77, 0x83, 0xd8, 0x08, 0x86, 0x4f, 0x48, 0x09,
400 0x29, 0x41, 0x79, 0xa1, 0x03, 0x12, 0xc4, 0xcd,
401 0x90, 0x55, 0x47, 0x66, 0x74, 0x9a, 0xcc, 0x4f,
402 0x35, 0x8c, 0xd6, 0x98, 0xef, 0xeb, 0x45, 0xb9,
403 0x9a, 0x26, 0x2f, 0x39, 0xa5, 0x70, 0x6d, 0xfc,
404 0xb4, 0x51, 0xee, 0xf4, 0x9c, 0xe7, 0x38, 0x59,
405 0xad, 0xf4, 0xbc, 0x46, 0xff, 0x46, 0x8e, 0x60,
406 0x9c, 0xa3, 0x60, 0x1d, 0xf8, 0x26, 0x72, 0xf5,
407 0x72, 0x9d, 0x68, 0x80, 0x04, 0xf6, 0x0b, 0xa1,
408 0x0a, 0xd5, 0xa7, 0x82, 0x3a, 0x3e, 0x47, 0xa8,
409 0x5a, 0xde, 0x59, 0x4f, 0x7b, 0x07, 0xb3, 0xe9,
410 0x24, 0x19, 0x3d, 0x34, 0x05, 0xec, 0xf1, 0xab,
411 0x6e, 0x64, 0x8f, 0xd3, 0xe6, 0x41, 0x86, 0x80,
412 0x70, 0xe3, 0x8d, 0x60, 0x9c, 0x34, 0x25, 0x01,
413 0x07, 0x4d, 0x19, 0x41, 0x4e, 0x3d, 0x5c, 0x7e,
414 0xa8, 0xf5, 0xcc, 0xd5, 0x7b, 0xe2, 0x7d, 0x3d,
415 0x49, 0x86, 0x7d, 0x07, 0xb7, 0x10, 0xe3, 0x35,
416 0xb8, 0x84, 0x6d, 0x76, 0xab, 0x17, 0xc6, 0x38,
417 0xb4, 0xd3, 0x28, 0x57, 0xad, 0xd3, 0x88, 0x5a,
418 0xda, 0xea, 0xc8, 0x94, 0xcc, 0x37, 0x19, 0xac,
419 0x9c, 0x9f, 0x4b, 0x00, 0x15, 0xc0, 0xc8, 0xca,
420 0x1f, 0x15, 0xaa, 0xe0, 0xdb, 0xf9, 0x2f, 0x57,
421 0x1b, 0x24, 0xc7, 0x6f, 0x76, 0x29, 0xfb, 0xed,
422 0x25, 0x0d, 0xc0, 0xfe, 0xbd, 0x5a, 0xbf, 0x20,
423 0x08, 0x51, 0x05, 0xec, 0x71, 0xa3, 0xbf, 0xef,
424 0x5e, 0x99, 0x75, 0xdb, 0x3c, 0x5f, 0x9a, 0x8c,
425 0xbb, 0x19, 0x5c, 0x0e, 0x93, 0x19, 0xf8, 0x6a,
426 0xbc, 0xf2, 0x12, 0x54, 0x2f, 0xcb, 0x28, 0x64,
427 0x88, 0xb3, 0x92, 0x0d, 0x96, 0xd1, 0xa6, 0xe4,
428 0x1f, 0xf1, 0x4d, 0xa4, 0xab, 0x1c, 0xee, 0x54,
429 0xf2, 0xad, 0x29, 0x6d, 0x32, 0x37, 0xb2, 0x16,
430 0x77, 0x5c, 0xdc, 0x2e, 0x54, 0xec, 0x75, 0x26,
431 0xc6, 0x36, 0xd9, 0x17, 0x2c, 0xf1, 0x7a, 0xdc,
432 0x4b, 0xf1, 0xe2, 0xd9, 0x95, 0xba, 0xac, 0x87,
433 0xc1, 0xf3, 0x8e, 0x58, 0x08, 0xd8, 0x87, 0x60,
434 0xc9, 0xee, 0x6a, 0xde, 0xa4, 0xd2, 0xfc, 0x0d,
435 0xe5, 0x36, 0xc4, 0x5c, 0x52, 0xb3, 0x07, 0x54,
436 0x65, 0x24, 0xc1, 0xb1, 0xd1, 0xb1, 0x53, 0x13,
437 0x31, 0x79, 0x7f, 0x05, 0x76, 0xeb, 0x37, 0x59,
438 0x15, 0x2b, 0xd1, 0x3f, 0xac, 0x08, 0x97, 0xeb,
439 0x91, 0x98, 0xdf, 0x6c, 0x09, 0x0d, 0x04, 0x9f,
440 0xdc, 0x3b, 0x0e, 0x60, 0x68, 0x47, 0x23, 0x15,
441 0x16, 0xc6, 0x0b, 0x35, 0xf8, 0x77, 0xa2, 0x78,
442 0x50, 0xd4, 0x64, 0x22, 0x33, 0xff, 0xfb, 0x93,
443 0x71, 0x46, 0x50, 0x39, 0x1b, 0x9c, 0xea, 0x4e,
444 0x8d, 0x0c, 0x37, 0xe5, 0x5c, 0x51, 0x3a, 0x31,
445 0xb2, 0x85, 0x84, 0x3f, 0x41, 0xee, 0xa2, 0xc1,
446 0xc6, 0x13, 0x3b, 0x54, 0x28, 0xd2, 0x18, 0x37,
447 0xcc, 0x46, 0x9f, 0x6a, 0x91, 0x3d, 0x5a, 0x15,
448 0x3c, 0x89, 0xa3, 0x61, 0x06, 0x7d, 0x2e, 0x78,
449 0xbe, 0x7d, 0x40, 0xba, 0x2f, 0x95, 0xb1, 0x2f,
450 0x87, 0x3b, 0x8a, 0xbe, 0x6a, 0xf4, 0xc2, 0x31,
451 0x74, 0xee, 0x91, 0xe0, 0x23, 0xaa, 0x5d, 0x7f,
452 0xdd, 0xf0, 0x44, 0x8c, 0x0b, 0x59, 0x2b, 0xfc,
453 0x48, 0x3a, 0xdf, 0x07, 0x05, 0x38, 0x6c, 0xc9,
454 0xeb, 0x18, 0x24, 0x68, 0x8d, 0x58, 0x98, 0xd3,
455 0x31, 0xa3, 0xe4, 0x70, 0x59, 0xb1, 0x21, 0xbe,
456 0x7e, 0x65, 0x7d, 0xb8, 0x04, 0xab, 0xf6, 0xe4,
457 0xd7, 0xda, 0xec, 0x09, 0x8f, 0xda, 0x6d, 0x24,
458 0x07, 0xcc, 0x29, 0x17, 0x05, 0x78, 0x1a, 0xc1,
459 0xb1, 0xce, 0xfc, 0xaa, 0x2d, 0xe7, 0xcc, 0x85,
460 0x84, 0x84, 0x03, 0x2a, 0x0c, 0x3f, 0xa9, 0xf8,
461 0xfd, 0x84, 0x53, 0x59, 0x5c, 0xf0, 0xd4, 0x09,
462 0xf0, 0xd2, 0x6c, 0x32, 0x03, 0xb0, 0xa0, 0x8c,
463 0x52, 0xeb, 0x23, 0x91, 0x88, 0x43, 0x13, 0x46,
464 0xf6, 0x1e, 0xb4, 0x1b, 0xf5, 0x8e, 0x3a, 0xb5,
465 0x3d, 0x00, 0xf6, 0xe5, 0x08, 0x3d, 0x5f, 0x39,
466 0xd3, 0x21, 0x69, 0xbc, 0x03, 0x22, 0x3a, 0xd2,
467 0x5c, 0x84, 0xf8, 0x15, 0xc4, 0x80, 0x0b, 0xbc,
468 0x29, 0x3c, 0xf3, 0x95, 0x98, 0xcd, 0x8f, 0x35,
469 0xbc, 0xa5, 0x3e, 0xfc, 0xd4, 0x13, 0x9e, 0xde,
470 0x4f, 0xce, 0x71, 0x9d, 0x09, 0xad, 0xf2, 0x80,
471 0x6b, 0x65, 0x7f, 0x03, 0x00, 0x14, 0x7c, 0x15,
472 0x85, 0x40, 0x6d, 0x70, 0xea, 0xdc, 0xb3, 0x63,
473 0x35, 0x4f, 0x4d, 0xe0, 0xd9, 0xd5, 0x3c, 0x58,
474 0x56, 0x23, 0x80, 0xe2, 0x36, 0xdd, 0x75, 0x1d,
475 0x94, 0x11, 0x41, 0x8e, 0xe0, 0x81, 0x8e, 0xcf,
476 0xe0, 0xe5, 0xf6, 0xde, 0xd1, 0xe7, 0x04, 0x12,
477 0x79, 0x92, 0x2b, 0x71, 0x2a, 0x79, 0x8b, 0x7c,
478 0x44, 0x79, 0x16, 0x30, 0x4e, 0xf4, 0xf6, 0x9b,
479 0xb7, 0x40, 0xa3, 0x5a, 0xa7, 0x69, 0x3e, 0xc1,
480 0x3a, 0x04, 0xd0, 0x88, 0xa0, 0x3b, 0xdd, 0xc6,
481 0x9e, 0x7e, 0x1e, 0x1e, 0x8f, 0x44, 0xf7, 0x73,
482 0x67, 0x1e, 0x1a, 0x78, 0xfa, 0x62, 0xf4, 0xa9,
483 0xa8, 0xc6, 0x5b, 0xb8, 0xfa, 0x06, 0x7d, 0x5e,
484 0x38, 0x1c, 0x9a, 0x39, 0xe9, 0x39, 0x98, 0x22,
485 0x0b, 0xa7, 0xac, 0x0b, 0xf3, 0xbc, 0xf1, 0xeb,
486 0x8c, 0x81, 0xe3, 0x48, 0x8a, 0xed, 0x42, 0xc2,
487 0x38, 0xcf, 0x3e, 0xda, 0xd2, 0x89, 0x8d, 0x9c,
488 0x53, 0xb5, 0x2f, 0x41, 0x01, 0x26, 0x84, 0x9c,
489 0xa3, 0x56, 0xf6, 0x49, 0xc7, 0xd4, 0x9f, 0x93,
490 0x1b, 0x96, 0x49, 0x5e, 0xad, 0xb3, 0x84, 0x1f,
491 0x3c, 0xa4, 0xe0, 0x9b, 0xd1, 0x90, 0xbc, 0x38,
492 0x6c, 0xdd, 0x95, 0x4d, 0x9d, 0xb1, 0x71, 0x57,
493 0x2d, 0x34, 0xe8, 0xb8, 0x42, 0xc7, 0x99, 0x03,
494 0xc7, 0x07, 0x30, 0x65, 0x91, 0x55, 0xd5, 0x90,
495 0x70, 0x97, 0x37, 0x68, 0xd4, 0x11, 0xf9, 0xe8,
496 0xce, 0xec, 0xdc, 0x34, 0xd5, 0xd3, 0xb7, 0xc4,
497 0xb8, 0x97, 0x05, 0x92, 0xad, 0xf8, 0xe2, 0x36,
498 0x64, 0x41, 0xc9, 0xc5, 0x41, 0x77, 0x52, 0xd7,
499 0x2c, 0xa5, 0x24, 0x2f, 0xd9, 0x34, 0x0b, 0x47,
500 0x35, 0xa7, 0x28, 0x8b, 0xc5, 0xcd, 0xe9, 0x46,
501 0xac, 0x39, 0x94, 0x3c, 0x10, 0xc6, 0x29, 0x73,
502 0x0e, 0x0e, 0x5d, 0xe0, 0x71, 0x03, 0x8a, 0x72,
503 0x0e, 0x26, 0xb0, 0x7d, 0x84, 0xed, 0x95, 0x23,
504 0x49, 0x5a, 0x45, 0x83, 0x45, 0x60, 0x11, 0x4a,
505 0x46, 0x31, 0xd4, 0xd8, 0x16, 0x54, 0x98, 0x58,
506 0xed, 0x6d, 0xcc, 0x5d, 0xd6, 0x50, 0x61, 0x9f,
507 0x9d, 0xc5, 0x3e, 0x9d, 0x32, 0x47, 0xde, 0x96,
508 0xe1, 0x5d, 0xd8, 0xf8, 0xb4, 0x69, 0x6f, 0xb9,
509 0x15, 0x90, 0x57, 0x7a, 0xf6, 0xad, 0xb0, 0x5b,
510 0xf5, 0xa6, 0x36, 0x94, 0xfd, 0x84, 0xce, 0x1c,
511 0x0f, 0x4b, 0xd0, 0xc2, 0x5b, 0x6b, 0x56, 0xef,
512 0x73, 0x93, 0x0b, 0xc3, 0xee, 0xd9, 0xcf, 0xd3,
513 0xa4, 0x22, 0x58, 0xcd, 0x50, 0x6e, 0x65, 0xf4,
514 0xe9, 0xb7, 0x71, 0xaf, 0x4b, 0xb3, 0xb6, 0x2f,
515 0x0f, 0x0e, 0x3b, 0xc9, 0x85, 0x14, 0xf5, 0x17,
516 0xe8, 0x7a, 0x3a, 0xbf, 0x5f, 0x5e, 0xf8, 0x18,
517 0x48, 0xa6, 0x72, 0xab, 0x06, 0x95, 0xe9, 0xc8,
518 0xa7, 0xf4, 0x32, 0x44, 0x04, 0x0c, 0x84, 0x98,
519 0x73, 0xe3, 0x89, 0x8d, 0x5f, 0x7e, 0x4a, 0x42,
520 0x8f, 0xc5, 0x28, 0xb1, 0x82, 0xef, 0x1c, 0x97,
521 0x31, 0x3b, 0x4d, 0xe0, 0x0e, 0x10, 0x10, 0x97,
522 0x93, 0x49, 0x78, 0x2f, 0x0d, 0x86, 0x8b, 0xa1,
523 0x53, 0xa9, 0x81, 0x20, 0x79, 0xe7, 0x07, 0x77,
524 0xb6, 0xac, 0x5e, 0xd2, 0x05, 0xcd, 0xe9, 0xdb,
525 0x8a, 0x94, 0x82, 0x8a, 0x23, 0xb9, 0x3d, 0x1c,
526 0xa9, 0x7d, 0x72, 0x4a, 0xed, 0x33, 0xa3, 0xdb,
527 0x21, 0xa7, 0x86, 0x33, 0x45, 0xa5, 0xaa, 0x56,
528 0x45, 0xb5, 0x83, 0x29, 0x40, 0x47, 0x79, 0x04,
529 0x6e, 0xb9, 0x95, 0xd0, 0x81, 0x77, 0x2d, 0x48,
530 0x1e, 0xfe, 0xc3, 0xc2, 0x1e, 0xe5, 0xf2, 0xbe,
531 0xfd, 0x3b, 0x94, 0x9f, 0xc4, 0xc4, 0x26, 0x9d,
532 0xe4, 0x66, 0x1e, 0x19, 0xee, 0x6c, 0x79, 0x97,
533 0x11, 0x31, 0x4b, 0x0d, 0x01, 0xcb, 0xde, 0xa8,
534 0xf6, 0x6d, 0x7c, 0x39, 0x46, 0x4e, 0x7e, 0x3f,
535 0x94, 0x17, 0xdf, 0xa1, 0x7d, 0xd9, 0x1c, 0x8e,
536 0xbc, 0x7d, 0x33, 0x7d, 0xe3, 0x12, 0x40, 0xca,
537 0xab, 0x37, 0x11, 0x46, 0xd4, 0xae, 0xef, 0x44,
538 0xa2, 0xb3, 0x6a, 0x66, 0x0e, 0x0c, 0x90, 0x7f,
539 0xdf, 0x5c, 0x66, 0x5f, 0xf2, 0x94, 0x9f, 0xa6,
540 0x73, 0x4f, 0xeb, 0x0d, 0xad, 0xbf, 0xc0, 0x63,
541 0x5c, 0xdc, 0x46, 0x51, 0xe8, 0x8e, 0x90, 0x19,
542 0xa8, 0xa4, 0x3c, 0x91, 0x79, 0xfa, 0x7e, 0x58,
543 0x85, 0x13, 0x55, 0xc5, 0x19, 0x82, 0x37, 0x1b,
544 0x0a, 0x02, 0x1f, 0x99, 0x6b, 0x18, 0xf1, 0x28,
545 0x08, 0xa2, 0x73, 0xb8, 0x0f, 0x2e, 0xcd, 0xbf,
546 0xf3, 0x86, 0x7f, 0xea, 0xef, 0xd0, 0xbb, 0xa6,
547 0x21, 0xdf, 0x49, 0x73, 0x51, 0xcc, 0x36, 0xd3,
548 0x3e, 0xa0, 0xf8, 0x44, 0xdf, 0xd3, 0xa6, 0xbe,
549 0x8a, 0xd4, 0x57, 0xdd, 0x72, 0x94, 0x61, 0x0f,
550 0x82, 0xd1, 0x07, 0xb8, 0x7c, 0x18, 0x83, 0xdf,
551 0x3a, 0xe5, 0x50, 0x6a, 0x82, 0x20, 0xac, 0xa9,
552 0xa8, 0xff, 0xd9, 0xf3, 0x77, 0x33, 0x5a, 0x9e,
553 0x7f, 0x6d, 0xfe, 0x5d, 0x33, 0x41, 0x42, 0xe7,
554 0x6c, 0x19, 0xe0, 0x44, 0x8a, 0x15, 0xf6, 0x70,
555 0x98, 0xb7, 0x68, 0x4d, 0xfa, 0x97, 0x39, 0xb0,
556 0x8e, 0xe8, 0x84, 0x8b, 0x75, 0x30, 0xb7, 0x7d,
557 0x92, 0x69, 0x20, 0x9c, 0x81, 0xfb, 0x4b, 0xf4,
558 0x01, 0x50, 0xeb, 0xce, 0x0c, 0x1c, 0x6c, 0xb5,
559 0x4a, 0xd7, 0x27, 0x0c, 0xce, 0xbb, 0xe5, 0x85,
560 0xf0, 0xb6, 0xee, 0xd5, 0x70, 0xdd, 0x3b, 0xfc,
561 0xd4, 0x99, 0xf1, 0x33, 0xdd, 0x8b, 0xc4, 0x2f,
562 0xae, 0xab, 0x74, 0x96, 0x32, 0xc7, 0x4c, 0x56,
563 0x3c, 0x89, 0x0f, 0x96, 0x0b, 0x42, 0xc0, 0xcb,
564 0xee, 0x0f, 0x0b, 0x8c, 0xfb, 0x7e, 0x47, 0x7b,
565 0x64, 0x48, 0xfd, 0xb2, 0x00, 0x80, 0x89, 0xa5,
566 0x13, 0x55, 0x62, 0xfc, 0x8f, 0xe2, 0x42, 0x03,
567 0xb7, 0x4e, 0x2a, 0x79, 0xb4, 0x82, 0xea, 0x23,
568 0x49, 0xda, 0xaf, 0x52, 0x63, 0x1e, 0x60, 0x03,
569 0x89, 0x06, 0x44, 0x46, 0x08, 0xc3, 0xc4, 0x87,
570 0x70, 0x2e, 0xda, 0x94, 0xad, 0x6b, 0xe0, 0xe4,
571 0xd1, 0x8a, 0x06, 0xc2, 0xa8, 0xc0, 0xa7, 0x43,
572 0x3c, 0x47, 0x52, 0x0e, 0xc3, 0x77, 0x81, 0x11,
573 0x67, 0x0e, 0xa0, 0x70, 0x04, 0x47, 0x29, 0x40,
574 0x86, 0x0d, 0x34, 0x56, 0xa7, 0xc9, 0x35, 0x59,
575 0x68, 0xdc, 0x93, 0x81, 0x70, 0xee, 0x86, 0xd9,
576 0x80, 0x06, 0x40, 0x4f, 0x1a, 0x0d, 0x40, 0x30,
577 0x0b, 0xcb, 0x96, 0x47, 0xc1, 0xb7, 0x52, 0xfd,
578 0x56, 0xe0, 0x72, 0x4b, 0xfb, 0xbd, 0x92, 0x45,
579 0x61, 0x71, 0xc2, 0x33, 0x11, 0xbf, 0x52, 0x83,
580 0x79, 0x26, 0xe0, 0x49, 0x6b, 0xb7, 0x05, 0x8b,
581 0xe8, 0x0e, 0x87, 0x31, 0xd7, 0x9d, 0x8a, 0xf5,
582 0xc0, 0x5f, 0x2e, 0x58, 0x4a, 0xdb, 0x11, 0xb3,
583 0x6c, 0x30, 0x2a, 0x46, 0x19, 0xe3, 0x27, 0x84,
584 0x1f, 0x63, 0x6e, 0xf6, 0x57, 0xc7, 0xc9, 0xd8,
585 0x5e, 0xba, 0xb3, 0x87, 0xd5, 0x83, 0x26, 0x34,
586 0x21, 0x9e, 0x65, 0xde, 0x42, 0xd3, 0xbe, 0x7b,
587 0xbc, 0x91, 0x71, 0x44, 0x4d, 0x99, 0x3b, 0x31,
588 0xe5, 0x3f, 0x11, 0x4e, 0x7f, 0x13, 0x51, 0x3b,
589 0xae, 0x79, 0xc9, 0xd3, 0x81, 0x8e, 0x25, 0x40,
590 0x10, 0xfc, 0x07, 0x1e, 0xf9, 0x7b, 0x9a, 0x4b,
591 0x6c, 0xe3, 0xb3, 0xad, 0x1a, 0x0a, 0xdd, 0x9e,
592 0x59, 0x0c, 0xa2, 0xcd, 0xae, 0x48, 0x4a, 0x38,
593 0x5b, 0x47, 0x41, 0x94, 0x65, 0x6b, 0xbb, 0xeb,
594 0x5b, 0xe3, 0xaf, 0x07, 0x5b, 0xd4, 0x4a, 0xa2,
595 0xc9, 0x5d, 0x2f, 0x64, 0x03, 0xd7, 0x3a, 0x2c,
596 0x6e, 0xce, 0x76, 0x95, 0xb4, 0xb3, 0xc0, 0xf1,
597 0xe2, 0x45, 0x73, 0x7a, 0x5c, 0xab, 0xc1, 0xfc,
598 0x02, 0x8d, 0x81, 0x29, 0xb3, 0xac, 0x07, 0xec,
599 0x40, 0x7d, 0x45, 0xd9, 0x7a, 0x59, 0xee, 0x34,
600 0xf0, 0xe9, 0xd5, 0x7b, 0x96, 0xb1, 0x3d, 0x95,
601 0xcc, 0x86, 0xb5, 0xb6, 0x04, 0x2d, 0xb5, 0x92,
602 0x7e, 0x76, 0xf4, 0x06, 0xa9, 0xa3, 0x12, 0x0f,
603 0xb1, 0xaf, 0x26, 0xba, 0x7c, 0xfc, 0x7e, 0x1c,
604 0xbc, 0x2c, 0x49, 0x97, 0x53, 0x60, 0x13, 0x0b,
605 0xa6, 0x61, 0x83, 0x89, 0x42, 0xd4, 0x17, 0x0c,
606 0x6c, 0x26, 0x52, 0xc3, 0xb3, 0xd4, 0x67, 0xf5,
607 0xe3, 0x04, 0xb7, 0xf4, 0xcb, 0x80, 0xb8, 0xcb,
608 0x77, 0x56, 0x3e, 0xaa, 0x57, 0x54, 0xee, 0xb4,
609 0x2c, 0x67, 0xcf, 0xf2, 0xdc, 0xbe, 0x55, 0xf9,
610 0x43, 0x1f, 0x6e, 0x22, 0x97, 0x67, 0x7f, 0xc4,
611 0xef, 0xb1, 0x26, 0x31, 0x1e, 0x27, 0xdf, 0x41,
612 0x80, 0x47, 0x6c, 0xe2, 0xfa, 0xa9, 0x8c, 0x2a,
613 0xf6, 0xf2, 0xab, 0xf0, 0x15, 0xda, 0x6c, 0xc8,
614 0xfe, 0xb5, 0x23, 0xde, 0xa9, 0x05, 0x3f, 0x06,
615 0x54, 0x4c, 0xcd, 0xe1, 0xab, 0xfc, 0x0e, 0x62,
616 0x33, 0x31, 0x73, 0x2c, 0x76, 0xcb, 0xb4, 0x47,
617 0x1e, 0x20, 0xad, 0xd8, 0xf2, 0x31, 0xdd, 0xc4,
618 0x8b, 0x0c, 0x77, 0xbe, 0xe1, 0x8b, 0x26, 0x00,
619 0x02, 0x58, 0xd6, 0x8d, 0xef, 0xad, 0x74, 0x67,
620 0xab, 0x3f, 0xef, 0xcb, 0x6f, 0xb0, 0xcc, 0x81,
621 0x44, 0x4c, 0xaf, 0xe9, 0x49, 0x4f, 0xdb, 0xa0,
622 0x25, 0xa4, 0xf0, 0x89, 0xf1, 0xbe, 0xd8, 0x10,
623 0xff, 0xb1, 0x3b, 0x4b, 0xfa, 0x98, 0xf5, 0x79,
624 0x6d, 0x1e, 0x69, 0x4d, 0x57, 0xb1, 0xc8, 0x19,
625 0x1b, 0xbd, 0x1e, 0x8c, 0x84, 0xb7, 0x7b, 0xe8,
626 0xd2, 0x2d, 0x09, 0x41, 0x41, 0x37, 0x3d, 0xb1,
627 0x6f, 0x26, 0x5d, 0x71, 0x16, 0x3d, 0xb7, 0x83,
628 0x27, 0x2c, 0xa7, 0xb6, 0x50, 0xbd, 0x91, 0x86,
629 0xab, 0x24, 0xa1, 0x38, 0xfd, 0xea, 0x71, 0x55,
630 0x7e, 0x9a, 0x07, 0x77, 0x4b, 0xfa, 0x61, 0x66,
631 0x20, 0x1e, 0x28, 0x95, 0x18, 0x1b, 0xa4, 0xa0,
632 0xfd, 0xc0, 0x89, 0x72, 0x43, 0xd9, 0x3b, 0x49,
633 0x5a, 0x3f, 0x9d, 0xbf, 0xdb, 0xb4, 0x46, 0xea,
634 0x42, 0x01, 0x77, 0x23, 0x68, 0x95, 0xb6, 0x24,
635 0xb3, 0xa8, 0x6c, 0x28, 0x3b, 0x11, 0x40, 0x7e,
636 0x18, 0x65, 0x6d, 0xd8, 0x24, 0x42, 0x7d, 0x88,
637 0xc0, 0x52, 0xd9, 0x05, 0xe4, 0x95, 0x90, 0x87,
638 0x8c, 0xf4, 0xd0, 0x6b, 0xb9, 0x83, 0x99, 0x34,
639 0x6d, 0xfe, 0x54, 0x40, 0x94, 0x52, 0x21, 0x4f,
640 0x14, 0x25, 0xc5, 0xd6, 0x5e, 0x95, 0xdc, 0x0a,
641 0x2b, 0x89, 0x20, 0x11, 0x84, 0x48, 0xd6, 0x3a,
642 0xcd, 0x5c, 0x24, 0xad, 0x62, 0xe3, 0xb1, 0x93,
643 0x25, 0x8d, 0xcd, 0x7e, 0xfc, 0x27, 0xa3, 0x37,
644 0xfd, 0x84, 0xfc, 0x1b, 0xb2, 0xf1, 0x27, 0x38,
645 0x5a, 0xb7, 0xfc, 0xf2, 0xfa, 0x95, 0x66, 0xd4,
646 0xfb, 0xba, 0xa7, 0xd7, 0xa3, 0x72, 0x69, 0x48,
647 0x48, 0x8c, 0xeb, 0x28, 0x89, 0xfe, 0x33, 0x65,
648 0x5a, 0x36, 0x01, 0x7e, 0x06, 0x79, 0x0a, 0x09,
649 0x3b, 0x74, 0x11, 0x9a, 0x6e, 0xbf, 0xd4, 0x9e,
650 0x58, 0x90, 0x49, 0x4f, 0x4d, 0x08, 0xd4, 0xe5,
651 0x4a, 0x09, 0x21, 0xef, 0x8b, 0xb8, 0x74, 0x3b,
652 0x91, 0xdd, 0x36, 0x85, 0x60, 0x2d, 0xfa, 0xd4,
653 0x45, 0x7b, 0x45, 0x53, 0xf5, 0x47, 0x87, 0x7e,
654 0xa6, 0x37, 0xc8, 0x78, 0x7a, 0x68, 0x9d, 0x8d,
655 0x65, 0x2c, 0x0e, 0x91, 0x5c, 0xa2, 0x60, 0xf0,
656 0x8e, 0x3f, 0xe9, 0x1a, 0xcd, 0xaa, 0xe7, 0xd5,
657 0x77, 0x18, 0xaf, 0xc9, 0xbc, 0x18, 0xea, 0x48,
658 0x1b, 0xfb, 0x22, 0x48, 0x70, 0x16, 0x29, 0x9e,
659 0x5b, 0xc1, 0x2c, 0x66, 0x23, 0xbc, 0xf0, 0x1f,
660 0xef, 0xaf, 0xe4, 0xd6, 0x04, 0x19, 0x82, 0x7a,
661 0x0b, 0xba, 0x4b, 0x46, 0xb1, 0x6a, 0x85, 0x5d,
662 0xb4, 0x73, 0xd6, 0x21, 0xa1, 0x71, 0x60, 0x14,
663 0xee, 0x0a, 0x77, 0xc4, 0x66, 0x2e, 0xf9, 0x69,
664 0x30, 0xaf, 0x41, 0x0b, 0xc8, 0x83, 0x3c, 0x53,
665 0x99, 0x19, 0x27, 0x46, 0xf7, 0x41, 0x6e, 0x56,
666 0xdc, 0x94, 0x28, 0x67, 0x4e, 0xb7, 0x25, 0x48,
667 0x8a, 0xc2, 0xe0, 0x60, 0x96, 0xcc, 0x18, 0xf4,
668 0x84, 0xdd, 0xa7, 0x5e, 0x3e, 0x05, 0x0b, 0x26,
669 0x26, 0xb2, 0x5c, 0x1f, 0x57, 0x1a, 0x04, 0x7e,
670 0x6a, 0xe3, 0x2f, 0xb4, 0x35, 0xb6, 0x38, 0x40,
671 0x40, 0xcd, 0x6f, 0x87, 0x2e, 0xef, 0xa3, 0xd7,
672 0xa9, 0xc2, 0xe8, 0x0d, 0x27, 0xdf, 0x44, 0x62,
673 0x99, 0xa0, 0xfc, 0xcf, 0x81, 0x78, 0xcb, 0xfe,
674 0xe5, 0xa0, 0x03, 0x4e, 0x6c, 0xd7, 0xf4, 0xaf,
675 0x7a, 0xbb, 0x61, 0x82, 0xfe, 0x71, 0x89, 0xb2,
676 0x22, 0x7c, 0x8e, 0x83, 0x04, 0xce, 0xf6, 0x5d,
677 0x84, 0x8f, 0x95, 0x6a, 0x7f, 0xad, 0xfd, 0x32,
678 0x9c, 0x5e, 0xe4, 0x9c, 0x89, 0x60, 0x54, 0xaa,
679 0x96, 0x72, 0xd2, 0xd7, 0x36, 0x85, 0xa9, 0x45,
680 0xd2, 0x2a, 0xa1, 0x81, 0x49, 0x6f, 0x7e, 0x04,
681 0xfa, 0xe2, 0xfe, 0x90, 0x26, 0x77, 0x5a, 0x33,
682 0xb8, 0x04, 0x9a, 0x7a, 0xe6, 0x4c, 0x4f, 0xad,
683 0x72, 0x96, 0x08, 0x28, 0x58, 0x13, 0xf8, 0xc4,
684 0x1c, 0xf0, 0xc3, 0x45, 0x95, 0x49, 0x20, 0x8c,
685 0x9f, 0x39, 0x70, 0xe1, 0x77, 0xfe, 0xd5, 0x4b,
686 0xaf, 0x86, 0xda, 0xef, 0x22, 0x06, 0x83, 0x36,
687 0x29, 0x12, 0x11, 0x40, 0xbc, 0x3b, 0x86, 0xaa,
688 0xaa, 0x65, 0x60, 0xc3, 0x80, 0xca, 0xed, 0xa9,
689 0xf3, 0xb0, 0x79, 0x96, 0xa2, 0x55, 0x27, 0x28,
690 0x55, 0x73, 0x26, 0xa5, 0x50, 0xea, 0x92, 0x4b,
691 0x3c, 0x5c, 0x82, 0x33, 0xf0, 0x01, 0x3f, 0x03,
692 0xc1, 0x08, 0x05, 0xbf, 0x98, 0xf4, 0x9b, 0x6d,
693 0xa5, 0xa8, 0xb4, 0x82, 0x0c, 0x06, 0xfa, 0xff,
694 0x2d, 0x08, 0xf3, 0x05, 0x4f, 0x57, 0x2a, 0x39,
695 0xd4, 0x83, 0x0d, 0x75, 0x51, 0xd8, 0x5b, 0x1b,
696 0xd3, 0x51, 0x5a, 0x32, 0x2a, 0x9b, 0x32, 0xb2,
697 0xf2, 0xa4, 0x96, 0x12, 0xf2, 0xae, 0x40, 0x34,
698 0x67, 0xa8, 0xf5, 0x44, 0xd5, 0x35, 0x53, 0xfe,
699 0xa3, 0x60, 0x96, 0x63, 0x0f, 0x1f, 0x6e, 0xb0,
700 0x5a, 0x42, 0xa6, 0xfc, 0x51, 0x0b, 0x60, 0x27,
701 0xbc, 0x06, 0x71, 0xed, 0x65, 0x5b, 0x23, 0x86,
702 0x4a, 0x07, 0x3b, 0x22, 0x07, 0x46, 0xe6, 0x90,
703 0x3e, 0xf3, 0x25, 0x50, 0x1b, 0x4c, 0x7f, 0x03,
704 0x08, 0xa8, 0x36, 0x6b, 0x87, 0xe5, 0xe3, 0xdb,
705 0x9a, 0x38, 0x83, 0xff, 0x9f, 0x1a, 0x9f, 0x57,
706 0xa4, 0x2a, 0xf6, 0x37, 0xbc, 0x1a, 0xff, 0xc9,
707 0x1e, 0x35, 0x0c, 0xc3, 0x7c, 0xa3, 0xb2, 0xe5,
708 0xd2, 0xc6, 0xb4, 0x57, 0x47, 0xe4, 0x32, 0x16,
709 0x6d, 0xa9, 0xae, 0x64, 0xe6, 0x2d, 0x8d, 0xc5,
710 0x8d, 0x50, 0x8e, 0xe8, 0x1a, 0x22, 0x34, 0x2a,
711 0xd9, 0xeb, 0x51, 0x90, 0x4a, 0xb1, 0x41, 0x7d,
712 0x64, 0xf9, 0xb9, 0x0d, 0xf6, 0x23, 0x33, 0xb0,
713 0x33, 0xf4, 0xf7, 0x3f, 0x27, 0x84, 0xc6, 0x0f,
714 0x54, 0xa5, 0xc0, 0x2e, 0xec, 0x0b, 0x3a, 0x48,
715 0x6e, 0x80, 0x35, 0x81, 0x43, 0x9b, 0x90, 0xb1,
716 0xd0, 0x2b, 0xea, 0x21, 0xdc, 0xda, 0x5b, 0x09,
717 0xf4, 0xcc, 0x10, 0xb4, 0xc7, 0xfe, 0x79, 0x51,
718 0xc3, 0xc5, 0xac, 0x88, 0x74, 0x84, 0x0b, 0x4b,
719 0xca, 0x79, 0x16, 0x29, 0xfb, 0x69, 0x54, 0xdf,
720 0x41, 0x7e, 0xe9, 0xc7, 0x8e, 0xea, 0xa5, 0xfe,
721 0xfc, 0x76, 0x0e, 0x90, 0xc4, 0x92, 0x38, 0xad,
722 0x7b, 0x48, 0xe6, 0x6e, 0xf7, 0x21, 0xfd, 0x4e,
723 0x93, 0x0a, 0x7b, 0x41, 0x83, 0x68, 0xfb, 0x57,
724 0x51, 0x76, 0x34, 0xa9, 0x6c, 0x00, 0xaa, 0x4f,
725 0x66, 0x65, 0x98, 0x4a, 0x4f, 0xa3, 0xa0, 0xef,
726 0x69, 0x3f, 0xe3, 0x1c, 0x92, 0x8c, 0xfd, 0xd8,
727 0xe8, 0xde, 0x7c, 0x7f, 0x3e, 0x84, 0x8e, 0x69,
728 0x3c, 0xf1, 0xf2, 0x05, 0x46, 0xdc, 0x2f, 0x9d,
729 0x5e, 0x6e, 0x4c, 0xfb, 0xb5, 0x99, 0x2a, 0x59,
730 0x63, 0xc1, 0x34, 0xbc, 0x57, 0xc0, 0x0d, 0xb9,
731 0x61, 0x25, 0xf3, 0x33, 0x23, 0x51, 0xb6, 0x0d,
732 0x07, 0xa6, 0xab, 0x94, 0x4a, 0xb7, 0x2a, 0xea,
733 0xee, 0xac, 0xa3, 0xc3, 0x04, 0x8b, 0x0e, 0x56,
734 0xfe, 0x44, 0xa7, 0x39, 0xe2, 0xed, 0xed, 0xb4,
735 0x22, 0x2b, 0xac, 0x12, 0x32, 0x28, 0x91, 0xd8,
736 0xa5, 0xab, 0xff, 0x5f, 0xe0, 0x4b, 0xda, 0x78,
737 0x17, 0xda, 0xf1, 0x01, 0x5b, 0xcd, 0xe2, 0x5f,
738 0x50, 0x45, 0x73, 0x2b, 0xe4, 0x76, 0x77, 0xf4,
739 0x64, 0x1d, 0x43, 0xfb, 0x84, 0x7a, 0xea, 0x91,
740 0xae, 0xf9, 0x9e, 0xb7, 0xb4, 0xb0, 0x91, 0x5f,
741 0x16, 0x35, 0x9a, 0x11, 0xb8, 0xc7, 0xc1, 0x8c,
742 0xc6, 0x10, 0x8d, 0x2f, 0x63, 0x4a, 0xa7, 0x57,
743 0x3a, 0x51, 0xd6, 0x32, 0x2d, 0x64, 0x72, 0xd4,
744 0x66, 0xdc, 0x10, 0xa6, 0x67, 0xd6, 0x04, 0x23,
745 0x9d, 0x0a, 0x11, 0x77, 0xdd, 0x37, 0x94, 0x17,
746 0x3c, 0xbf, 0x8b, 0x65, 0xb0, 0x2e, 0x5e, 0x66,
747 0x47, 0x64, 0xac, 0xdd, 0xf0, 0x84, 0xfd, 0x39,
748 0xfa, 0x15, 0x5d, 0xef, 0xae, 0xca, 0xc1, 0x36,
749 0xa7, 0x5c, 0xbf, 0xc7, 0x08, 0xc2, 0x66, 0x00,
750 0x74, 0x74, 0x4e, 0x27, 0x3f, 0x55, 0x8a, 0xb7,
751 0x38, 0x66, 0x83, 0x6d, 0xcf, 0x99, 0x9e, 0x60,
752 0x8f, 0xdd, 0x2e, 0x62, 0x22, 0x0e, 0xef, 0x0c,
753 0x98, 0xa7, 0x85, 0x74, 0x3b, 0x9d, 0xec, 0x9e,
754 0xa9, 0x19, 0x72, 0xa5, 0x7f, 0x2c, 0x39, 0xb7,
755 0x7d, 0xb7, 0xf1, 0x12, 0x65, 0x27, 0x4b, 0x5a,
756 0xde, 0x17, 0xfe, 0xad, 0x44, 0xf3, 0x20, 0x4d,
757 0xfd, 0xe4, 0x1f, 0xb5, 0x81, 0xb0, 0x36, 0x37,
758 0x08, 0x6f, 0xc3, 0x0c, 0xe9, 0x85, 0x98, 0x82,
759 0xa9, 0x62, 0x0c, 0xc4, 0x97, 0xc0, 0x50, 0xc8,
760 0xa7, 0x3c, 0x50, 0x9f, 0x43, 0xb9, 0xcd, 0x5e,
761 0x4d, 0xfa, 0x1c, 0x4b, 0x0b, 0xa9, 0x98, 0x85,
762 0x38, 0x92, 0xac, 0x8d, 0xe4, 0xad, 0x9b, 0x98,
763 0xab, 0xd9, 0x38, 0xac, 0x62, 0x52, 0xa3, 0x22,
764 0x63, 0x0f, 0xbf, 0x95, 0x48, 0xdf, 0x69, 0xe7,
765 0x8b, 0x33, 0xd5, 0xb2, 0xbd, 0x05, 0x49, 0x49,
766 0x9d, 0x57, 0x73, 0x19, 0x33, 0xae, 0xfa, 0x33,
767 0xf1, 0x19, 0xa8, 0x80, 0xce, 0x04, 0x9f, 0xbc,
768 0x1d, 0x65, 0x82, 0x1b, 0xe5, 0x3a, 0x51, 0xc8,
769 0x1c, 0x21, 0xe3, 0x5d, 0xf3, 0x7d, 0x9b, 0x2f,
770 0x2c, 0x1d, 0x4a, 0x7f, 0x9b, 0x68, 0x35, 0xa3,
771 0xb2, 0x50, 0xf7, 0x62, 0x79, 0xcd, 0xf4, 0x98,
772 0x4f, 0xe5, 0x63, 0x7c, 0x3e, 0x45, 0x31, 0x8c,
773 0x16, 0xa0, 0x12, 0xc8, 0x58, 0xce, 0x39, 0xa6,
774 0xbc, 0x54, 0xdb, 0xc5, 0xe0, 0xd5, 0xba, 0xbc,
775 0xb9, 0x04, 0xf4, 0x8d, 0xe8, 0x2f, 0x15, 0x9d,
776};
343 777
344#if 0 /*Not used at present */ 778/* 100 test cases */
345static void 779static struct crc_test {
346buf_dump(char const *prefix, unsigned char const *buf, size_t len) 780 u32 crc; /* random starting crc */
781 u32 start; /* random 6 bit offset in buf */
782 u32 length; /* random 11 bit length of test */
783 u32 crc_le; /* expected crc32_le result */
784 u32 crc_be; /* expected crc32_be result */
785 u32 crc32c_le; /* expected crc32c_le result */
786} test[] =
347{ 787{
348 fputs(prefix, stdout); 788 {0x674bf11d, 0x00000038, 0x00000542, 0x0af6d466, 0xd8b6e4c1,
349 while (len--) 789 0xf6e93d6c},
350 printf(" %02x", *buf++); 790 {0x35c672c6, 0x0000003a, 0x000001aa, 0xc6d3dfba, 0x28aaf3ad,
351 putchar('\n'); 791 0x0fe92aca},
792 {0x496da28e, 0x00000039, 0x000005af, 0xd933660f, 0x5d57e81f,
793 0x52e1ebb8},
794 {0x09a9b90e, 0x00000027, 0x000001f8, 0xb45fe007, 0xf45fca9a,
795 0x0798af9a},
796 {0xdc97e5a9, 0x00000025, 0x000003b6, 0xf81a3562, 0xe0126ba2,
797 0x18eb3152},
798 {0x47c58900, 0x0000000a, 0x000000b9, 0x8e58eccf, 0xf3afc793,
799 0xd00d08c7},
800 {0x292561e8, 0x0000000c, 0x00000403, 0xa2ba8aaf, 0x0b797aed,
801 0x8ba966bc},
802 {0x415037f6, 0x00000003, 0x00000676, 0xa17d52e8, 0x7f0fdf35,
803 0x11d694a2},
804 {0x3466e707, 0x00000026, 0x00000042, 0x258319be, 0x75c484a2,
805 0x6ab3208d},
806 {0xafd1281b, 0x00000023, 0x000002ee, 0x4428eaf8, 0x06c7ad10,
807 0xba4603c5},
808 {0xd3857b18, 0x00000028, 0x000004a2, 0x5c430821, 0xb062b7cb,
809 0xe6071c6f},
810 {0x1d825a8f, 0x0000002b, 0x0000050b, 0xd2c45f0c, 0xd68634e0,
811 0x179ec30a},
812 {0x5033e3bc, 0x0000000b, 0x00000078, 0xa3ea4113, 0xac6d31fb,
813 0x0903beb8},
814 {0x94f1fb5e, 0x0000000f, 0x000003a2, 0xfbfc50b1, 0x3cfe50ed,
815 0x6a7cb4fa},
816 {0xc9a0fe14, 0x00000009, 0x00000473, 0x5fb61894, 0x87070591,
817 0xdb535801},
818 {0x88a034b1, 0x0000001c, 0x000005ad, 0xc1b16053, 0x46f95c67,
819 0x92bed597},
820 {0xf0f72239, 0x00000020, 0x0000026d, 0xa6fa58f3, 0xf8c2c1dd,
821 0x192a3f1b},
822 {0xcc20a5e3, 0x0000003b, 0x0000067a, 0x7740185a, 0x308b979a,
823 0xccbaec1a},
824 {0xce589c95, 0x0000002b, 0x00000641, 0xd055e987, 0x40aae25b,
825 0x7eabae4d},
826 {0x78edc885, 0x00000035, 0x000005be, 0xa39cb14b, 0x035b0d1f,
827 0x28c72982},
828 {0x9d40a377, 0x0000003b, 0x00000038, 0x1f47ccd2, 0x197fbc9d,
829 0xc3cd4d18},
830 {0x703d0e01, 0x0000003c, 0x000006f1, 0x88735e7c, 0xfed57c5a,
831 0xbca8f0e7},
832 {0x776bf505, 0x0000000f, 0x000005b2, 0x5cc4fc01, 0xf32efb97,
833 0x713f60b3},
834 {0x4a3e7854, 0x00000027, 0x000004b8, 0x8d923c82, 0x0cbfb4a2,
835 0xebd08fd5},
836 {0x209172dd, 0x0000003b, 0x00000356, 0xb89e9c2b, 0xd7868138,
837 0x64406c59},
838 {0x3ba4cc5b, 0x0000002f, 0x00000203, 0xe51601a9, 0x5b2a1032,
839 0x7421890e},
840 {0xfc62f297, 0x00000000, 0x00000079, 0x71a8e1a2, 0x5d88685f,
841 0xe9347603},
842 {0x64280b8b, 0x00000016, 0x000007ab, 0x0fa7a30c, 0xda3a455f,
843 0x1bef9060},
844 {0x97dd724b, 0x00000033, 0x000007ad, 0x5788b2f4, 0xd7326d32,
845 0x34720072},
846 {0x61394b52, 0x00000035, 0x00000571, 0xc66525f1, 0xcabe7fef,
847 0x48310f59},
848 {0x29b4faff, 0x00000024, 0x0000006e, 0xca13751e, 0x993648e0,
849 0x783a4213},
850 {0x29bfb1dc, 0x0000000b, 0x00000244, 0x436c43f7, 0x429f7a59,
851 0x9e8efd41},
852 {0x86ae934b, 0x00000035, 0x00000104, 0x0760ec93, 0x9cf7d0f4,
853 0xfc3d34a5},
854 {0xc4c1024e, 0x0000002e, 0x000006b1, 0x6516a3ec, 0x19321f9c,
855 0x17a52ae2},
856 {0x3287a80a, 0x00000026, 0x00000496, 0x0b257eb1, 0x754ebd51,
857 0x886d935a},
858 {0xa4db423e, 0x00000023, 0x0000045d, 0x9b3a66dc, 0x873e9f11,
859 0xeaaeaeb2},
860 {0x7a1078df, 0x00000015, 0x0000014a, 0x8c2484c5, 0x6a628659,
861 0x8e900a4b},
862 {0x6048bd5b, 0x00000006, 0x0000006a, 0x897e3559, 0xac9961af,
863 0xd74662b1},
864 {0xd8f9ea20, 0x0000003d, 0x00000277, 0x60eb905b, 0xed2aaf99,
865 0xd26752ba},
866 {0xea5ec3b4, 0x0000002a, 0x000004fe, 0x869965dc, 0x6c1f833b,
867 0x8b1fcd62},
868 {0x2dfb005d, 0x00000016, 0x00000345, 0x6a3b117e, 0xf05e8521,
869 0xf54342fe},
870 {0x5a214ade, 0x00000020, 0x000005b6, 0x467f70be, 0xcb22ccd3,
871 0x5b95b988},
872 {0xf0ab9cca, 0x00000032, 0x00000515, 0xed223df3, 0x7f3ef01d,
873 0x2e1176be},
874 {0x91b444f9, 0x0000002e, 0x000007f8, 0x84e9a983, 0x5676756f,
875 0x66120546},
876 {0x1b5d2ddb, 0x0000002e, 0x0000012c, 0xba638c4c, 0x3f42047b,
877 0xf256a5cc},
878 {0xd824d1bb, 0x0000003a, 0x000007b5, 0x6288653b, 0x3a3ebea0,
879 0x4af1dd69},
880 {0x0470180c, 0x00000034, 0x000001f0, 0x9d5b80d6, 0x3de08195,
881 0x56f0a04a},
882 {0xffaa3a3f, 0x00000036, 0x00000299, 0xf3a82ab8, 0x53e0c13d,
883 0x74f6b6b2},
884 {0x6406cfeb, 0x00000023, 0x00000600, 0xa920b8e8, 0xe4e2acf4,
885 0x085951fd},
886 {0xb24aaa38, 0x0000003e, 0x000004a1, 0x657cc328, 0x5077b2c3,
887 0xc65387eb},
888 {0x58b2ab7c, 0x00000039, 0x000002b4, 0x3a17ee7e, 0x9dcb3643,
889 0x1ca9257b},
890 {0x3db85970, 0x00000006, 0x000002b6, 0x95268b59, 0xb9812c10,
891 0xfd196d76},
892 {0x857830c5, 0x00000003, 0x00000590, 0x4ef439d5, 0xf042161d,
893 0x5ef88339},
894 {0xe1fcd978, 0x0000003e, 0x000007d8, 0xae8d8699, 0xce0a1ef5,
895 0x2c3714d9},
896 {0xb982a768, 0x00000016, 0x000006e0, 0x62fad3df, 0x5f8a067b,
897 0x58576548},
898 {0x1d581ce8, 0x0000001e, 0x0000058b, 0xf0f5da53, 0x26e39eee,
899 0xfd7c57de},
900 {0x2456719b, 0x00000025, 0x00000503, 0x4296ac64, 0xd50e4c14,
901 0xd5fedd59},
902 {0xfae6d8f2, 0x00000000, 0x0000055d, 0x057fdf2e, 0x2a31391a,
903 0x1cc3b17b},
904 {0xcba828e3, 0x00000039, 0x000002ce, 0xe3f22351, 0x8f00877b,
905 0x270eed73},
906 {0x13d25952, 0x0000000a, 0x0000072d, 0x76d4b4cc, 0x5eb67ec3,
907 0x91ecbb11},
908 {0x0342be3f, 0x00000015, 0x00000599, 0xec75d9f1, 0x9d4d2826,
909 0x05ed8d0c},
910 {0xeaa344e0, 0x00000014, 0x000004d8, 0x72a4c981, 0x2064ea06,
911 0x0b09ad5b},
912 {0xbbb52021, 0x0000003b, 0x00000272, 0x04af99fc, 0xaf042d35,
913 0xf8d511fb},
914 {0xb66384dc, 0x0000001d, 0x000007fc, 0xd7629116, 0x782bd801,
915 0x5ad832cc},
916 {0x616c01b6, 0x00000022, 0x000002c8, 0x5b1dab30, 0x783ce7d2,
917 0x1214d196},
918 {0xce2bdaad, 0x00000016, 0x0000062a, 0x932535c8, 0x3f02926d,
919 0x5747218a},
920 {0x00fe84d7, 0x00000005, 0x00000205, 0x850e50aa, 0x753d649c,
921 0xde8f14de},
922 {0xbebdcb4c, 0x00000006, 0x0000055d, 0xbeaa37a2, 0x2d8c9eba,
923 0x3563b7b9},
924 {0xd8b1a02a, 0x00000010, 0x00000387, 0x5017d2fc, 0x503541a5,
925 0x071475d0},
926 {0x3b96cad2, 0x00000036, 0x00000347, 0x1d2372ae, 0x926cd90b,
927 0x54c79d60},
928 {0xc94c1ed7, 0x00000005, 0x0000038b, 0x9e9fdb22, 0x144a9178,
929 0x4c53eee6},
930 {0x1aad454e, 0x00000025, 0x000002b2, 0xc3f6315c, 0x5c7a35b3,
931 0x10137a3c},
932 {0xa4fec9a6, 0x00000000, 0x000006d6, 0x90be5080, 0xa4107605,
933 0xaa9d6c73},
934 {0x1bbe71e2, 0x0000001f, 0x000002fd, 0x4e504c3b, 0x284ccaf1,
935 0xb63d23e7},
936 {0x4201c7e4, 0x00000002, 0x000002b7, 0x7822e3f9, 0x0cc912a9,
937 0x7f53e9cf},
938 {0x23fddc96, 0x00000003, 0x00000627, 0x8a385125, 0x07767e78,
939 0x13c1cd83},
940 {0xd82ba25c, 0x00000016, 0x0000063e, 0x98e4148a, 0x283330c9,
941 0x49ff5867},
942 {0x786f2032, 0x0000002d, 0x0000060f, 0xf201600a, 0xf561bfcd,
943 0x8467f211},
944 {0xfebe4e1f, 0x0000002a, 0x000004f2, 0x95e51961, 0xfd80dcab,
945 0x3f9683b2},
946 {0x1a6e0a39, 0x00000008, 0x00000672, 0x8af6c2a5, 0x78dd84cb,
947 0x76a3f874},
948 {0x56000ab8, 0x0000000e, 0x000000e5, 0x36bacb8f, 0x22ee1f77,
949 0x863b702f},
950 {0x4717fe0c, 0x00000000, 0x000006ec, 0x8439f342, 0x5c8e03da,
951 0xdc6c58ff},
952 {0xd5d5d68e, 0x0000003c, 0x000003a3, 0x46fff083, 0x177d1b39,
953 0x0622cc95},
954 {0xc25dd6c6, 0x00000024, 0x000006c0, 0x5ceb8eb4, 0x892b0d16,
955 0xe85605cd},
956 {0xe9b11300, 0x00000023, 0x00000683, 0x07a5d59a, 0x6c6a3208,
957 0x31da5f06},
958 {0x95cd285e, 0x00000001, 0x00000047, 0x7b3a4368, 0x0202c07e,
959 0xa1f2e784},
960 {0xd9245a25, 0x0000001e, 0x000003a6, 0xd33c1841, 0x1936c0d5,
961 0xb07cc616},
962 {0x103279db, 0x00000006, 0x0000039b, 0xca09b8a0, 0x77d62892,
963 0xbf943b6c},
964 {0x1cba3172, 0x00000027, 0x000001c8, 0xcb377194, 0xebe682db,
965 0x2c01af1c},
966 {0x8f613739, 0x0000000c, 0x000001df, 0xb4b0bc87, 0x7710bd43,
967 0x0fe5f56d},
968 {0x1c6aa90d, 0x0000001b, 0x0000053c, 0x70559245, 0xda7894ac,
969 0xf8943b2d},
970 {0xaabe5b93, 0x0000003d, 0x00000715, 0xcdbf42fa, 0x0c3b99e7,
971 0xe4d89272},
972 {0xf15dd038, 0x00000006, 0x000006db, 0x6e104aea, 0x8d5967f2,
973 0x7c2f6bbb},
974 {0x584dd49c, 0x00000020, 0x000007bc, 0x36b6cfd6, 0xad4e23b2,
975 0xabbf388b},
976 {0x5d8c9506, 0x00000020, 0x00000470, 0x4c62378e, 0x31d92640,
977 0x1dca1f4e},
978 {0xb80d17b0, 0x00000032, 0x00000346, 0x22a5bb88, 0x9a7ec89f,
979 0x5c170e23},
980 {0xdaf0592e, 0x00000023, 0x000007b0, 0x3cab3f99, 0x9b1fdd99,
981 0xc0e9d672},
982 {0x4793cc85, 0x0000000d, 0x00000706, 0xe82e04f6, 0xed3db6b7,
983 0xc18bdc86},
984 {0x82ebf64e, 0x00000009, 0x000007c3, 0x69d590a9, 0x9efa8499,
985 0xa874fcdd},
986 {0xb18a0319, 0x00000026, 0x000007db, 0x1cf98dcc, 0x8fa9ad6a,
987 0x9dc0bb48},
988};
352 989
353} 990#include <linux/time.h>
354#endif
355 991
356static void bytereverse(unsigned char *buf, size_t len) 992static int __init crc32c_test(void)
357{ 993{
358 while (len--) { 994 int i;
359 unsigned char x = bitrev8(*buf); 995 int errors = 0;
360 *buf++ = x; 996 int bytes = 0;
997 struct timespec start, stop;
998 u64 nsec;
999 unsigned long flags;
1000
1001 /* keep static to prevent cache warming code from
1002 * getting eliminated by the compiler */
1003 static u32 crc;
1004
1005 /* pre-warm the cache */
1006 for (i = 0; i < 100; i++) {
1007 bytes += 2*test[i].length;
1008
1009 crc ^= __crc32c_le(test[i].crc, test_buf +
1010 test[i].start, test[i].length);
361 } 1011 }
362}
363 1012
364static void random_garbage(unsigned char *buf, size_t len) 1013 /* reduce OS noise */
365{ 1014 local_irq_save(flags);
366 while (len--) 1015 local_irq_disable();
367 *buf++ = (unsigned char) random();
368}
369 1016
370#if 0 /* Not used at present */ 1017 getnstimeofday(&start);
371static void store_le(u32 x, unsigned char *buf) 1018 for (i = 0; i < 100; i++) {
372{ 1019 if (test[i].crc32c_le != __crc32c_le(test[i].crc, test_buf +
373 buf[0] = (unsigned char) x; 1020 test[i].start, test[i].length))
374 buf[1] = (unsigned char) (x >> 8); 1021 errors++;
375 buf[2] = (unsigned char) (x >> 16); 1022 }
376 buf[3] = (unsigned char) (x >> 24); 1023 getnstimeofday(&stop);
377}
378#endif
379 1024
380static void store_be(u32 x, unsigned char *buf) 1025 local_irq_restore(flags);
381{ 1026 local_irq_enable();
382 buf[0] = (unsigned char) (x >> 24); 1027
383 buf[1] = (unsigned char) (x >> 16); 1028 nsec = stop.tv_nsec - start.tv_nsec +
384 buf[2] = (unsigned char) (x >> 8); 1029 1000000000 * (stop.tv_sec - start.tv_sec);
385 buf[3] = (unsigned char) x; 1030
1031 pr_info("crc32c: CRC_LE_BITS = %d\n", CRC_LE_BITS);
1032
1033 if (errors)
1034 pr_warn("crc32c: %d self tests failed\n", errors);
1035 else {
1036 pr_info("crc32c: self tests passed, processed %d bytes in %lld nsec\n",
1037 bytes, nsec);
1038 }
1039
1040 return 0;
386} 1041}
387 1042
388/* 1043static int __init crc32_test(void)
389 * This checks that CRC(buf + CRC(buf)) = 0, and that
390 * CRC commutes with bit-reversal. This has the side effect
391 * of bytewise bit-reversing the input buffer, and returns
392 * the CRC of the reversed buffer.
393 */
394static u32 test_step(u32 init, unsigned char *buf, size_t len)
395{ 1044{
396 u32 crc1, crc2; 1045 int i;
397 size_t i; 1046 int errors = 0;
1047 int bytes = 0;
1048 struct timespec start, stop;
1049 u64 nsec;
1050 unsigned long flags;
1051
1052 /* keep static to prevent cache warming code from
1053 * getting eliminated by the compiler */
1054 static u32 crc;
1055
1056 /* pre-warm the cache */
1057 for (i = 0; i < 100; i++) {
1058 bytes += 2*test[i].length;
398 1059
399 crc1 = crc32_be(init, buf, len); 1060 crc ^= crc32_le(test[i].crc, test_buf +
400 store_be(crc1, buf + len); 1061 test[i].start, test[i].length);
401 crc2 = crc32_be(init, buf, len + 4); 1062
402 if (crc2) 1063 crc ^= crc32_be(test[i].crc, test_buf +
403 printf("\nCRC cancellation fail: 0x%08x should be 0\n", 1064 test[i].start, test[i].length);
404 crc2);
405
406 for (i = 0; i <= len + 4; i++) {
407 crc2 = crc32_be(init, buf, i);
408 crc2 = crc32_be(crc2, buf + i, len + 4 - i);
409 if (crc2)
410 printf("\nCRC split fail: 0x%08x\n", crc2);
411 } 1065 }
412 1066
413 /* Now swap it around for the other test */ 1067 /* reduce OS noise */
414 1068 local_irq_save(flags);
415 bytereverse(buf, len + 4); 1069 local_irq_disable();
416 init = bitrev32(init); 1070
417 crc2 = bitrev32(crc1); 1071 getnstimeofday(&start);
418 if (crc1 != bitrev32(crc2)) 1072 for (i = 0; i < 100; i++) {
419 printf("\nBit reversal fail: 0x%08x -> 0x%08x -> 0x%08x\n", 1073 if (test[i].crc_le != crc32_le(test[i].crc, test_buf +
420 crc1, crc2, bitrev32(crc2)); 1074 test[i].start, test[i].length))
421 crc1 = crc32_le(init, buf, len); 1075 errors++;
422 if (crc1 != crc2) 1076
423 printf("\nCRC endianness fail: 0x%08x != 0x%08x\n", crc1, 1077 if (test[i].crc_be != crc32_be(test[i].crc, test_buf +
424 crc2); 1078 test[i].start, test[i].length))
425 crc2 = crc32_le(init, buf, len + 4); 1079 errors++;
426 if (crc2)
427 printf("\nCRC cancellation fail: 0x%08x should be 0\n",
428 crc2);
429
430 for (i = 0; i <= len + 4; i++) {
431 crc2 = crc32_le(init, buf, i);
432 crc2 = crc32_le(crc2, buf + i, len + 4 - i);
433 if (crc2)
434 printf("\nCRC split fail: 0x%08x\n", crc2);
435 } 1080 }
1081 getnstimeofday(&stop);
436 1082
437 return crc1; 1083 local_irq_restore(flags);
438} 1084 local_irq_enable();
439 1085
440#define SIZE 64 1086 nsec = stop.tv_nsec - start.tv_nsec +
441#define INIT1 0 1087 1000000000 * (stop.tv_sec - start.tv_sec);
442#define INIT2 0
443 1088
444int main(void) 1089 pr_info("crc32: CRC_LE_BITS = %d, CRC_BE BITS = %d\n",
445{ 1090 CRC_LE_BITS, CRC_BE_BITS);
446 unsigned char buf1[SIZE + 4]; 1091
447 unsigned char buf2[SIZE + 4]; 1092 if (errors)
448 unsigned char buf3[SIZE + 4]; 1093 pr_warn("crc32: %d self tests failed\n", errors);
449 int i, j; 1094 else {
450 u32 crc1, crc2, crc3; 1095 pr_info("crc32: self tests passed, processed %d bytes in %lld nsec\n",
451 1096 bytes, nsec);
452 for (i = 0; i <= SIZE; i++) {
453 printf("\rTesting length %d...", i);
454 fflush(stdout);
455 random_garbage(buf1, i);
456 random_garbage(buf2, i);
457 for (j = 0; j < i; j++)
458 buf3[j] = buf1[j] ^ buf2[j];
459
460 crc1 = test_step(INIT1, buf1, i);
461 crc2 = test_step(INIT2, buf2, i);
462 /* Now check that CRC(buf1 ^ buf2) = CRC(buf1) ^ CRC(buf2) */
463 crc3 = test_step(INIT1 ^ INIT2, buf3, i);
464 if (crc3 != (crc1 ^ crc2))
465 printf("CRC XOR fail: 0x%08x != 0x%08x ^ 0x%08x\n",
466 crc3, crc1, crc2);
467 } 1097 }
468 printf("\nAll test complete. No failures expected.\n"); 1098
469 return 0; 1099 return 0;
470} 1100}
471 1101
472#endif /* UNITTEST */ 1102static int __init crc32test_init(void)
1103{
1104 crc32_test();
1105 crc32c_test();
1106 return 0;
1107}
1108
1109static void __exit crc32_exit(void)
1110{
1111}
1112
1113module_init(crc32test_init);
1114module_exit(crc32_exit);
1115#endif /* CONFIG_CRC32_SELFTEST */
diff --git a/lib/crc32defs.h b/lib/crc32defs.h
index 9b6773d73749..64cba2c3c700 100644
--- a/lib/crc32defs.h
+++ b/lib/crc32defs.h
@@ -6,27 +6,67 @@
6#define CRCPOLY_LE 0xedb88320 6#define CRCPOLY_LE 0xedb88320
7#define CRCPOLY_BE 0x04c11db7 7#define CRCPOLY_BE 0x04c11db7
8 8
9/* How many bits at a time to use. Requires a table of 4<<CRC_xx_BITS bytes. */ 9/*
10/* For less performance-sensitive, use 4 */ 10 * This is the CRC32c polynomial, as outlined by Castagnoli.
11#ifndef CRC_LE_BITS 11 * x^32+x^28+x^27+x^26+x^25+x^23+x^22+x^20+x^19+x^18+x^14+x^13+x^11+x^10+x^9+
12 * x^8+x^6+x^0
13 */
14#define CRC32C_POLY_LE 0x82F63B78
15
16/* Try to choose an implementation variant via Kconfig */
17#ifdef CONFIG_CRC32_SLICEBY8
18# define CRC_LE_BITS 64
19# define CRC_BE_BITS 64
20#endif
21#ifdef CONFIG_CRC32_SLICEBY4
22# define CRC_LE_BITS 32
23# define CRC_BE_BITS 32
24#endif
25#ifdef CONFIG_CRC32_SARWATE
12# define CRC_LE_BITS 8 26# define CRC_LE_BITS 8
27# define CRC_BE_BITS 8
28#endif
29#ifdef CONFIG_CRC32_BIT
30# define CRC_LE_BITS 1
31# define CRC_BE_BITS 1
32#endif
33
34/*
35 * How many bits at a time to use. Valid values are 1, 2, 4, 8, 32 and 64.
36 * For less performance-sensitive, use 4 or 8 to save table size.
37 * For larger systems choose same as CPU architecture as default.
38 * This works well on X86_64, SPARC64 systems. This may require some
39 * elaboration after experiments with other architectures.
40 */
41#ifndef CRC_LE_BITS
42# ifdef CONFIG_64BIT
43# define CRC_LE_BITS 64
44# else
45# define CRC_LE_BITS 32
46# endif
13#endif 47#endif
14#ifndef CRC_BE_BITS 48#ifndef CRC_BE_BITS
15# define CRC_BE_BITS 8 49# ifdef CONFIG_64BIT
50# define CRC_BE_BITS 64
51# else
52# define CRC_BE_BITS 32
53# endif
16#endif 54#endif
17 55
18/* 56/*
19 * Little-endian CRC computation. Used with serial bit streams sent 57 * Little-endian CRC computation. Used with serial bit streams sent
20 * lsbit-first. Be sure to use cpu_to_le32() to append the computed CRC. 58 * lsbit-first. Be sure to use cpu_to_le32() to append the computed CRC.
21 */ 59 */
22#if CRC_LE_BITS > 8 || CRC_LE_BITS < 1 || CRC_LE_BITS & CRC_LE_BITS-1 60#if CRC_LE_BITS > 64 || CRC_LE_BITS < 1 || CRC_LE_BITS == 16 || \
23# error CRC_LE_BITS must be a power of 2 between 1 and 8 61 CRC_LE_BITS & CRC_LE_BITS-1
62# error "CRC_LE_BITS must be one of {1, 2, 4, 8, 32, 64}"
24#endif 63#endif
25 64
26/* 65/*
27 * Big-endian CRC computation. Used with serial bit streams sent 66 * Big-endian CRC computation. Used with serial bit streams sent
28 * msbit-first. Be sure to use cpu_to_be32() to append the computed CRC. 67 * msbit-first. Be sure to use cpu_to_be32() to append the computed CRC.
29 */ 68 */
30#if CRC_BE_BITS > 8 || CRC_BE_BITS < 1 || CRC_BE_BITS & CRC_BE_BITS-1 69#if CRC_BE_BITS > 64 || CRC_BE_BITS < 1 || CRC_BE_BITS == 16 || \
31# error CRC_BE_BITS must be a power of 2 between 1 and 8 70 CRC_BE_BITS & CRC_BE_BITS-1
71# error "CRC_BE_BITS must be one of {1, 2, 4, 8, 32, 64}"
32#endif 72#endif
diff --git a/lib/ctype.c b/lib/ctype.c
index 26baa620e95b..c646df91a2f7 100644
--- a/lib/ctype.c
+++ b/lib/ctype.c
@@ -5,7 +5,8 @@
5 */ 5 */
6 6
7#include <linux/ctype.h> 7#include <linux/ctype.h>
8#include <linux/module.h> 8#include <linux/compiler.h>
9#include <linux/export.h>
9 10
10const unsigned char _ctype[] = { 11const unsigned char _ctype[] = {
11_C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ 12_C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */
diff --git a/lib/debug_locks.c b/lib/debug_locks.c
index b1c177307677..f2fa60c59343 100644
--- a/lib/debug_locks.c
+++ b/lib/debug_locks.c
@@ -10,7 +10,7 @@
10 */ 10 */
11#include <linux/rwsem.h> 11#include <linux/rwsem.h>
12#include <linux/mutex.h> 12#include <linux/mutex.h>
13#include <linux/module.h> 13#include <linux/export.h>
14#include <linux/spinlock.h> 14#include <linux/spinlock.h>
15#include <linux/debug_locks.h> 15#include <linux/debug_locks.h>
16 16
diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index 77cb245f8e7b..0ab9ae8057f0 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -818,17 +818,9 @@ static int __init fixup_activate(void *addr, enum debug_obj_state state)
818 if (obj->static_init == 1) { 818 if (obj->static_init == 1) {
819 debug_object_init(obj, &descr_type_test); 819 debug_object_init(obj, &descr_type_test);
820 debug_object_activate(obj, &descr_type_test); 820 debug_object_activate(obj, &descr_type_test);
821 /* 821 return 0;
822 * Real code should return 0 here ! This is
823 * not a fixup of some bad behaviour. We
824 * merily call the debug_init function to keep
825 * track of the object.
826 */
827 return 1;
828 } else {
829 /* Real code needs to emit a warning here */
830 } 822 }
831 return 0; 823 return 1;
832 824
833 case ODEBUG_STATE_ACTIVE: 825 case ODEBUG_STATE_ACTIVE:
834 debug_object_deactivate(obj, &descr_type_test); 826 debug_object_deactivate(obj, &descr_type_test);
@@ -967,7 +959,7 @@ static void __init debug_objects_selftest(void)
967 959
968 obj.static_init = 1; 960 obj.static_init = 1;
969 debug_object_activate(&obj, &descr_type_test); 961 debug_object_activate(&obj, &descr_type_test);
970 if (check_results(&obj, ODEBUG_STATE_ACTIVE, ++fixups, warnings)) 962 if (check_results(&obj, ODEBUG_STATE_ACTIVE, fixups, warnings))
971 goto out; 963 goto out;
972 debug_object_init(&obj, &descr_type_test); 964 debug_object_init(&obj, &descr_type_test);
973 if (check_results(&obj, ODEBUG_STATE_INIT, ++fixups, ++warnings)) 965 if (check_results(&obj, ODEBUG_STATE_INIT, ++fixups, ++warnings))
diff --git a/lib/dec_and_lock.c b/lib/dec_and_lock.c
index b5257725daad..e26278576b31 100644
--- a/lib/dec_and_lock.c
+++ b/lib/dec_and_lock.c
@@ -1,4 +1,4 @@
1#include <linux/module.h> 1#include <linux/export.h>
2#include <linux/spinlock.h> 2#include <linux/spinlock.h>
3#include <linux/atomic.h> 3#include <linux/atomic.h>
4 4
diff --git a/lib/decompress_unlzo.c b/lib/decompress_unlzo.c
index 5a7a2adf4c4c..4531294fa62f 100644
--- a/lib/decompress_unlzo.c
+++ b/lib/decompress_unlzo.c
@@ -279,7 +279,7 @@ STATIC inline int INIT unlzo(u8 *input, int in_len,
279 ret = 0; 279 ret = 0;
280exit_2: 280exit_2:
281 if (!input) 281 if (!input)
282 free(in_buf); 282 free(in_buf_save);
283exit_1: 283exit_1:
284 if (!output) 284 if (!output)
285 free(out_buf); 285 free(out_buf);
diff --git a/lib/devres.c b/lib/devres.c
index 9676617b4486..80b9c76d436a 100644
--- a/lib/devres.c
+++ b/lib/devres.c
@@ -1,7 +1,7 @@
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/gfp.h>
4#include <linux/module.h> 4#include <linux/export.h>
5 5
6void devm_ioremap_release(struct device *dev, void *res) 6void devm_ioremap_release(struct device *dev, void *res)
7{ 7{
diff --git a/lib/digsig.c b/lib/digsig.c
index fd2402f67f89..286d558033e2 100644
--- a/lib/digsig.c
+++ b/lib/digsig.c
@@ -34,14 +34,9 @@ static int pkcs_1_v1_5_decode_emsa(const unsigned char *msg,
34 unsigned long msglen, 34 unsigned long msglen,
35 unsigned long modulus_bitlen, 35 unsigned long modulus_bitlen,
36 unsigned char *out, 36 unsigned char *out,
37 unsigned long *outlen, 37 unsigned long *outlen)
38 int *is_valid)
39{ 38{
40 unsigned long modulus_len, ps_len, i; 39 unsigned long modulus_len, ps_len, i;
41 int result;
42
43 /* default to invalid packet */
44 *is_valid = 0;
45 40
46 modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0); 41 modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
47 42
@@ -50,39 +45,30 @@ static int pkcs_1_v1_5_decode_emsa(const unsigned char *msg,
50 return -EINVAL; 45 return -EINVAL;
51 46
52 /* separate encoded message */ 47 /* separate encoded message */
53 if ((msg[0] != 0x00) || (msg[1] != (unsigned char)1)) { 48 if ((msg[0] != 0x00) || (msg[1] != (unsigned char)1))
54 result = -EINVAL; 49 return -EINVAL;
55 goto bail;
56 }
57 50
58 for (i = 2; i < modulus_len - 1; i++) 51 for (i = 2; i < modulus_len - 1; i++)
59 if (msg[i] != 0xFF) 52 if (msg[i] != 0xFF)
60 break; 53 break;
61 54
62 /* separator check */ 55 /* separator check */
63 if (msg[i] != 0) { 56 if (msg[i] != 0)
64 /* There was no octet with hexadecimal value 0x00 57 /* There was no octet with hexadecimal value 0x00
65 to separate ps from m. */ 58 to separate ps from m. */
66 result = -EINVAL; 59 return -EINVAL;
67 goto bail;
68 }
69 60
70 ps_len = i - 2; 61 ps_len = i - 2;
71 62
72 if (*outlen < (msglen - (2 + ps_len + 1))) { 63 if (*outlen < (msglen - (2 + ps_len + 1))) {
73 *outlen = msglen - (2 + ps_len + 1); 64 *outlen = msglen - (2 + ps_len + 1);
74 result = -EOVERFLOW; 65 return -EOVERFLOW;
75 goto bail;
76 } 66 }
77 67
78 *outlen = (msglen - (2 + ps_len + 1)); 68 *outlen = (msglen - (2 + ps_len + 1));
79 memcpy(out, &msg[2 + ps_len + 1], *outlen); 69 memcpy(out, &msg[2 + ps_len + 1], *outlen);
80 70
81 /* valid packet */ 71 return 0;
82 *is_valid = 1;
83 result = 0;
84bail:
85 return result;
86} 72}
87 73
88/* 74/*
@@ -96,7 +82,7 @@ static int digsig_verify_rsa(struct key *key,
96 unsigned long len; 82 unsigned long len;
97 unsigned long mlen, mblen; 83 unsigned long mlen, mblen;
98 unsigned nret, l; 84 unsigned nret, l;
99 int valid, head, i; 85 int head, i;
100 unsigned char *out1 = NULL, *out2 = NULL; 86 unsigned char *out1 = NULL, *out2 = NULL;
101 MPI in = NULL, res = NULL, pkey[2]; 87 MPI in = NULL, res = NULL, pkey[2];
102 uint8_t *p, *datap, *endp; 88 uint8_t *p, *datap, *endp;
@@ -105,6 +91,10 @@ static int digsig_verify_rsa(struct key *key,
105 91
106 down_read(&key->sem); 92 down_read(&key->sem);
107 ukp = key->payload.data; 93 ukp = key->payload.data;
94
95 if (ukp->datalen < sizeof(*pkh))
96 goto err1;
97
108 pkh = (struct pubkey_hdr *)ukp->data; 98 pkh = (struct pubkey_hdr *)ukp->data;
109 99
110 if (pkh->version != 1) 100 if (pkh->version != 1)
@@ -117,18 +107,23 @@ static int digsig_verify_rsa(struct key *key,
117 goto err1; 107 goto err1;
118 108
119 datap = pkh->mpi; 109 datap = pkh->mpi;
120 endp = datap + ukp->datalen; 110 endp = ukp->data + ukp->datalen;
111
112 err = -ENOMEM;
121 113
122 for (i = 0; i < pkh->nmpi; i++) { 114 for (i = 0; i < pkh->nmpi; i++) {
123 unsigned int remaining = endp - datap; 115 unsigned int remaining = endp - datap;
124 pkey[i] = mpi_read_from_buffer(datap, &remaining); 116 pkey[i] = mpi_read_from_buffer(datap, &remaining);
117 if (!pkey[i])
118 goto err;
125 datap += remaining; 119 datap += remaining;
126 } 120 }
127 121
128 mblen = mpi_get_nbits(pkey[0]); 122 mblen = mpi_get_nbits(pkey[0]);
129 mlen = (mblen + 7)/8; 123 mlen = (mblen + 7)/8;
130 124
131 err = -ENOMEM; 125 if (mlen == 0)
126 goto err;
132 127
133 out1 = kzalloc(mlen, GFP_KERNEL); 128 out1 = kzalloc(mlen, GFP_KERNEL);
134 if (!out1) 129 if (!out1)
@@ -167,10 +162,9 @@ static int digsig_verify_rsa(struct key *key,
167 memset(out1, 0, head); 162 memset(out1, 0, head);
168 memcpy(out1 + head, p, l); 163 memcpy(out1 + head, p, l);
169 164
170 err = -EINVAL; 165 err = pkcs_1_v1_5_decode_emsa(out1, len, mblen, out2, &len);
171 pkcs_1_v1_5_decode_emsa(out1, len, mblen, out2, &len, &valid);
172 166
173 if (valid && len == hlen) 167 if (!err && len == hlen)
174 err = memcmp(out2, h, hlen); 168 err = memcmp(out2, h, hlen);
175 169
176err: 170err:
@@ -178,8 +172,8 @@ err:
178 mpi_free(res); 172 mpi_free(res);
179 kfree(out1); 173 kfree(out1);
180 kfree(out2); 174 kfree(out2);
181 mpi_free(pkey[0]); 175 while (--i >= 0)
182 mpi_free(pkey[1]); 176 mpi_free(pkey[i]);
183err1: 177err1:
184 up_read(&key->sem); 178 up_read(&key->sem);
185 179
diff --git a/lib/div64.c b/lib/div64.c
index 5b4919191778..3ea24907d52e 100644
--- a/lib/div64.c
+++ b/lib/div64.c
@@ -16,7 +16,8 @@
16 * assembly versions such as arch/ppc/lib/div64.S and arch/sh/lib/div64.S. 16 * assembly versions such as arch/ppc/lib/div64.S and arch/sh/lib/div64.S.
17 */ 17 */
18 18
19#include <linux/module.h> 19#include <linux/export.h>
20#include <linux/kernel.h>
20#include <linux/math64.h> 21#include <linux/math64.h>
21 22
22/* Not needed on 64bit architectures */ 23/* Not needed on 64bit architectures */
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index fea790a2b176..13ef2338be41 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -170,7 +170,7 @@ static bool driver_filter(struct device *dev)
170 return false; 170 return false;
171 171
172 /* driver filter on but not yet initialized */ 172 /* driver filter on but not yet initialized */
173 drv = get_driver(dev->driver); 173 drv = dev->driver;
174 if (!drv) 174 if (!drv)
175 return false; 175 return false;
176 176
@@ -185,7 +185,6 @@ static bool driver_filter(struct device *dev)
185 } 185 }
186 186
187 read_unlock_irqrestore(&driver_name_lock, flags); 187 read_unlock_irqrestore(&driver_name_lock, flags);
188 put_driver(drv);
189 188
190 return ret; 189 return ret;
191} 190}
diff --git a/lib/dump_stack.c b/lib/dump_stack.c
index 53bff4c8452b..42f4f55c9458 100644
--- a/lib/dump_stack.c
+++ b/lib/dump_stack.c
@@ -4,7 +4,7 @@
4 */ 4 */
5 5
6#include <linux/kernel.h> 6#include <linux/kernel.h>
7#include <linux/module.h> 7#include <linux/export.h>
8 8
9void dump_stack(void) 9void dump_stack(void)
10{ 10{
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index dcdade39e47f..310c753cf83e 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -60,6 +60,7 @@ struct ddebug_iter {
60static DEFINE_MUTEX(ddebug_lock); 60static DEFINE_MUTEX(ddebug_lock);
61static LIST_HEAD(ddebug_tables); 61static LIST_HEAD(ddebug_tables);
62static int verbose = 0; 62static int verbose = 0;
63module_param(verbose, int, 0644);
63 64
64/* Return the last part of a pathname */ 65/* Return the last part of a pathname */
65static inline const char *basename(const char *path) 66static inline const char *basename(const char *path)
@@ -68,12 +69,24 @@ static inline const char *basename(const char *path)
68 return tail ? tail+1 : path; 69 return tail ? tail+1 : path;
69} 70}
70 71
72/* Return the path relative to source root */
73static inline const char *trim_prefix(const char *path)
74{
75 int skip = strlen(__FILE__) - strlen("lib/dynamic_debug.c");
76
77 if (strncmp(path, __FILE__, skip))
78 skip = 0; /* prefix mismatch, don't skip */
79
80 return path + skip;
81}
82
71static struct { unsigned flag:8; char opt_char; } opt_array[] = { 83static struct { unsigned flag:8; char opt_char; } opt_array[] = {
72 { _DPRINTK_FLAGS_PRINT, 'p' }, 84 { _DPRINTK_FLAGS_PRINT, 'p' },
73 { _DPRINTK_FLAGS_INCL_MODNAME, 'm' }, 85 { _DPRINTK_FLAGS_INCL_MODNAME, 'm' },
74 { _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' }, 86 { _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' },
75 { _DPRINTK_FLAGS_INCL_LINENO, 'l' }, 87 { _DPRINTK_FLAGS_INCL_LINENO, 'l' },
76 { _DPRINTK_FLAGS_INCL_TID, 't' }, 88 { _DPRINTK_FLAGS_INCL_TID, 't' },
89 { _DPRINTK_FLAGS_NONE, '_' },
77}; 90};
78 91
79/* format a string into buf[] which describes the _ddebug's flags */ 92/* format a string into buf[] which describes the _ddebug's flags */
@@ -83,58 +96,74 @@ static char *ddebug_describe_flags(struct _ddebug *dp, char *buf,
83 char *p = buf; 96 char *p = buf;
84 int i; 97 int i;
85 98
86 BUG_ON(maxlen < 4); 99 BUG_ON(maxlen < 6);
87 for (i = 0; i < ARRAY_SIZE(opt_array); ++i) 100 for (i = 0; i < ARRAY_SIZE(opt_array); ++i)
88 if (dp->flags & opt_array[i].flag) 101 if (dp->flags & opt_array[i].flag)
89 *p++ = opt_array[i].opt_char; 102 *p++ = opt_array[i].opt_char;
90 if (p == buf) 103 if (p == buf)
91 *p++ = '-'; 104 *p++ = '_';
92 *p = '\0'; 105 *p = '\0';
93 106
94 return buf; 107 return buf;
95} 108}
96 109
110#define vpr_info_dq(q, msg) \
111do { \
112 if (verbose) \
113 /* trim last char off format print */ \
114 pr_info("%s: func=\"%s\" file=\"%s\" " \
115 "module=\"%s\" format=\"%.*s\" " \
116 "lineno=%u-%u", \
117 msg, \
118 q->function ? q->function : "", \
119 q->filename ? q->filename : "", \
120 q->module ? q->module : "", \
121 (int)(q->format ? strlen(q->format) - 1 : 0), \
122 q->format ? q->format : "", \
123 q->first_lineno, q->last_lineno); \
124} while (0)
125
97/* 126/*
98 * Search the tables for _ddebug's which match the given 127 * Search the tables for _ddebug's which match the given `query' and
99 * `query' and apply the `flags' and `mask' to them. Tells 128 * apply the `flags' and `mask' to them. Returns number of matching
100 * the user which ddebug's were changed, or whether none 129 * callsites, normally the same as number of changes. If verbose,
101 * were matched. 130 * logs the changes. Takes ddebug_lock.
102 */ 131 */
103static void ddebug_change(const struct ddebug_query *query, 132static int ddebug_change(const struct ddebug_query *query,
104 unsigned int flags, unsigned int mask) 133 unsigned int flags, unsigned int mask)
105{ 134{
106 int i; 135 int i;
107 struct ddebug_table *dt; 136 struct ddebug_table *dt;
108 unsigned int newflags; 137 unsigned int newflags;
109 unsigned int nfound = 0; 138 unsigned int nfound = 0;
110 char flagbuf[8]; 139 char flagbuf[10];
111 140
112 /* search for matching ddebugs */ 141 /* search for matching ddebugs */
113 mutex_lock(&ddebug_lock); 142 mutex_lock(&ddebug_lock);
114 list_for_each_entry(dt, &ddebug_tables, link) { 143 list_for_each_entry(dt, &ddebug_tables, link) {
115 144
116 /* match against the module name */ 145 /* match against the module name */
117 if (query->module != NULL && 146 if (query->module && strcmp(query->module, dt->mod_name))
118 strcmp(query->module, dt->mod_name))
119 continue; 147 continue;
120 148
121 for (i = 0 ; i < dt->num_ddebugs ; i++) { 149 for (i = 0 ; i < dt->num_ddebugs ; i++) {
122 struct _ddebug *dp = &dt->ddebugs[i]; 150 struct _ddebug *dp = &dt->ddebugs[i];
123 151
124 /* match against the source filename */ 152 /* match against the source filename */
125 if (query->filename != NULL && 153 if (query->filename &&
126 strcmp(query->filename, dp->filename) && 154 strcmp(query->filename, dp->filename) &&
127 strcmp(query->filename, basename(dp->filename))) 155 strcmp(query->filename, basename(dp->filename)) &&
156 strcmp(query->filename, trim_prefix(dp->filename)))
128 continue; 157 continue;
129 158
130 /* match against the function */ 159 /* match against the function */
131 if (query->function != NULL && 160 if (query->function &&
132 strcmp(query->function, dp->function)) 161 strcmp(query->function, dp->function))
133 continue; 162 continue;
134 163
135 /* match against the format */ 164 /* match against the format */
136 if (query->format != NULL && 165 if (query->format &&
137 strstr(dp->format, query->format) == NULL) 166 !strstr(dp->format, query->format))
138 continue; 167 continue;
139 168
140 /* match against the line number range */ 169 /* match against the line number range */
@@ -151,13 +180,9 @@ static void ddebug_change(const struct ddebug_query *query,
151 if (newflags == dp->flags) 180 if (newflags == dp->flags)
152 continue; 181 continue;
153 dp->flags = newflags; 182 dp->flags = newflags;
154 if (newflags)
155 dp->enabled = 1;
156 else
157 dp->enabled = 0;
158 if (verbose) 183 if (verbose)
159 pr_info("changed %s:%d [%s]%s %s\n", 184 pr_info("changed %s:%d [%s]%s =%s\n",
160 dp->filename, dp->lineno, 185 trim_prefix(dp->filename), dp->lineno,
161 dt->mod_name, dp->function, 186 dt->mod_name, dp->function,
162 ddebug_describe_flags(dp, flagbuf, 187 ddebug_describe_flags(dp, flagbuf,
163 sizeof(flagbuf))); 188 sizeof(flagbuf)));
@@ -167,6 +192,8 @@ static void ddebug_change(const struct ddebug_query *query,
167 192
168 if (!nfound && verbose) 193 if (!nfound && verbose)
169 pr_info("no matches for query\n"); 194 pr_info("no matches for query\n");
195
196 return nfound;
170} 197}
171 198
172/* 199/*
@@ -186,8 +213,10 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
186 buf = skip_spaces(buf); 213 buf = skip_spaces(buf);
187 if (!*buf) 214 if (!*buf)
188 break; /* oh, it was trailing whitespace */ 215 break; /* oh, it was trailing whitespace */
216 if (*buf == '#')
217 break; /* token starts comment, skip rest of line */
189 218
190 /* Run `end' over a word, either whitespace separated or quoted */ 219 /* find `end' of word, whitespace separated or quoted */
191 if (*buf == '"' || *buf == '\'') { 220 if (*buf == '"' || *buf == '\'') {
192 int quote = *buf++; 221 int quote = *buf++;
193 for (end = buf ; *end && *end != quote ; end++) 222 for (end = buf ; *end && *end != quote ; end++)
@@ -199,8 +228,8 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
199 ; 228 ;
200 BUG_ON(end == buf); 229 BUG_ON(end == buf);
201 } 230 }
202 /* Here `buf' is the start of the word, `end' is one past the end */
203 231
232 /* `buf' is start of word, `end' is one past its end */
204 if (nwords == maxwords) 233 if (nwords == maxwords)
205 return -EINVAL; /* ran out of words[] before bytes */ 234 return -EINVAL; /* ran out of words[] before bytes */
206 if (*end) 235 if (*end)
@@ -279,6 +308,19 @@ static char *unescape(char *str)
279 return str; 308 return str;
280} 309}
281 310
311static int check_set(const char **dest, char *src, char *name)
312{
313 int rc = 0;
314
315 if (*dest) {
316 rc = -EINVAL;
317 pr_err("match-spec:%s val:%s overridden by %s",
318 name, *dest, src);
319 }
320 *dest = src;
321 return rc;
322}
323
282/* 324/*
283 * Parse words[] as a ddebug query specification, which is a series 325 * Parse words[] as a ddebug query specification, which is a series
284 * of (keyword, value) pairs chosen from these possibilities: 326 * of (keyword, value) pairs chosen from these possibilities:
@@ -290,11 +332,15 @@ static char *unescape(char *str)
290 * format <escaped-string-to-find-in-format> 332 * format <escaped-string-to-find-in-format>
291 * line <lineno> 333 * line <lineno>
292 * line <first-lineno>-<last-lineno> // where either may be empty 334 * line <first-lineno>-<last-lineno> // where either may be empty
335 *
336 * Only 1 of each type is allowed.
337 * Returns 0 on success, <0 on error.
293 */ 338 */
294static int ddebug_parse_query(char *words[], int nwords, 339static int ddebug_parse_query(char *words[], int nwords,
295 struct ddebug_query *query) 340 struct ddebug_query *query)
296{ 341{
297 unsigned int i; 342 unsigned int i;
343 int rc;
298 344
299 /* check we have an even number of words */ 345 /* check we have an even number of words */
300 if (nwords % 2 != 0) 346 if (nwords % 2 != 0)
@@ -303,41 +349,43 @@ static int ddebug_parse_query(char *words[], int nwords,
303 349
304 for (i = 0 ; i < nwords ; i += 2) { 350 for (i = 0 ; i < nwords ; i += 2) {
305 if (!strcmp(words[i], "func")) 351 if (!strcmp(words[i], "func"))
306 query->function = words[i+1]; 352 rc = check_set(&query->function, words[i+1], "func");
307 else if (!strcmp(words[i], "file")) 353 else if (!strcmp(words[i], "file"))
308 query->filename = words[i+1]; 354 rc = check_set(&query->filename, words[i+1], "file");
309 else if (!strcmp(words[i], "module")) 355 else if (!strcmp(words[i], "module"))
310 query->module = words[i+1]; 356 rc = check_set(&query->module, words[i+1], "module");
311 else if (!strcmp(words[i], "format")) 357 else if (!strcmp(words[i], "format"))
312 query->format = unescape(words[i+1]); 358 rc = check_set(&query->format, unescape(words[i+1]),
359 "format");
313 else if (!strcmp(words[i], "line")) { 360 else if (!strcmp(words[i], "line")) {
314 char *first = words[i+1]; 361 char *first = words[i+1];
315 char *last = strchr(first, '-'); 362 char *last = strchr(first, '-');
363 if (query->first_lineno || query->last_lineno) {
364 pr_err("match-spec:line given 2 times\n");
365 return -EINVAL;
366 }
316 if (last) 367 if (last)
317 *last++ = '\0'; 368 *last++ = '\0';
318 if (parse_lineno(first, &query->first_lineno) < 0) 369 if (parse_lineno(first, &query->first_lineno) < 0)
319 return -EINVAL; 370 return -EINVAL;
320 if (last != NULL) { 371 if (last) {
321 /* range <first>-<last> */ 372 /* range <first>-<last> */
322 if (parse_lineno(last, &query->last_lineno) < 0) 373 if (parse_lineno(last, &query->last_lineno)
374 < query->first_lineno) {
375 pr_err("last-line < 1st-line\n");
323 return -EINVAL; 376 return -EINVAL;
377 }
324 } else { 378 } else {
325 query->last_lineno = query->first_lineno; 379 query->last_lineno = query->first_lineno;
326 } 380 }
327 } else { 381 } else {
328 if (verbose) 382 pr_err("unknown keyword \"%s\"\n", words[i]);
329 pr_err("unknown keyword \"%s\"\n", words[i]);
330 return -EINVAL; 383 return -EINVAL;
331 } 384 }
385 if (rc)
386 return rc;
332 } 387 }
333 388 vpr_info_dq(query, "parsed");
334 if (verbose)
335 pr_info("q->function=\"%s\" q->filename=\"%s\" "
336 "q->module=\"%s\" q->format=\"%s\" q->lineno=%u-%u\n",
337 query->function, query->filename,
338 query->module, query->format, query->first_lineno,
339 query->last_lineno);
340
341 return 0; 389 return 0;
342} 390}
343 391
@@ -375,8 +423,6 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
375 if (i < 0) 423 if (i < 0)
376 return -EINVAL; 424 return -EINVAL;
377 } 425 }
378 if (flags == 0)
379 return -EINVAL;
380 if (verbose) 426 if (verbose)
381 pr_info("flags=0x%x\n", flags); 427 pr_info("flags=0x%x\n", flags);
382 428
@@ -405,7 +451,7 @@ static int ddebug_exec_query(char *query_string)
405 unsigned int flags = 0, mask = 0; 451 unsigned int flags = 0, mask = 0;
406 struct ddebug_query query; 452 struct ddebug_query query;
407#define MAXWORDS 9 453#define MAXWORDS 9
408 int nwords; 454 int nwords, nfound;
409 char *words[MAXWORDS]; 455 char *words[MAXWORDS];
410 456
411 nwords = ddebug_tokenize(query_string, words, MAXWORDS); 457 nwords = ddebug_tokenize(query_string, words, MAXWORDS);
@@ -417,8 +463,47 @@ static int ddebug_exec_query(char *query_string)
417 return -EINVAL; 463 return -EINVAL;
418 464
419 /* actually go and implement the change */ 465 /* actually go and implement the change */
420 ddebug_change(&query, flags, mask); 466 nfound = ddebug_change(&query, flags, mask);
421 return 0; 467 vpr_info_dq((&query), (nfound) ? "applied" : "no-match");
468
469 return nfound;
470}
471
472/* handle multiple queries in query string, continue on error, return
473 last error or number of matching callsites. Module name is either
474 in param (for boot arg) or perhaps in query string.
475*/
476static int ddebug_exec_queries(char *query)
477{
478 char *split;
479 int i, errs = 0, exitcode = 0, rc, nfound = 0;
480
481 for (i = 0; query; query = split) {
482 split = strpbrk(query, ";\n");
483 if (split)
484 *split++ = '\0';
485
486 query = skip_spaces(query);
487 if (!query || !*query || *query == '#')
488 continue;
489
490 if (verbose)
491 pr_info("query %d: \"%s\"\n", i, query);
492
493 rc = ddebug_exec_query(query);
494 if (rc < 0) {
495 errs++;
496 exitcode = rc;
497 } else
498 nfound += rc;
499 i++;
500 }
501 pr_info("processed %d queries, with %d matches, %d errs\n",
502 i, nfound, errs);
503
504 if (exitcode)
505 return exitcode;
506 return nfound;
422} 507}
423 508
424#define PREFIX_SIZE 64 509#define PREFIX_SIZE 64
@@ -452,7 +537,8 @@ static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf)
452 pos += snprintf(buf + pos, remaining(pos), "%s:", 537 pos += snprintf(buf + pos, remaining(pos), "%s:",
453 desc->function); 538 desc->function);
454 if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO) 539 if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO)
455 pos += snprintf(buf + pos, remaining(pos), "%d:", desc->lineno); 540 pos += snprintf(buf + pos, remaining(pos), "%d:",
541 desc->lineno);
456 if (pos - pos_after_tid) 542 if (pos - pos_after_tid)
457 pos += snprintf(buf + pos, remaining(pos), " "); 543 pos += snprintf(buf + pos, remaining(pos), " ");
458 if (pos >= PREFIX_SIZE) 544 if (pos >= PREFIX_SIZE)
@@ -527,14 +613,16 @@ EXPORT_SYMBOL(__dynamic_netdev_dbg);
527 613
528#endif 614#endif
529 615
530static __initdata char ddebug_setup_string[1024]; 616#define DDEBUG_STRING_SIZE 1024
617static __initdata char ddebug_setup_string[DDEBUG_STRING_SIZE];
618
531static __init int ddebug_setup_query(char *str) 619static __init int ddebug_setup_query(char *str)
532{ 620{
533 if (strlen(str) >= 1024) { 621 if (strlen(str) >= DDEBUG_STRING_SIZE) {
534 pr_warn("ddebug boot param string too large\n"); 622 pr_warn("ddebug boot param string too large\n");
535 return 0; 623 return 0;
536 } 624 }
537 strcpy(ddebug_setup_string, str); 625 strlcpy(ddebug_setup_string, str, DDEBUG_STRING_SIZE);
538 return 1; 626 return 1;
539} 627}
540 628
@@ -544,25 +632,33 @@ __setup("ddebug_query=", ddebug_setup_query);
544 * File_ops->write method for <debugfs>/dynamic_debug/conrol. Gathers the 632 * File_ops->write method for <debugfs>/dynamic_debug/conrol. Gathers the
545 * command text from userspace, parses and executes it. 633 * command text from userspace, parses and executes it.
546 */ 634 */
635#define USER_BUF_PAGE 4096
547static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, 636static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
548 size_t len, loff_t *offp) 637 size_t len, loff_t *offp)
549{ 638{
550 char tmpbuf[256]; 639 char *tmpbuf;
551 int ret; 640 int ret;
552 641
553 if (len == 0) 642 if (len == 0)
554 return 0; 643 return 0;
555 /* we don't check *offp -- multiple writes() are allowed */ 644 if (len > USER_BUF_PAGE - 1) {
556 if (len > sizeof(tmpbuf)-1) 645 pr_warn("expected <%d bytes into control\n", USER_BUF_PAGE);
557 return -E2BIG; 646 return -E2BIG;
558 if (copy_from_user(tmpbuf, ubuf, len)) 647 }
648 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
649 if (!tmpbuf)
650 return -ENOMEM;
651 if (copy_from_user(tmpbuf, ubuf, len)) {
652 kfree(tmpbuf);
559 return -EFAULT; 653 return -EFAULT;
654 }
560 tmpbuf[len] = '\0'; 655 tmpbuf[len] = '\0';
561 if (verbose) 656 if (verbose)
562 pr_info("read %d bytes from userspace\n", (int)len); 657 pr_info("read %d bytes from userspace\n", (int)len);
563 658
564 ret = ddebug_exec_query(tmpbuf); 659 ret = ddebug_exec_queries(tmpbuf);
565 if (ret) 660 kfree(tmpbuf);
661 if (ret < 0)
566 return ret; 662 return ret;
567 663
568 *offp += len; 664 *offp += len;
@@ -668,7 +764,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
668{ 764{
669 struct ddebug_iter *iter = m->private; 765 struct ddebug_iter *iter = m->private;
670 struct _ddebug *dp = p; 766 struct _ddebug *dp = p;
671 char flagsbuf[8]; 767 char flagsbuf[10];
672 768
673 if (verbose) 769 if (verbose)
674 pr_info("called m=%p p=%p\n", m, p); 770 pr_info("called m=%p p=%p\n", m, p);
@@ -679,10 +775,10 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
679 return 0; 775 return 0;
680 } 776 }
681 777
682 seq_printf(m, "%s:%u [%s]%s %s \"", 778 seq_printf(m, "%s:%u [%s]%s =%s \"",
683 dp->filename, dp->lineno, 779 trim_prefix(dp->filename), dp->lineno,
684 iter->table->mod_name, dp->function, 780 iter->table->mod_name, dp->function,
685 ddebug_describe_flags(dp, flagsbuf, sizeof(flagsbuf))); 781 ddebug_describe_flags(dp, flagsbuf, sizeof(flagsbuf)));
686 seq_escape(m, dp->format, "\t\r\n\""); 782 seq_escape(m, dp->format, "\t\r\n\"");
687 seq_puts(m, "\"\n"); 783 seq_puts(m, "\"\n");
688 784
@@ -708,10 +804,11 @@ static const struct seq_operations ddebug_proc_seqops = {
708}; 804};
709 805
710/* 806/*
711 * File_ops->open method for <debugfs>/dynamic_debug/control. Does the seq_file 807 * File_ops->open method for <debugfs>/dynamic_debug/control. Does
712 * setup dance, and also creates an iterator to walk the _ddebugs. 808 * the seq_file setup dance, and also creates an iterator to walk the
713 * Note that we create a seq_file always, even for O_WRONLY files 809 * _ddebugs. Note that we create a seq_file always, even for O_WRONLY
714 * where it's not needed, as doing so simplifies the ->release method. 810 * files where it's not needed, as doing so simplifies the ->release
811 * method.
715 */ 812 */
716static int ddebug_proc_open(struct inode *inode, struct file *file) 813static int ddebug_proc_open(struct inode *inode, struct file *file)
717{ 814{
@@ -846,33 +943,40 @@ static int __init dynamic_debug_init(void)
846 int ret = 0; 943 int ret = 0;
847 int n = 0; 944 int n = 0;
848 945
849 if (__start___verbose != __stop___verbose) { 946 if (__start___verbose == __stop___verbose) {
850 iter = __start___verbose; 947 pr_warn("_ddebug table is empty in a "
851 modname = iter->modname; 948 "CONFIG_DYNAMIC_DEBUG build");
852 iter_start = iter; 949 return 1;
853 for (; iter < __stop___verbose; iter++) { 950 }
854 if (strcmp(modname, iter->modname)) { 951 iter = __start___verbose;
855 ret = ddebug_add_module(iter_start, n, modname); 952 modname = iter->modname;
856 if (ret) 953 iter_start = iter;
857 goto out_free; 954 for (; iter < __stop___verbose; iter++) {
858 n = 0; 955 if (strcmp(modname, iter->modname)) {
859 modname = iter->modname; 956 ret = ddebug_add_module(iter_start, n, modname);
860 iter_start = iter; 957 if (ret)
861 } 958 goto out_free;
862 n++; 959 n = 0;
960 modname = iter->modname;
961 iter_start = iter;
863 } 962 }
864 ret = ddebug_add_module(iter_start, n, modname); 963 n++;
865 } 964 }
965 ret = ddebug_add_module(iter_start, n, modname);
966 if (ret)
967 goto out_free;
866 968
867 /* ddebug_query boot param got passed -> set it up */ 969 /* ddebug_query boot param got passed -> set it up */
868 if (ddebug_setup_string[0] != '\0') { 970 if (ddebug_setup_string[0] != '\0') {
869 ret = ddebug_exec_query(ddebug_setup_string); 971 ret = ddebug_exec_queries(ddebug_setup_string);
870 if (ret) 972 if (ret < 0)
871 pr_warn("Invalid ddebug boot param %s", 973 pr_warn("Invalid ddebug boot param %s",
872 ddebug_setup_string); 974 ddebug_setup_string);
873 else 975 else
874 pr_info("ddebug initialized with string %s", 976 pr_info("%d changes by ddebug_query\n", ret);
875 ddebug_setup_string); 977
978 /* keep tables even on ddebug_query parse error */
979 ret = 0;
876 } 980 }
877 981
878out_free: 982out_free:
diff --git a/lib/dynamic_queue_limits.c b/lib/dynamic_queue_limits.c
index 3d1bdcdd7db4..6ab4587d052b 100644
--- a/lib/dynamic_queue_limits.c
+++ b/lib/dynamic_queue_limits.c
@@ -7,6 +7,7 @@
7#include <linux/types.h> 7#include <linux/types.h>
8#include <linux/ctype.h> 8#include <linux/ctype.h>
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/jiffies.h>
10#include <linux/dynamic_queue_limits.h> 11#include <linux/dynamic_queue_limits.h>
11 12
12#define POSDIFF(A, B) ((A) > (B) ? (A) - (B) : 0) 13#define POSDIFF(A, B) ((A) > (B) ? (A) - (B) : 0)
diff --git a/lib/fault-inject.c b/lib/fault-inject.c
index b4801f51b607..6805453c18e7 100644
--- a/lib/fault-inject.c
+++ b/lib/fault-inject.c
@@ -5,7 +5,7 @@
5#include <linux/stat.h> 5#include <linux/stat.h>
6#include <linux/types.h> 6#include <linux/types.h>
7#include <linux/fs.h> 7#include <linux/fs.h>
8#include <linux/module.h> 8#include <linux/export.h>
9#include <linux/interrupt.h> 9#include <linux/interrupt.h>
10#include <linux/stacktrace.h> 10#include <linux/stacktrace.h>
11#include <linux/fault-inject.h> 11#include <linux/fault-inject.h>
diff --git a/lib/find_last_bit.c b/lib/find_last_bit.c
index d903959ad695..91ca09fbf6f9 100644
--- a/lib/find_last_bit.c
+++ b/lib/find_last_bit.c
@@ -11,7 +11,7 @@
11 */ 11 */
12 12
13#include <linux/bitops.h> 13#include <linux/bitops.h>
14#include <linux/module.h> 14#include <linux/export.h>
15#include <asm/types.h> 15#include <asm/types.h>
16#include <asm/byteorder.h> 16#include <asm/byteorder.h>
17 17
diff --git a/lib/find_next_bit.c b/lib/find_next_bit.c
index 4bd75a73ba00..0cbfc0b4398f 100644
--- a/lib/find_next_bit.c
+++ b/lib/find_next_bit.c
@@ -10,7 +10,7 @@
10 */ 10 */
11 11
12#include <linux/bitops.h> 12#include <linux/bitops.h>
13#include <linux/module.h> 13#include <linux/export.h>
14#include <asm/types.h> 14#include <asm/types.h>
15#include <asm/byteorder.h> 15#include <asm/byteorder.h>
16 16
diff --git a/lib/flex_array.c b/lib/flex_array.c
index 9b8b89458c4c..6948a6692fc4 100644
--- a/lib/flex_array.c
+++ b/lib/flex_array.c
@@ -23,7 +23,7 @@
23#include <linux/flex_array.h> 23#include <linux/flex_array.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/stddef.h> 25#include <linux/stddef.h>
26#include <linux/module.h> 26#include <linux/export.h>
27#include <linux/reciprocal_div.h> 27#include <linux/reciprocal_div.h>
28 28
29struct flex_array_part { 29struct flex_array_part {
diff --git a/lib/gcd.c b/lib/gcd.c
index f879033d9822..cce4f3cd14b3 100644
--- a/lib/gcd.c
+++ b/lib/gcd.c
@@ -1,6 +1,6 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/gcd.h> 2#include <linux/gcd.h>
3#include <linux/module.h> 3#include <linux/export.h>
4 4
5/* Greatest common divisor */ 5/* Greatest common divisor */
6unsigned long gcd(unsigned long a, unsigned long b) 6unsigned long gcd(unsigned long a, unsigned long b)
diff --git a/lib/gen_crc32table.c b/lib/gen_crc32table.c
index 85d0e412a04f..8f8d5439e2d9 100644
--- a/lib/gen_crc32table.c
+++ b/lib/gen_crc32table.c
@@ -1,14 +1,29 @@
1#include <stdio.h> 1#include <stdio.h>
2#include "../include/generated/autoconf.h"
2#include "crc32defs.h" 3#include "crc32defs.h"
3#include <inttypes.h> 4#include <inttypes.h>
4 5
5#define ENTRIES_PER_LINE 4 6#define ENTRIES_PER_LINE 4
6 7
7#define LE_TABLE_SIZE (1 << CRC_LE_BITS) 8#if CRC_LE_BITS > 8
8#define BE_TABLE_SIZE (1 << CRC_BE_BITS) 9# define LE_TABLE_ROWS (CRC_LE_BITS/8)
10# define LE_TABLE_SIZE 256
11#else
12# define LE_TABLE_ROWS 1
13# define LE_TABLE_SIZE (1 << CRC_LE_BITS)
14#endif
9 15
10static uint32_t crc32table_le[4][LE_TABLE_SIZE]; 16#if CRC_BE_BITS > 8
11static uint32_t crc32table_be[4][BE_TABLE_SIZE]; 17# define BE_TABLE_ROWS (CRC_BE_BITS/8)
18# define BE_TABLE_SIZE 256
19#else
20# define BE_TABLE_ROWS 1
21# define BE_TABLE_SIZE (1 << CRC_BE_BITS)
22#endif
23
24static uint32_t crc32table_le[LE_TABLE_ROWS][256];
25static uint32_t crc32table_be[BE_TABLE_ROWS][256];
26static uint32_t crc32ctable_le[LE_TABLE_ROWS][256];
12 27
13/** 28/**
14 * crc32init_le() - allocate and initialize LE table data 29 * crc32init_le() - allocate and initialize LE table data
@@ -17,27 +32,38 @@ static uint32_t crc32table_be[4][BE_TABLE_SIZE];
17 * fact that crctable[i^j] = crctable[i] ^ crctable[j]. 32 * fact that crctable[i^j] = crctable[i] ^ crctable[j].
18 * 33 *
19 */ 34 */
20static void crc32init_le(void) 35static void crc32init_le_generic(const uint32_t polynomial,
36 uint32_t (*tab)[256])
21{ 37{
22 unsigned i, j; 38 unsigned i, j;
23 uint32_t crc = 1; 39 uint32_t crc = 1;
24 40
25 crc32table_le[0][0] = 0; 41 tab[0][0] = 0;
26 42
27 for (i = 1 << (CRC_LE_BITS - 1); i; i >>= 1) { 43 for (i = LE_TABLE_SIZE >> 1; i; i >>= 1) {
28 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); 44 crc = (crc >> 1) ^ ((crc & 1) ? polynomial : 0);
29 for (j = 0; j < LE_TABLE_SIZE; j += 2 * i) 45 for (j = 0; j < LE_TABLE_SIZE; j += 2 * i)
30 crc32table_le[0][i + j] = crc ^ crc32table_le[0][j]; 46 tab[0][i + j] = crc ^ tab[0][j];
31 } 47 }
32 for (i = 0; i < LE_TABLE_SIZE; i++) { 48 for (i = 0; i < LE_TABLE_SIZE; i++) {
33 crc = crc32table_le[0][i]; 49 crc = tab[0][i];
34 for (j = 1; j < 4; j++) { 50 for (j = 1; j < LE_TABLE_ROWS; j++) {
35 crc = crc32table_le[0][crc & 0xff] ^ (crc >> 8); 51 crc = tab[0][crc & 0xff] ^ (crc >> 8);
36 crc32table_le[j][i] = crc; 52 tab[j][i] = crc;
37 } 53 }
38 } 54 }
39} 55}
40 56
57static void crc32init_le(void)
58{
59 crc32init_le_generic(CRCPOLY_LE, crc32table_le);
60}
61
62static void crc32cinit_le(void)
63{
64 crc32init_le_generic(CRC32C_POLY_LE, crc32ctable_le);
65}
66
41/** 67/**
42 * crc32init_be() - allocate and initialize BE table data 68 * crc32init_be() - allocate and initialize BE table data
43 */ 69 */
@@ -55,18 +81,18 @@ static void crc32init_be(void)
55 } 81 }
56 for (i = 0; i < BE_TABLE_SIZE; i++) { 82 for (i = 0; i < BE_TABLE_SIZE; i++) {
57 crc = crc32table_be[0][i]; 83 crc = crc32table_be[0][i];
58 for (j = 1; j < 4; j++) { 84 for (j = 1; j < BE_TABLE_ROWS; j++) {
59 crc = crc32table_be[0][(crc >> 24) & 0xff] ^ (crc << 8); 85 crc = crc32table_be[0][(crc >> 24) & 0xff] ^ (crc << 8);
60 crc32table_be[j][i] = crc; 86 crc32table_be[j][i] = crc;
61 } 87 }
62 } 88 }
63} 89}
64 90
65static void output_table(uint32_t table[4][256], int len, char *trans) 91static void output_table(uint32_t (*table)[256], int rows, int len, char *trans)
66{ 92{
67 int i, j; 93 int i, j;
68 94
69 for (j = 0 ; j < 4; j++) { 95 for (j = 0 ; j < rows; j++) {
70 printf("{"); 96 printf("{");
71 for (i = 0; i < len - 1; i++) { 97 for (i = 0; i < len - 1; i++) {
72 if (i % ENTRIES_PER_LINE == 0) 98 if (i % ENTRIES_PER_LINE == 0)
@@ -83,15 +109,30 @@ int main(int argc, char** argv)
83 109
84 if (CRC_LE_BITS > 1) { 110 if (CRC_LE_BITS > 1) {
85 crc32init_le(); 111 crc32init_le();
86 printf("static const u32 crc32table_le[4][256] = {"); 112 printf("static const u32 __cacheline_aligned "
87 output_table(crc32table_le, LE_TABLE_SIZE, "tole"); 113 "crc32table_le[%d][%d] = {",
114 LE_TABLE_ROWS, LE_TABLE_SIZE);
115 output_table(crc32table_le, LE_TABLE_ROWS,
116 LE_TABLE_SIZE, "tole");
88 printf("};\n"); 117 printf("};\n");
89 } 118 }
90 119
91 if (CRC_BE_BITS > 1) { 120 if (CRC_BE_BITS > 1) {
92 crc32init_be(); 121 crc32init_be();
93 printf("static const u32 crc32table_be[4][256] = {"); 122 printf("static const u32 __cacheline_aligned "
94 output_table(crc32table_be, BE_TABLE_SIZE, "tobe"); 123 "crc32table_be[%d][%d] = {",
124 BE_TABLE_ROWS, BE_TABLE_SIZE);
125 output_table(crc32table_be, LE_TABLE_ROWS,
126 BE_TABLE_SIZE, "tobe");
127 printf("};\n");
128 }
129 if (CRC_LE_BITS > 1) {
130 crc32cinit_le();
131 printf("static const u32 __cacheline_aligned "
132 "crc32ctable_le[%d][%d] = {",
133 LE_TABLE_ROWS, LE_TABLE_SIZE);
134 output_table(crc32ctable_le, LE_TABLE_ROWS,
135 LE_TABLE_SIZE, "tole");
95 printf("};\n"); 136 printf("};\n");
96 } 137 }
97 138
diff --git a/lib/genalloc.c b/lib/genalloc.c
index f352cc42f4f8..6bc04aab6ec7 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -29,7 +29,7 @@
29 */ 29 */
30 30
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/module.h> 32#include <linux/export.h>
33#include <linux/bitmap.h> 33#include <linux/bitmap.h>
34#include <linux/rculist.h> 34#include <linux/rculist.h>
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
diff --git a/lib/halfmd4.c b/lib/halfmd4.c
index e11db26f8ae5..66d0ee8b7776 100644
--- a/lib/halfmd4.c
+++ b/lib/halfmd4.c
@@ -1,5 +1,5 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/module.h> 2#include <linux/export.h>
3#include <linux/cryptohash.h> 3#include <linux/cryptohash.h>
4 4
5/* F, G and H are basic MD4 functions: selection, majority, parity */ 5/* F, G and H are basic MD4 functions: selection, majority, parity */
diff --git a/lib/hexdump.c b/lib/hexdump.c
index 51d5ae210244..6540d657dca4 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -10,7 +10,7 @@
10#include <linux/types.h> 10#include <linux/types.h>
11#include <linux/ctype.h> 11#include <linux/ctype.h>
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/module.h> 13#include <linux/export.h>
14 14
15const char hex_asc[] = "0123456789abcdef"; 15const char hex_asc[] = "0123456789abcdef";
16EXPORT_SYMBOL(hex_asc); 16EXPORT_SYMBOL(hex_asc);
diff --git a/lib/hweight.c b/lib/hweight.c
index 3c79d50814cf..b7d81ba143d1 100644
--- a/lib/hweight.c
+++ b/lib/hweight.c
@@ -1,4 +1,4 @@
1#include <linux/module.h> 1#include <linux/export.h>
2#include <linux/bitops.h> 2#include <linux/bitops.h>
3#include <asm/types.h> 3#include <asm/types.h>
4 4
diff --git a/lib/idr.c b/lib/idr.c
index ed055b297c81..4046e29c0a99 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -29,7 +29,7 @@
29#ifndef TEST // to test in user space... 29#ifndef TEST // to test in user space...
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/module.h> 32#include <linux/export.h>
33#endif 33#endif
34#include <linux/err.h> 34#include <linux/err.h>
35#include <linux/string.h> 35#include <linux/string.h>
@@ -595,8 +595,10 @@ EXPORT_SYMBOL(idr_for_each);
595 * Returns pointer to registered object with id, which is next number to 595 * Returns pointer to registered object with id, which is next number to
596 * given id. After being looked up, *@nextidp will be updated for the next 596 * given id. After being looked up, *@nextidp will be updated for the next
597 * iteration. 597 * iteration.
598 *
599 * This function can be called under rcu_read_lock(), given that the leaf
600 * pointers lifetimes are correctly managed.
598 */ 601 */
599
600void *idr_get_next(struct idr *idp, int *nextidp) 602void *idr_get_next(struct idr *idp, int *nextidp)
601{ 603{
602 struct idr_layer *p, *pa[MAX_LEVEL]; 604 struct idr_layer *p, *pa[MAX_LEVEL];
@@ -605,11 +607,11 @@ void *idr_get_next(struct idr *idp, int *nextidp)
605 int n, max; 607 int n, max;
606 608
607 /* find first ent */ 609 /* find first ent */
608 n = idp->layers * IDR_BITS;
609 max = 1 << n;
610 p = rcu_dereference_raw(idp->top); 610 p = rcu_dereference_raw(idp->top);
611 if (!p) 611 if (!p)
612 return NULL; 612 return NULL;
613 n = (p->layer + 1) * IDR_BITS;
614 max = 1 << n;
613 615
614 while (id < max) { 616 while (id < max) {
615 while (n > 0 && p) { 617 while (n > 0 && p) {
diff --git a/lib/int_sqrt.c b/lib/int_sqrt.c
index fd355a99327c..fc2eeb7cb2ea 100644
--- a/lib/int_sqrt.c
+++ b/lib/int_sqrt.c
@@ -1,6 +1,6 @@
1 1
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/module.h> 3#include <linux/export.h>
4 4
5/** 5/**
6 * int_sqrt - rough approximation to sqrt 6 * int_sqrt - rough approximation to sqrt
diff --git a/lib/iomap.c b/lib/iomap.c
index ada922a808e6..2c08f36862eb 100644
--- a/lib/iomap.c
+++ b/lib/iomap.c
@@ -6,7 +6,7 @@
6#include <linux/pci.h> 6#include <linux/pci.h>
7#include <linux/io.h> 7#include <linux/io.h>
8 8
9#include <linux/module.h> 9#include <linux/export.h>
10 10
11/* 11/*
12 * Read/write from/to an (offsettable) iomem cookie. It might be a PIO 12 * Read/write from/to an (offsettable) iomem cookie. It might be a PIO
diff --git a/lib/iomap_copy.c b/lib/iomap_copy.c
index 864fc5ea398c..4527e751b5e0 100644
--- a/lib/iomap_copy.c
+++ b/lib/iomap_copy.c
@@ -15,7 +15,7 @@
15 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 15 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
16 */ 16 */
17 17
18#include <linux/module.h> 18#include <linux/export.h>
19#include <linux/io.h> 19#include <linux/io.h>
20 20
21/** 21/**
diff --git a/lib/iommu-helper.c b/lib/iommu-helper.c
index da053313ee5c..c27e269210c4 100644
--- a/lib/iommu-helper.c
+++ b/lib/iommu-helper.c
@@ -2,8 +2,9 @@
2 * IOMMU helper functions for the free area management 2 * IOMMU helper functions for the free area management
3 */ 3 */
4 4
5#include <linux/module.h> 5#include <linux/export.h>
6#include <linux/bitmap.h> 6#include <linux/bitmap.h>
7#include <linux/bug.h>
7 8
8int iommu_is_span_boundary(unsigned int index, unsigned int nr, 9int iommu_is_span_boundary(unsigned int index, unsigned int nr,
9 unsigned long shift, 10 unsigned long shift,
diff --git a/lib/ioremap.c b/lib/ioremap.c
index da4e2ad74b68..0c9216c48762 100644
--- a/lib/ioremap.c
+++ b/lib/ioremap.c
@@ -9,7 +9,7 @@
9#include <linux/mm.h> 9#include <linux/mm.h>
10#include <linux/sched.h> 10#include <linux/sched.h>
11#include <linux/io.h> 11#include <linux/io.h>
12#include <linux/module.h> 12#include <linux/export.h>
13#include <asm/cacheflush.h> 13#include <asm/cacheflush.h>
14#include <asm/pgtable.h> 14#include <asm/pgtable.h>
15 15
diff --git a/lib/irq_regs.c b/lib/irq_regs.c
index 753880a5440c..9c0a1d70fbe8 100644
--- a/lib/irq_regs.c
+++ b/lib/irq_regs.c
@@ -8,7 +8,8 @@
8 * as published by the Free Software Foundation; either version 8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version. 9 * 2 of the License, or (at your option) any later version.
10 */ 10 */
11#include <linux/module.h> 11#include <linux/export.h>
12#include <linux/percpu.h>
12#include <asm/irq_regs.h> 13#include <asm/irq_regs.h>
13 14
14#ifndef ARCH_HAS_OWN_IRQ_REGS 15#ifndef ARCH_HAS_OWN_IRQ_REGS
diff --git a/lib/kasprintf.c b/lib/kasprintf.c
index 9c4233b23783..ae0de80c1c88 100644
--- a/lib/kasprintf.c
+++ b/lib/kasprintf.c
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7#include <stdarg.h> 7#include <stdarg.h>
8#include <linux/module.h> 8#include <linux/export.h>
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/types.h> 10#include <linux/types.h>
11#include <linux/string.h> 11#include <linux/string.h>
diff --git a/lib/klist.c b/lib/klist.c
index 573d6068a42e..0874e41609a6 100644
--- a/lib/klist.c
+++ b/lib/klist.c
@@ -35,7 +35,7 @@
35 */ 35 */
36 36
37#include <linux/klist.h> 37#include <linux/klist.h>
38#include <linux/module.h> 38#include <linux/export.h>
39#include <linux/sched.h> 39#include <linux/sched.h>
40 40
41/* 41/*
diff --git a/lib/kobject.c b/lib/kobject.c
index c33d7a18d635..aeefa8bc8b1c 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -14,7 +14,7 @@
14 14
15#include <linux/kobject.h> 15#include <linux/kobject.h>
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/module.h> 17#include <linux/export.h>
18#include <linux/stat.h> 18#include <linux/stat.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20 20
@@ -192,14 +192,14 @@ static int kobject_add_internal(struct kobject *kobj)
192 192
193 /* be noisy on error issues */ 193 /* be noisy on error issues */
194 if (error == -EEXIST) 194 if (error == -EEXIST)
195 printk(KERN_ERR "%s failed for %s with " 195 WARN(1, "%s failed for %s with "
196 "-EEXIST, don't try to register things with " 196 "-EEXIST, don't try to register things with "
197 "the same name in the same directory.\n", 197 "the same name in the same directory.\n",
198 __func__, kobject_name(kobj)); 198 __func__, kobject_name(kobj));
199 else 199 else
200 printk(KERN_ERR "%s failed for %s (%d)\n", 200 WARN(1, "%s failed for %s (error: %d parent: %s)\n",
201 __func__, kobject_name(kobj), error); 201 __func__, kobject_name(kobj), error,
202 dump_stack(); 202 parent ? kobject_name(parent) : "'none'");
203 } else 203 } else
204 kobj->state_in_sysfs = 1; 204 kobj->state_in_sysfs = 1;
205 205
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index e66e9b632617..1a91efa6d121 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -17,7 +17,8 @@
17#include <linux/spinlock.h> 17#include <linux/spinlock.h>
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/export.h>
21#include <linux/kmod.h>
21#include <linux/slab.h> 22#include <linux/slab.h>
22#include <linux/user_namespace.h> 23#include <linux/user_namespace.h>
23#include <linux/socket.h> 24#include <linux/socket.h>
@@ -29,16 +30,17 @@
29 30
30u64 uevent_seqnum; 31u64 uevent_seqnum;
31char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH; 32char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH;
32static DEFINE_SPINLOCK(sequence_lock);
33#ifdef CONFIG_NET 33#ifdef CONFIG_NET
34struct uevent_sock { 34struct uevent_sock {
35 struct list_head list; 35 struct list_head list;
36 struct sock *sk; 36 struct sock *sk;
37}; 37};
38static LIST_HEAD(uevent_sock_list); 38static LIST_HEAD(uevent_sock_list);
39static DEFINE_MUTEX(uevent_sock_mutex);
40#endif 39#endif
41 40
41/* This lock protects uevent_seqnum and uevent_sock_list */
42static DEFINE_MUTEX(uevent_sock_mutex);
43
42/* the strings here must match the enum in include/linux/kobject.h */ 44/* the strings here must match the enum in include/linux/kobject.h */
43static const char *kobject_actions[] = { 45static const char *kobject_actions[] = {
44 [KOBJ_ADD] = "add", 46 [KOBJ_ADD] = "add",
@@ -136,7 +138,6 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
136 struct kobject *top_kobj; 138 struct kobject *top_kobj;
137 struct kset *kset; 139 struct kset *kset;
138 const struct kset_uevent_ops *uevent_ops; 140 const struct kset_uevent_ops *uevent_ops;
139 u64 seq;
140 int i = 0; 141 int i = 0;
141 int retval = 0; 142 int retval = 0;
142#ifdef CONFIG_NET 143#ifdef CONFIG_NET
@@ -243,17 +244,16 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
243 else if (action == KOBJ_REMOVE) 244 else if (action == KOBJ_REMOVE)
244 kobj->state_remove_uevent_sent = 1; 245 kobj->state_remove_uevent_sent = 1;
245 246
247 mutex_lock(&uevent_sock_mutex);
246 /* we will send an event, so request a new sequence number */ 248 /* we will send an event, so request a new sequence number */
247 spin_lock(&sequence_lock); 249 retval = add_uevent_var(env, "SEQNUM=%llu", (unsigned long long)++uevent_seqnum);
248 seq = ++uevent_seqnum; 250 if (retval) {
249 spin_unlock(&sequence_lock); 251 mutex_unlock(&uevent_sock_mutex);
250 retval = add_uevent_var(env, "SEQNUM=%llu", (unsigned long long)seq);
251 if (retval)
252 goto exit; 252 goto exit;
253 }
253 254
254#if defined(CONFIG_NET) 255#if defined(CONFIG_NET)
255 /* send netlink message */ 256 /* send netlink message */
256 mutex_lock(&uevent_sock_mutex);
257 list_for_each_entry(ue_sk, &uevent_sock_list, list) { 257 list_for_each_entry(ue_sk, &uevent_sock_list, list) {
258 struct sock *uevent_sock = ue_sk->sk; 258 struct sock *uevent_sock = ue_sk->sk;
259 struct sk_buff *skb; 259 struct sk_buff *skb;
@@ -290,8 +290,8 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
290 } else 290 } else
291 retval = -ENOMEM; 291 retval = -ENOMEM;
292 } 292 }
293 mutex_unlock(&uevent_sock_mutex);
294#endif 293#endif
294 mutex_unlock(&uevent_sock_mutex);
295 295
296 /* call uevent_helper, usually only enabled during early boot */ 296 /* call uevent_helper, usually only enabled during early boot */
297 if (uevent_helper[0] && !kobj_usermode_filter(kobj)) { 297 if (uevent_helper[0] && !kobj_usermode_filter(kobj)) {
diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index 7a94c8f14e29..c3615eab0cc3 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -15,7 +15,7 @@
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/math64.h> 17#include <linux/math64.h>
18#include <linux/module.h> 18#include <linux/export.h>
19#include <linux/types.h> 19#include <linux/types.h>
20#include <asm/uaccess.h> 20#include <asm/uaccess.h>
21#include "kstrtox.h" 21#include "kstrtox.h"
@@ -44,12 +44,13 @@ const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
44 * 44 *
45 * Don't you dare use this function. 45 * Don't you dare use this function.
46 */ 46 */
47unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *res) 47unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p)
48{ 48{
49 unsigned long long res;
49 unsigned int rv; 50 unsigned int rv;
50 int overflow; 51 int overflow;
51 52
52 *res = 0; 53 res = 0;
53 rv = 0; 54 rv = 0;
54 overflow = 0; 55 overflow = 0;
55 while (*s) { 56 while (*s) {
@@ -64,12 +65,19 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long
64 65
65 if (val >= base) 66 if (val >= base)
66 break; 67 break;
67 if (*res > div_u64(ULLONG_MAX - val, base)) 68 /*
68 overflow = 1; 69 * Check for overflow only if we are within range of
69 *res = *res * base + val; 70 * it in the max base we support (16)
71 */
72 if (unlikely(res & (~0ull << 60))) {
73 if (res > div_u64(ULLONG_MAX - val, base))
74 overflow = 1;
75 }
76 res = res * base + val;
70 rv++; 77 rv++;
71 s++; 78 s++;
72 } 79 }
80 *p = res;
73 if (overflow) 81 if (overflow)
74 rv |= KSTRTOX_OVERFLOW; 82 rv |= KSTRTOX_OVERFLOW;
75 return rv; 83 return rv;
diff --git a/lib/lcm.c b/lib/lcm.c
index 10b5cfcacf6b..b9c8de461e9e 100644
--- a/lib/lcm.c
+++ b/lib/lcm.c
@@ -1,6 +1,6 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/gcd.h> 2#include <linux/gcd.h>
3#include <linux/module.h> 3#include <linux/export.h>
4#include <linux/lcm.h> 4#include <linux/lcm.h>
5 5
6/* Lowest common multiple */ 6/* Lowest common multiple */
diff --git a/lib/list_debug.c b/lib/list_debug.c
index b8029a5583ff..982b850d4e7a 100644
--- a/lib/list_debug.c
+++ b/lib/list_debug.c
@@ -6,8 +6,10 @@
6 * DEBUG_LIST. 6 * DEBUG_LIST.
7 */ 7 */
8 8
9#include <linux/module.h> 9#include <linux/export.h>
10#include <linux/list.h> 10#include <linux/list.h>
11#include <linux/bug.h>
12#include <linux/kernel.h>
11 13
12/* 14/*
13 * Insert a new entry between two known consecutive entries. 15 * Insert a new entry between two known consecutive entries.
diff --git a/lib/llist.c b/lib/llist.c
index 700cff77a387..4a15115e90f8 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -23,11 +23,10 @@
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */ 24 */
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/module.h> 26#include <linux/export.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/llist.h> 28#include <linux/llist.h>
29 29
30#include <asm/system.h>
31 30
32/** 31/**
33 * llist_add_batch - add several linked entries in batch 32 * llist_add_batch - add several linked entries in batch
diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c
index 507a22fab738..7aae0f2a5e0a 100644
--- a/lib/locking-selftest.c
+++ b/lib/locking-selftest.c
@@ -14,7 +14,6 @@
14#include <linux/mutex.h> 14#include <linux/mutex.h>
15#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/module.h>
18#include <linux/lockdep.h> 17#include <linux/lockdep.h>
19#include <linux/spinlock.h> 18#include <linux/spinlock.h>
20#include <linux/kallsyms.h> 19#include <linux/kallsyms.h>
diff --git a/lib/md5.c b/lib/md5.c
index c777180e1f2f..958a3c15923c 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -1,5 +1,5 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/module.h> 2#include <linux/export.h>
3#include <linux/cryptohash.h> 3#include <linux/cryptohash.h>
4 4
5#define F1(x, y, z) (z ^ (x & (y ^ z))) 5#define F1(x, y, z) (z ^ (x & (y ^ z)))
diff --git a/lib/mpi/longlong.h b/lib/mpi/longlong.h
index b87487b40a8b..29f98624ef93 100644
--- a/lib/mpi/longlong.h
+++ b/lib/mpi/longlong.h
@@ -1200,18 +1200,40 @@ do { \
1200 "r" ((USItype)(v)) \ 1200 "r" ((USItype)(v)) \
1201 : "%g1", "%g2" __AND_CLOBBER_CC) 1201 : "%g1", "%g2" __AND_CLOBBER_CC)
1202#define UMUL_TIME 39 /* 39 instructions */ 1202#define UMUL_TIME 39 /* 39 instructions */
1203#endif 1203/* It's quite necessary to add this much assembler for the sparc.
1204#ifndef udiv_qrnnd 1204 The default udiv_qrnnd (in C) is more than 10 times slower! */
1205#ifndef LONGLONG_STANDALONE
1206#define udiv_qrnnd(q, r, n1, n0, d) \ 1205#define udiv_qrnnd(q, r, n1, n0, d) \
1207do { USItype __r; \ 1206 __asm__ ("! Inlined udiv_qrnnd\n\t" \
1208 (q) = __udiv_qrnnd(&__r, (n1), (n0), (d)); \ 1207 "mov 32,%%g1\n\t" \
1209 (r) = __r; \ 1208 "subcc %1,%2,%%g0\n\t" \
1210} while (0) 1209 "1: bcs 5f\n\t" \
1211 extern USItype __udiv_qrnnd(); 1210 "addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n\t" \
1212#define UDIV_TIME 140 1211 "sub %1,%2,%1 ! this kills msb of n\n\t" \
1213#endif /* LONGLONG_STANDALONE */ 1212 "addx %1,%1,%1 ! so this can't give carry\n\t" \
1214#endif /* udiv_qrnnd */ 1213 "subcc %%g1,1,%%g1\n\t" \
1214 "2: bne 1b\n\t" \
1215 "subcc %1,%2,%%g0\n\t" \
1216 "bcs 3f\n\t" \
1217 "addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n\t" \
1218 "b 3f\n\t" \
1219 "sub %1,%2,%1 ! this kills msb of n\n\t" \
1220 "4: sub %1,%2,%1\n\t" \
1221 "5: addxcc %1,%1,%1\n\t" \
1222 "bcc 2b\n\t" \
1223 "subcc %%g1,1,%%g1\n\t" \
1224 "! Got carry from n. Subtract next step to cancel this carry.\n\t" \
1225 "bne 4b\n\t" \
1226 "addcc %0,%0,%0 ! shift n1n0 and a 0-bit in lsb\n\t" \
1227 "sub %1,%2,%1\n\t" \
1228 "3: xnor %0,0,%0\n\t" \
1229 "! End of inline udiv_qrnnd\n" \
1230 : "=&r" ((USItype)(q)), \
1231 "=&r" ((USItype)(r)) \
1232 : "r" ((USItype)(d)), \
1233 "1" ((USItype)(n1)), \
1234 "0" ((USItype)(n0)) : "%g1", "cc")
1235#define UDIV_TIME (3+7*32) /* 7 instructions/iteration. 32 iterations. */
1236#endif
1215#endif /* __sparc__ */ 1237#endif /* __sparc__ */
1216 1238
1217/*************************************** 1239/***************************************
diff --git a/lib/mpi/mpi-bit.c b/lib/mpi/mpi-bit.c
index 854c9c6da025..2f526627e4f5 100644
--- a/lib/mpi/mpi-bit.c
+++ b/lib/mpi/mpi-bit.c
@@ -21,25 +21,6 @@
21#include "mpi-internal.h" 21#include "mpi-internal.h"
22#include "longlong.h" 22#include "longlong.h"
23 23
24const unsigned char __clz_tab[] = {
25 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
26 5, 5, 5, 5, 5, 5, 5, 5,
27 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
28 6, 6, 6, 6, 6, 6, 6, 6,
29 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
30 7, 7, 7, 7, 7, 7, 7, 7,
31 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
32 7, 7, 7, 7, 7, 7, 7, 7,
33 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
34 8, 8, 8, 8, 8, 8, 8, 8,
35 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
36 8, 8, 8, 8, 8, 8, 8, 8,
37 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
38 8, 8, 8, 8, 8, 8, 8, 8,
39 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
40 8, 8, 8, 8, 8, 8, 8, 8,
41};
42
43#define A_LIMB_1 ((mpi_limb_t) 1) 24#define A_LIMB_1 ((mpi_limb_t) 1)
44 25
45/**************** 26/****************
diff --git a/lib/mpi/mpi-div.c b/lib/mpi/mpi-div.c
index c3087d1390ce..f68cbbb4d4a4 100644
--- a/lib/mpi/mpi-div.c
+++ b/lib/mpi/mpi-div.c
@@ -149,6 +149,9 @@ int mpi_tdiv_qr(MPI quot, MPI rem, MPI num, MPI den)
149 mpi_ptr_t marker[5]; 149 mpi_ptr_t marker[5];
150 int markidx = 0; 150 int markidx = 0;
151 151
152 if (!dsize)
153 return -EINVAL;
154
152 memset(marker, 0, sizeof(marker)); 155 memset(marker, 0, sizeof(marker));
153 156
154 /* Ensure space is enough for quotient and remainder. 157 /* Ensure space is enough for quotient and remainder.
@@ -207,6 +210,8 @@ int mpi_tdiv_qr(MPI quot, MPI rem, MPI num, MPI den)
207 * numerator would be gradually overwritten by the quotient limbs. */ 210 * numerator would be gradually overwritten by the quotient limbs. */
208 if (qp == np) { /* Copy NP object to temporary space. */ 211 if (qp == np) { /* Copy NP object to temporary space. */
209 np = marker[markidx++] = mpi_alloc_limb_space(nsize); 212 np = marker[markidx++] = mpi_alloc_limb_space(nsize);
213 if (!np)
214 goto nomem;
210 MPN_COPY(np, qp, nsize); 215 MPN_COPY(np, qp, nsize);
211 } 216 }
212 } else /* Put quotient at top of remainder. */ 217 } else /* Put quotient at top of remainder. */
diff --git a/lib/mpi/mpi-pow.c b/lib/mpi/mpi-pow.c
index b04a3cf80080..67f3e79af914 100644
--- a/lib/mpi/mpi-pow.c
+++ b/lib/mpi/mpi-pow.c
@@ -59,7 +59,7 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod)
59 ep = exp->d; 59 ep = exp->d;
60 60
61 if (!msize) 61 if (!msize)
62 msize = 1 / msize; /* provoke a signal */ 62 return -EINVAL;
63 63
64 if (!esize) { 64 if (!esize) {
65 /* Exponent is zero, result is 1 mod MOD, i.e., 1 or 0 65 /* Exponent is zero, result is 1 mod MOD, i.e., 1 or 0
diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c
index fe84bb978e3b..f26b41fcb48c 100644
--- a/lib/mpi/mpicoder.c
+++ b/lib/mpi/mpicoder.c
@@ -20,78 +20,15 @@
20 20
21#include "mpi-internal.h" 21#include "mpi-internal.h"
22 22
23#define DIM(v) (sizeof(v)/sizeof((v)[0]))
24#define MAX_EXTERN_MPI_BITS 16384 23#define MAX_EXTERN_MPI_BITS 16384
25 24
26static uint8_t asn[15] = /* Object ID is 1.3.14.3.2.26 */
27{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
28 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14
29};
30
31MPI do_encode_md(const void *sha_buffer, unsigned nbits)
32{
33 int nframe = (nbits + 7) / 8;
34 uint8_t *frame, *fr_pt;
35 int i = 0, n;
36 size_t asnlen = DIM(asn);
37 MPI a = MPI_NULL;
38
39 if (SHA1_DIGEST_LENGTH + asnlen + 4 > nframe)
40 pr_info("MPI: can't encode a %d bit MD into a %d bits frame\n",
41 (int)(SHA1_DIGEST_LENGTH * 8), (int)nbits);
42
43 /* We encode the MD in this way:
44 *
45 * 0 A PAD(n bytes) 0 ASN(asnlen bytes) MD(len bytes)
46 *
47 * PAD consists of FF bytes.
48 */
49 frame = kmalloc(nframe, GFP_KERNEL);
50 if (!frame)
51 return MPI_NULL;
52 n = 0;
53 frame[n++] = 0;
54 frame[n++] = 1; /* block type */
55 i = nframe - SHA1_DIGEST_LENGTH - asnlen - 3;
56
57 if (i <= 1) {
58 pr_info("MPI: message digest encoding failed\n");
59 kfree(frame);
60 return a;
61 }
62
63 memset(frame + n, 0xff, i);
64 n += i;
65 frame[n++] = 0;
66 memcpy(frame + n, &asn, asnlen);
67 n += asnlen;
68 memcpy(frame + n, sha_buffer, SHA1_DIGEST_LENGTH);
69 n += SHA1_DIGEST_LENGTH;
70
71 i = nframe;
72 fr_pt = frame;
73
74 if (n != nframe) {
75 printk
76 ("MPI: message digest encoding failed, frame length is wrong\n");
77 kfree(frame);
78 return a;
79 }
80
81 a = mpi_alloc((nframe + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB);
82 mpi_set_buffer(a, frame, nframe, 0);
83 kfree(frame);
84
85 return a;
86}
87
88MPI mpi_read_from_buffer(const void *xbuffer, unsigned *ret_nread) 25MPI mpi_read_from_buffer(const void *xbuffer, unsigned *ret_nread)
89{ 26{
90 const uint8_t *buffer = xbuffer; 27 const uint8_t *buffer = xbuffer;
91 int i, j; 28 int i, j;
92 unsigned nbits, nbytes, nlimbs, nread = 0; 29 unsigned nbits, nbytes, nlimbs, nread = 0;
93 mpi_limb_t a; 30 mpi_limb_t a;
94 MPI val = MPI_NULL; 31 MPI val = NULL;
95 32
96 if (*ret_nread < 2) 33 if (*ret_nread < 2)
97 goto leave; 34 goto leave;
@@ -108,7 +45,7 @@ MPI mpi_read_from_buffer(const void *xbuffer, unsigned *ret_nread)
108 nlimbs = (nbytes + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB; 45 nlimbs = (nbytes + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB;
109 val = mpi_alloc(nlimbs); 46 val = mpi_alloc(nlimbs);
110 if (!val) 47 if (!val)
111 return MPI_NULL; 48 return NULL;
112 i = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB; 49 i = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB;
113 i %= BYTES_PER_MPI_LIMB; 50 i %= BYTES_PER_MPI_LIMB;
114 val->nbits = nbits; 51 val->nbits = nbits;
@@ -212,30 +149,6 @@ int mpi_fromstr(MPI val, const char *str)
212EXPORT_SYMBOL_GPL(mpi_fromstr); 149EXPORT_SYMBOL_GPL(mpi_fromstr);
213 150
214/**************** 151/****************
215 * Special function to get the low 8 bytes from an mpi.
216 * This can be used as a keyid; KEYID is an 2 element array.
217 * Return the low 4 bytes.
218 */
219u32 mpi_get_keyid(const MPI a, u32 *keyid)
220{
221#if BYTES_PER_MPI_LIMB == 4
222 if (keyid) {
223 keyid[0] = a->nlimbs >= 2 ? a->d[1] : 0;
224 keyid[1] = a->nlimbs >= 1 ? a->d[0] : 0;
225 }
226 return a->nlimbs >= 1 ? a->d[0] : 0;
227#elif BYTES_PER_MPI_LIMB == 8
228 if (keyid) {
229 keyid[0] = a->nlimbs ? (u32) (a->d[0] >> 32) : 0;
230 keyid[1] = a->nlimbs ? (u32) (a->d[0] & 0xffffffff) : 0;
231 }
232 return a->nlimbs ? (u32) (a->d[0] & 0xffffffff) : 0;
233#else
234#error Make this function work with other LIMB sizes
235#endif
236}
237
238/****************
239 * Return an allocated buffer with the MPI (msb first). 152 * Return an allocated buffer with the MPI (msb first).
240 * NBYTES receives the length of this buffer. Caller must free the 153 * NBYTES receives the length of this buffer. Caller must free the
241 * return string (This function does return a 0 byte buffer with NBYTES 154 * return string (This function does return a 0 byte buffer with NBYTES
@@ -255,6 +168,8 @@ void *mpi_get_buffer(MPI a, unsigned *nbytes, int *sign)
255 if (!n) 168 if (!n)
256 n++; /* avoid zero length allocation */ 169 n++; /* avoid zero length allocation */
257 p = buffer = kmalloc(n, GFP_KERNEL); 170 p = buffer = kmalloc(n, GFP_KERNEL);
171 if (!p)
172 return NULL;
258 173
259 for (i = a->nlimbs - 1; i >= 0; i--) { 174 for (i = a->nlimbs - 1; i >= 0; i--) {
260 alimb = a->d[i]; 175 alimb = a->d[i];
diff --git a/lib/mpi/mpih-div.c b/lib/mpi/mpih-div.c
index 87ede162dfab..cde1aaec18da 100644
--- a/lib/mpi/mpih-div.c
+++ b/lib/mpi/mpih-div.c
@@ -217,6 +217,10 @@ mpihelp_divrem(mpi_ptr_t qp, mpi_size_t qextra_limbs,
217 case 0: 217 case 0:
218 /* We are asked to divide by zero, so go ahead and do it! (To make 218 /* We are asked to divide by zero, so go ahead and do it! (To make
219 the compiler not remove this statement, return the value.) */ 219 the compiler not remove this statement, return the value.) */
220 /*
221 * existing clients of this function have been modified
222 * not to call it with dsize == 0, so this should not happen
223 */
220 return 1 / dsize; 224 return 1 / dsize;
221 225
222 case 1: 226 case 1:
diff --git a/lib/mpi/mpiutil.c b/lib/mpi/mpiutil.c
index eefc55d6b7f5..26e4ed31e256 100644
--- a/lib/mpi/mpiutil.c
+++ b/lib/mpi/mpiutil.c
@@ -58,6 +58,9 @@ mpi_ptr_t mpi_alloc_limb_space(unsigned nlimbs)
58{ 58{
59 size_t len = nlimbs * sizeof(mpi_limb_t); 59 size_t len = nlimbs * sizeof(mpi_limb_t);
60 60
61 if (!len)
62 return NULL;
63
61 return kmalloc(len, GFP_KERNEL); 64 return kmalloc(len, GFP_KERNEL);
62} 65}
63 66
@@ -135,7 +138,7 @@ int mpi_copy(MPI *copied, const MPI a)
135 size_t i; 138 size_t i;
136 MPI b; 139 MPI b;
137 140
138 *copied = MPI_NULL; 141 *copied = NULL;
139 142
140 if (a) { 143 if (a) {
141 b = mpi_alloc(a->nlimbs); 144 b = mpi_alloc(a->nlimbs);
diff --git a/lib/nlattr.c b/lib/nlattr.c
index a8408b6cacdf..4226dfeb5178 100644
--- a/lib/nlattr.c
+++ b/lib/nlattr.c
@@ -5,7 +5,7 @@
5 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> 5 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
6 */ 6 */
7 7
8#include <linux/module.h> 8#include <linux/export.h>
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/errno.h> 10#include <linux/errno.h>
11#include <linux/jiffies.h> 11#include <linux/jiffies.h>
diff --git a/lib/parser.c b/lib/parser.c
index dcbaaef6cf11..c43410084838 100644
--- a/lib/parser.c
+++ b/lib/parser.c
@@ -6,7 +6,8 @@
6 */ 6 */
7 7
8#include <linux/ctype.h> 8#include <linux/ctype.h>
9#include <linux/module.h> 9#include <linux/types.h>
10#include <linux/export.h>
10#include <linux/parser.h> 11#include <linux/parser.h>
11#include <linux/slab.h> 12#include <linux/slab.h>
12#include <linux/string.h> 13#include <linux/string.h>
diff --git a/lib/pci_iomap.c b/lib/pci_iomap.c
index 4b0fdc22e688..0d83ea8a9605 100644
--- a/lib/pci_iomap.c
+++ b/lib/pci_iomap.c
@@ -34,7 +34,7 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
34 if (maxlen && len > maxlen) 34 if (maxlen && len > maxlen)
35 len = maxlen; 35 len = maxlen;
36 if (flags & IORESOURCE_IO) 36 if (flags & IORESOURCE_IO)
37 return ioport_map(start, len); 37 return __pci_ioport_map(dev, start, len);
38 if (flags & IORESOURCE_MEM) { 38 if (flags & IORESOURCE_MEM) {
39 if (flags & IORESOURCE_CACHEABLE) 39 if (flags & IORESOURCE_CACHEABLE)
40 return ioremap(start, len); 40 return ioremap(start, len);
diff --git a/lib/plist.c b/lib/plist.c
index a0a4da489c22..6ab0e521c48b 100644
--- a/lib/plist.c
+++ b/lib/plist.c
@@ -23,6 +23,7 @@
23 * information. 23 * information.
24 */ 24 */
25 25
26#include <linux/bug.h>
26#include <linux/plist.h> 27#include <linux/plist.h>
27#include <linux/spinlock.h> 28#include <linux/spinlock.h>
28 29
diff --git a/lib/prio_tree.c b/lib/prio_tree.c
index ccfd850b0dec..8d443af03b4c 100644
--- a/lib/prio_tree.c
+++ b/lib/prio_tree.c
@@ -85,6 +85,17 @@ static inline unsigned long prio_tree_maxindex(unsigned int bits)
85 return index_bits_to_maxindex[bits - 1]; 85 return index_bits_to_maxindex[bits - 1];
86} 86}
87 87
88static void prio_set_parent(struct prio_tree_node *parent,
89 struct prio_tree_node *child, bool left)
90{
91 if (left)
92 parent->left = child;
93 else
94 parent->right = child;
95
96 child->parent = parent;
97}
98
88/* 99/*
89 * Extend a priority search tree so that it can store a node with heap_index 100 * Extend a priority search tree so that it can store a node with heap_index
90 * max_heap_index. In the worst case, this algorithm takes O((log n)^2). 101 * max_heap_index. In the worst case, this algorithm takes O((log n)^2).
@@ -94,45 +105,32 @@ static inline unsigned long prio_tree_maxindex(unsigned int bits)
94static struct prio_tree_node *prio_tree_expand(struct prio_tree_root *root, 105static struct prio_tree_node *prio_tree_expand(struct prio_tree_root *root,
95 struct prio_tree_node *node, unsigned long max_heap_index) 106 struct prio_tree_node *node, unsigned long max_heap_index)
96{ 107{
97 struct prio_tree_node *first = NULL, *prev, *last = NULL; 108 struct prio_tree_node *prev;
98 109
99 if (max_heap_index > prio_tree_maxindex(root->index_bits)) 110 if (max_heap_index > prio_tree_maxindex(root->index_bits))
100 root->index_bits++; 111 root->index_bits++;
101 112
113 prev = node;
114 INIT_PRIO_TREE_NODE(node);
115
102 while (max_heap_index > prio_tree_maxindex(root->index_bits)) { 116 while (max_heap_index > prio_tree_maxindex(root->index_bits)) {
117 struct prio_tree_node *tmp = root->prio_tree_node;
118
103 root->index_bits++; 119 root->index_bits++;
104 120
105 if (prio_tree_empty(root)) 121 if (prio_tree_empty(root))
106 continue; 122 continue;
107 123
108 if (first == NULL) { 124 prio_tree_remove(root, root->prio_tree_node);
109 first = root->prio_tree_node; 125 INIT_PRIO_TREE_NODE(tmp);
110 prio_tree_remove(root, root->prio_tree_node);
111 INIT_PRIO_TREE_NODE(first);
112 last = first;
113 } else {
114 prev = last;
115 last = root->prio_tree_node;
116 prio_tree_remove(root, root->prio_tree_node);
117 INIT_PRIO_TREE_NODE(last);
118 prev->left = last;
119 last->parent = prev;
120 }
121 }
122
123 INIT_PRIO_TREE_NODE(node);
124
125 if (first) {
126 node->left = first;
127 first->parent = node;
128 } else
129 last = node;
130 126
131 if (!prio_tree_empty(root)) { 127 prio_set_parent(prev, tmp, true);
132 last->left = root->prio_tree_node; 128 prev = tmp;
133 last->left->parent = last;
134 } 129 }
135 130
131 if (!prio_tree_empty(root))
132 prio_set_parent(prev, root->prio_tree_node, true);
133
136 root->prio_tree_node = node; 134 root->prio_tree_node = node;
137 return node; 135 return node;
138} 136}
@@ -151,25 +149,15 @@ struct prio_tree_node *prio_tree_replace(struct prio_tree_root *root,
151 * We can reduce root->index_bits here. However, it is complex 149 * We can reduce root->index_bits here. However, it is complex
152 * and does not help much to improve performance (IMO). 150 * and does not help much to improve performance (IMO).
153 */ 151 */
154 node->parent = node;
155 root->prio_tree_node = node; 152 root->prio_tree_node = node;
156 } else { 153 } else
157 node->parent = old->parent; 154 prio_set_parent(old->parent, node, old->parent->left == old);
158 if (old->parent->left == old)
159 old->parent->left = node;
160 else
161 old->parent->right = node;
162 }
163 155
164 if (!prio_tree_left_empty(old)) { 156 if (!prio_tree_left_empty(old))
165 node->left = old->left; 157 prio_set_parent(node, old->left, true);
166 old->left->parent = node;
167 }
168 158
169 if (!prio_tree_right_empty(old)) { 159 if (!prio_tree_right_empty(old))
170 node->right = old->right; 160 prio_set_parent(node, old->right, false);
171 old->right->parent = node;
172 }
173 161
174 return old; 162 return old;
175} 163}
@@ -229,16 +217,14 @@ struct prio_tree_node *prio_tree_insert(struct prio_tree_root *root,
229 if (index & mask) { 217 if (index & mask) {
230 if (prio_tree_right_empty(cur)) { 218 if (prio_tree_right_empty(cur)) {
231 INIT_PRIO_TREE_NODE(node); 219 INIT_PRIO_TREE_NODE(node);
232 cur->right = node; 220 prio_set_parent(cur, node, false);
233 node->parent = cur;
234 return res; 221 return res;
235 } else 222 } else
236 cur = cur->right; 223 cur = cur->right;
237 } else { 224 } else {
238 if (prio_tree_left_empty(cur)) { 225 if (prio_tree_left_empty(cur)) {
239 INIT_PRIO_TREE_NODE(node); 226 INIT_PRIO_TREE_NODE(node);
240 cur->left = node; 227 prio_set_parent(cur, node, true);
241 node->parent = cur;
242 return res; 228 return res;
243 } else 229 } else
244 cur = cur->left; 230 cur = cur->left;
@@ -305,6 +291,40 @@ void prio_tree_remove(struct prio_tree_root *root, struct prio_tree_node *node)
305 cur = prio_tree_replace(root, cur->parent, cur); 291 cur = prio_tree_replace(root, cur->parent, cur);
306} 292}
307 293
294static void iter_walk_down(struct prio_tree_iter *iter)
295{
296 iter->mask >>= 1;
297 if (iter->mask) {
298 if (iter->size_level)
299 iter->size_level++;
300 return;
301 }
302
303 if (iter->size_level) {
304 BUG_ON(!prio_tree_left_empty(iter->cur));
305 BUG_ON(!prio_tree_right_empty(iter->cur));
306 iter->size_level++;
307 iter->mask = ULONG_MAX;
308 } else {
309 iter->size_level = 1;
310 iter->mask = 1UL << (BITS_PER_LONG - 1);
311 }
312}
313
314static void iter_walk_up(struct prio_tree_iter *iter)
315{
316 if (iter->mask == ULONG_MAX)
317 iter->mask = 1UL;
318 else if (iter->size_level == 1)
319 iter->mask = 1UL;
320 else
321 iter->mask <<= 1;
322 if (iter->size_level)
323 iter->size_level--;
324 if (!iter->size_level && (iter->value & iter->mask))
325 iter->value ^= iter->mask;
326}
327
308/* 328/*
309 * Following functions help to enumerate all prio_tree_nodes in the tree that 329 * Following functions help to enumerate all prio_tree_nodes in the tree that
310 * overlap with the input interval X [radix_index, heap_index]. The enumeration 330 * overlap with the input interval X [radix_index, heap_index]. The enumeration
@@ -323,21 +343,7 @@ static struct prio_tree_node *prio_tree_left(struct prio_tree_iter *iter,
323 343
324 if (iter->r_index <= *h_index) { 344 if (iter->r_index <= *h_index) {
325 iter->cur = iter->cur->left; 345 iter->cur = iter->cur->left;
326 iter->mask >>= 1; 346 iter_walk_down(iter);
327 if (iter->mask) {
328 if (iter->size_level)
329 iter->size_level++;
330 } else {
331 if (iter->size_level) {
332 BUG_ON(!prio_tree_left_empty(iter->cur));
333 BUG_ON(!prio_tree_right_empty(iter->cur));
334 iter->size_level++;
335 iter->mask = ULONG_MAX;
336 } else {
337 iter->size_level = 1;
338 iter->mask = 1UL << (BITS_PER_LONG - 1);
339 }
340 }
341 return iter->cur; 347 return iter->cur;
342 } 348 }
343 349
@@ -364,22 +370,7 @@ static struct prio_tree_node *prio_tree_right(struct prio_tree_iter *iter,
364 370
365 if (iter->r_index <= *h_index) { 371 if (iter->r_index <= *h_index) {
366 iter->cur = iter->cur->right; 372 iter->cur = iter->cur->right;
367 iter->mask >>= 1; 373 iter_walk_down(iter);
368 iter->value = value;
369 if (iter->mask) {
370 if (iter->size_level)
371 iter->size_level++;
372 } else {
373 if (iter->size_level) {
374 BUG_ON(!prio_tree_left_empty(iter->cur));
375 BUG_ON(!prio_tree_right_empty(iter->cur));
376 iter->size_level++;
377 iter->mask = ULONG_MAX;
378 } else {
379 iter->size_level = 1;
380 iter->mask = 1UL << (BITS_PER_LONG - 1);
381 }
382 }
383 return iter->cur; 374 return iter->cur;
384 } 375 }
385 376
@@ -389,16 +380,7 @@ static struct prio_tree_node *prio_tree_right(struct prio_tree_iter *iter,
389static struct prio_tree_node *prio_tree_parent(struct prio_tree_iter *iter) 380static struct prio_tree_node *prio_tree_parent(struct prio_tree_iter *iter)
390{ 381{
391 iter->cur = iter->cur->parent; 382 iter->cur = iter->cur->parent;
392 if (iter->mask == ULONG_MAX) 383 iter_walk_up(iter);
393 iter->mask = 1UL;
394 else if (iter->size_level == 1)
395 iter->mask = 1UL;
396 else
397 iter->mask <<= 1;
398 if (iter->size_level)
399 iter->size_level--;
400 if (!iter->size_level && (iter->value & iter->mask))
401 iter->value ^= iter->mask;
402 return iter->cur; 384 return iter->cur;
403} 385}
404 386
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index d9df7454519c..86516f5588e3 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -3,6 +3,7 @@
3 * Portions Copyright (C) 2001 Christoph Hellwig 3 * Portions Copyright (C) 2001 Christoph Hellwig
4 * Copyright (C) 2005 SGI, Christoph Lameter 4 * Copyright (C) 2005 SGI, Christoph Lameter
5 * Copyright (C) 2006 Nick Piggin 5 * Copyright (C) 2006 Nick Piggin
6 * Copyright (C) 2012 Konstantin Khlebnikov
6 * 7 *
7 * This program is free software; you can redistribute it and/or 8 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as 9 * modify it under the terms of the GNU General Public License as
@@ -22,7 +23,7 @@
22#include <linux/errno.h> 23#include <linux/errno.h>
23#include <linux/init.h> 24#include <linux/init.h>
24#include <linux/kernel.h> 25#include <linux/kernel.h>
25#include <linux/module.h> 26#include <linux/export.h>
26#include <linux/radix-tree.h> 27#include <linux/radix-tree.h>
27#include <linux/percpu.h> 28#include <linux/percpu.h>
28#include <linux/slab.h> 29#include <linux/slab.h>
@@ -48,16 +49,14 @@
48struct radix_tree_node { 49struct radix_tree_node {
49 unsigned int height; /* Height from the bottom */ 50 unsigned int height; /* Height from the bottom */
50 unsigned int count; 51 unsigned int count;
51 struct rcu_head rcu_head; 52 union {
53 struct radix_tree_node *parent; /* Used when ascending tree */
54 struct rcu_head rcu_head; /* Used when freeing node */
55 };
52 void __rcu *slots[RADIX_TREE_MAP_SIZE]; 56 void __rcu *slots[RADIX_TREE_MAP_SIZE];
53 unsigned long tags[RADIX_TREE_MAX_TAGS][RADIX_TREE_TAG_LONGS]; 57 unsigned long tags[RADIX_TREE_MAX_TAGS][RADIX_TREE_TAG_LONGS];
54}; 58};
55 59
56struct radix_tree_path {
57 struct radix_tree_node *node;
58 int offset;
59};
60
61#define RADIX_TREE_INDEX_BITS (8 /* CHAR_BIT */ * sizeof(unsigned long)) 60#define RADIX_TREE_INDEX_BITS (8 /* CHAR_BIT */ * sizeof(unsigned long))
62#define RADIX_TREE_MAX_PATH (DIV_ROUND_UP(RADIX_TREE_INDEX_BITS, \ 61#define RADIX_TREE_MAX_PATH (DIV_ROUND_UP(RADIX_TREE_INDEX_BITS, \
63 RADIX_TREE_MAP_SHIFT)) 62 RADIX_TREE_MAP_SHIFT))
@@ -148,6 +147,43 @@ static inline int any_tag_set(struct radix_tree_node *node, unsigned int tag)
148 } 147 }
149 return 0; 148 return 0;
150} 149}
150
151/**
152 * radix_tree_find_next_bit - find the next set bit in a memory region
153 *
154 * @addr: The address to base the search on
155 * @size: The bitmap size in bits
156 * @offset: The bitnumber to start searching at
157 *
158 * Unrollable variant of find_next_bit() for constant size arrays.
159 * Tail bits starting from size to roundup(size, BITS_PER_LONG) must be zero.
160 * Returns next bit offset, or size if nothing found.
161 */
162static __always_inline unsigned long
163radix_tree_find_next_bit(const unsigned long *addr,
164 unsigned long size, unsigned long offset)
165{
166 if (!__builtin_constant_p(size))
167 return find_next_bit(addr, size, offset);
168
169 if (offset < size) {
170 unsigned long tmp;
171
172 addr += offset / BITS_PER_LONG;
173 tmp = *addr >> (offset % BITS_PER_LONG);
174 if (tmp)
175 return __ffs(tmp) + offset;
176 offset = (offset + BITS_PER_LONG) & ~(BITS_PER_LONG - 1);
177 while (offset < size) {
178 tmp = *++addr;
179 if (tmp)
180 return __ffs(tmp) + offset;
181 offset += BITS_PER_LONG;
182 }
183 }
184 return size;
185}
186
151/* 187/*
152 * This assumes that the caller has performed appropriate preallocation, and 188 * This assumes that the caller has performed appropriate preallocation, and
153 * that the caller has pinned this thread of control to the current CPU. 189 * that the caller has pinned this thread of control to the current CPU.
@@ -256,6 +292,7 @@ static inline unsigned long radix_tree_maxindex(unsigned int height)
256static int radix_tree_extend(struct radix_tree_root *root, unsigned long index) 292static int radix_tree_extend(struct radix_tree_root *root, unsigned long index)
257{ 293{
258 struct radix_tree_node *node; 294 struct radix_tree_node *node;
295 struct radix_tree_node *slot;
259 unsigned int height; 296 unsigned int height;
260 int tag; 297 int tag;
261 298
@@ -274,18 +311,23 @@ static int radix_tree_extend(struct radix_tree_root *root, unsigned long index)
274 if (!(node = radix_tree_node_alloc(root))) 311 if (!(node = radix_tree_node_alloc(root)))
275 return -ENOMEM; 312 return -ENOMEM;
276 313
277 /* Increase the height. */
278 node->slots[0] = indirect_to_ptr(root->rnode);
279
280 /* Propagate the aggregated tag info into the new root */ 314 /* Propagate the aggregated tag info into the new root */
281 for (tag = 0; tag < RADIX_TREE_MAX_TAGS; tag++) { 315 for (tag = 0; tag < RADIX_TREE_MAX_TAGS; tag++) {
282 if (root_tag_get(root, tag)) 316 if (root_tag_get(root, tag))
283 tag_set(node, tag, 0); 317 tag_set(node, tag, 0);
284 } 318 }
285 319
320 /* Increase the height. */
286 newheight = root->height+1; 321 newheight = root->height+1;
287 node->height = newheight; 322 node->height = newheight;
288 node->count = 1; 323 node->count = 1;
324 node->parent = NULL;
325 slot = root->rnode;
326 if (newheight > 1) {
327 slot = indirect_to_ptr(slot);
328 slot->parent = node;
329 }
330 node->slots[0] = slot;
289 node = ptr_to_indirect(node); 331 node = ptr_to_indirect(node);
290 rcu_assign_pointer(root->rnode, node); 332 rcu_assign_pointer(root->rnode, node);
291 root->height = newheight; 333 root->height = newheight;
@@ -331,6 +373,7 @@ int radix_tree_insert(struct radix_tree_root *root,
331 if (!(slot = radix_tree_node_alloc(root))) 373 if (!(slot = radix_tree_node_alloc(root)))
332 return -ENOMEM; 374 return -ENOMEM;
333 slot->height = height; 375 slot->height = height;
376 slot->parent = node;
334 if (node) { 377 if (node) {
335 rcu_assign_pointer(node->slots[offset], slot); 378 rcu_assign_pointer(node->slots[offset], slot);
336 node->count++; 379 node->count++;
@@ -504,47 +547,41 @@ EXPORT_SYMBOL(radix_tree_tag_set);
504void *radix_tree_tag_clear(struct radix_tree_root *root, 547void *radix_tree_tag_clear(struct radix_tree_root *root,
505 unsigned long index, unsigned int tag) 548 unsigned long index, unsigned int tag)
506{ 549{
507 /* 550 struct radix_tree_node *node = NULL;
508 * The radix tree path needs to be one longer than the maximum path
509 * since the "list" is null terminated.
510 */
511 struct radix_tree_path path[RADIX_TREE_MAX_PATH + 1], *pathp = path;
512 struct radix_tree_node *slot = NULL; 551 struct radix_tree_node *slot = NULL;
513 unsigned int height, shift; 552 unsigned int height, shift;
553 int uninitialized_var(offset);
514 554
515 height = root->height; 555 height = root->height;
516 if (index > radix_tree_maxindex(height)) 556 if (index > radix_tree_maxindex(height))
517 goto out; 557 goto out;
518 558
519 shift = (height - 1) * RADIX_TREE_MAP_SHIFT; 559 shift = height * RADIX_TREE_MAP_SHIFT;
520 pathp->node = NULL;
521 slot = indirect_to_ptr(root->rnode); 560 slot = indirect_to_ptr(root->rnode);
522 561
523 while (height > 0) { 562 while (shift) {
524 int offset;
525
526 if (slot == NULL) 563 if (slot == NULL)
527 goto out; 564 goto out;
528 565
566 shift -= RADIX_TREE_MAP_SHIFT;
529 offset = (index >> shift) & RADIX_TREE_MAP_MASK; 567 offset = (index >> shift) & RADIX_TREE_MAP_MASK;
530 pathp[1].offset = offset; 568 node = slot;
531 pathp[1].node = slot;
532 slot = slot->slots[offset]; 569 slot = slot->slots[offset];
533 pathp++;
534 shift -= RADIX_TREE_MAP_SHIFT;
535 height--;
536 } 570 }
537 571
538 if (slot == NULL) 572 if (slot == NULL)
539 goto out; 573 goto out;
540 574
541 while (pathp->node) { 575 while (node) {
542 if (!tag_get(pathp->node, tag, pathp->offset)) 576 if (!tag_get(node, tag, offset))
543 goto out; 577 goto out;
544 tag_clear(pathp->node, tag, pathp->offset); 578 tag_clear(node, tag, offset);
545 if (any_tag_set(pathp->node, tag)) 579 if (any_tag_set(node, tag))
546 goto out; 580 goto out;
547 pathp--; 581
582 index >>= RADIX_TREE_MAP_SHIFT;
583 offset = index & RADIX_TREE_MAP_MASK;
584 node = node->parent;
548 } 585 }
549 586
550 /* clear the root's tag bit */ 587 /* clear the root's tag bit */
@@ -614,6 +651,119 @@ int radix_tree_tag_get(struct radix_tree_root *root,
614EXPORT_SYMBOL(radix_tree_tag_get); 651EXPORT_SYMBOL(radix_tree_tag_get);
615 652
616/** 653/**
654 * radix_tree_next_chunk - find next chunk of slots for iteration
655 *
656 * @root: radix tree root
657 * @iter: iterator state
658 * @flags: RADIX_TREE_ITER_* flags and tag index
659 * Returns: pointer to chunk first slot, or NULL if iteration is over
660 */
661void **radix_tree_next_chunk(struct radix_tree_root *root,
662 struct radix_tree_iter *iter, unsigned flags)
663{
664 unsigned shift, tag = flags & RADIX_TREE_ITER_TAG_MASK;
665 struct radix_tree_node *rnode, *node;
666 unsigned long index, offset;
667
668 if ((flags & RADIX_TREE_ITER_TAGGED) && !root_tag_get(root, tag))
669 return NULL;
670
671 /*
672 * Catch next_index overflow after ~0UL. iter->index never overflows
673 * during iterating; it can be zero only at the beginning.
674 * And we cannot overflow iter->next_index in a single step,
675 * because RADIX_TREE_MAP_SHIFT < BITS_PER_LONG.
676 */
677 index = iter->next_index;
678 if (!index && iter->index)
679 return NULL;
680
681 rnode = rcu_dereference_raw(root->rnode);
682 if (radix_tree_is_indirect_ptr(rnode)) {
683 rnode = indirect_to_ptr(rnode);
684 } else if (rnode && !index) {
685 /* Single-slot tree */
686 iter->index = 0;
687 iter->next_index = 1;
688 iter->tags = 1;
689 return (void **)&root->rnode;
690 } else
691 return NULL;
692
693restart:
694 shift = (rnode->height - 1) * RADIX_TREE_MAP_SHIFT;
695 offset = index >> shift;
696
697 /* Index outside of the tree */
698 if (offset >= RADIX_TREE_MAP_SIZE)
699 return NULL;
700
701 node = rnode;
702 while (1) {
703 if ((flags & RADIX_TREE_ITER_TAGGED) ?
704 !test_bit(offset, node->tags[tag]) :
705 !node->slots[offset]) {
706 /* Hole detected */
707 if (flags & RADIX_TREE_ITER_CONTIG)
708 return NULL;
709
710 if (flags & RADIX_TREE_ITER_TAGGED)
711 offset = radix_tree_find_next_bit(
712 node->tags[tag],
713 RADIX_TREE_MAP_SIZE,
714 offset + 1);
715 else
716 while (++offset < RADIX_TREE_MAP_SIZE) {
717 if (node->slots[offset])
718 break;
719 }
720 index &= ~((RADIX_TREE_MAP_SIZE << shift) - 1);
721 index += offset << shift;
722 /* Overflow after ~0UL */
723 if (!index)
724 return NULL;
725 if (offset == RADIX_TREE_MAP_SIZE)
726 goto restart;
727 }
728
729 /* This is leaf-node */
730 if (!shift)
731 break;
732
733 node = rcu_dereference_raw(node->slots[offset]);
734 if (node == NULL)
735 goto restart;
736 shift -= RADIX_TREE_MAP_SHIFT;
737 offset = (index >> shift) & RADIX_TREE_MAP_MASK;
738 }
739
740 /* Update the iterator state */
741 iter->index = index;
742 iter->next_index = (index | RADIX_TREE_MAP_MASK) + 1;
743
744 /* Construct iter->tags bit-mask from node->tags[tag] array */
745 if (flags & RADIX_TREE_ITER_TAGGED) {
746 unsigned tag_long, tag_bit;
747
748 tag_long = offset / BITS_PER_LONG;
749 tag_bit = offset % BITS_PER_LONG;
750 iter->tags = node->tags[tag][tag_long] >> tag_bit;
751 /* This never happens if RADIX_TREE_TAG_LONGS == 1 */
752 if (tag_long < RADIX_TREE_TAG_LONGS - 1) {
753 /* Pick tags from next element */
754 if (tag_bit)
755 iter->tags |= node->tags[tag][tag_long + 1] <<
756 (BITS_PER_LONG - tag_bit);
757 /* Clip chunk size, here only BITS_PER_LONG tags */
758 iter->next_index = index + BITS_PER_LONG;
759 }
760 }
761
762 return node->slots + offset;
763}
764EXPORT_SYMBOL(radix_tree_next_chunk);
765
766/**
617 * radix_tree_range_tag_if_tagged - for each item in given range set given 767 * radix_tree_range_tag_if_tagged - for each item in given range set given
618 * tag if item has another tag set 768 * tag if item has another tag set
619 * @root: radix tree root 769 * @root: radix tree root
@@ -646,8 +796,7 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
646 unsigned int iftag, unsigned int settag) 796 unsigned int iftag, unsigned int settag)
647{ 797{
648 unsigned int height = root->height; 798 unsigned int height = root->height;
649 struct radix_tree_path path[height]; 799 struct radix_tree_node *node = NULL;
650 struct radix_tree_path *pathp = path;
651 struct radix_tree_node *slot; 800 struct radix_tree_node *slot;
652 unsigned int shift; 801 unsigned int shift;
653 unsigned long tagged = 0; 802 unsigned long tagged = 0;
@@ -671,14 +820,8 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
671 shift = (height - 1) * RADIX_TREE_MAP_SHIFT; 820 shift = (height - 1) * RADIX_TREE_MAP_SHIFT;
672 slot = indirect_to_ptr(root->rnode); 821 slot = indirect_to_ptr(root->rnode);
673 822
674 /*
675 * we fill the path from (root->height - 2) to 0, leaving the index at
676 * (root->height - 1) as a terminator. Zero the node in the terminator
677 * so that we can use this to end walk loops back up the path.
678 */
679 path[height - 1].node = NULL;
680
681 for (;;) { 823 for (;;) {
824 unsigned long upindex;
682 int offset; 825 int offset;
683 826
684 offset = (index >> shift) & RADIX_TREE_MAP_MASK; 827 offset = (index >> shift) & RADIX_TREE_MAP_MASK;
@@ -686,12 +829,10 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
686 goto next; 829 goto next;
687 if (!tag_get(slot, iftag, offset)) 830 if (!tag_get(slot, iftag, offset))
688 goto next; 831 goto next;
689 if (height > 1) { 832 if (shift) {
690 /* Go down one level */ 833 /* Go down one level */
691 height--;
692 shift -= RADIX_TREE_MAP_SHIFT; 834 shift -= RADIX_TREE_MAP_SHIFT;
693 path[height - 1].node = slot; 835 node = slot;
694 path[height - 1].offset = offset;
695 slot = slot->slots[offset]; 836 slot = slot->slots[offset];
696 continue; 837 continue;
697 } 838 }
@@ -701,15 +842,27 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
701 tag_set(slot, settag, offset); 842 tag_set(slot, settag, offset);
702 843
703 /* walk back up the path tagging interior nodes */ 844 /* walk back up the path tagging interior nodes */
704 pathp = &path[0]; 845 upindex = index;
705 while (pathp->node) { 846 while (node) {
847 upindex >>= RADIX_TREE_MAP_SHIFT;
848 offset = upindex & RADIX_TREE_MAP_MASK;
849
706 /* stop if we find a node with the tag already set */ 850 /* stop if we find a node with the tag already set */
707 if (tag_get(pathp->node, settag, pathp->offset)) 851 if (tag_get(node, settag, offset))
708 break; 852 break;
709 tag_set(pathp->node, settag, pathp->offset); 853 tag_set(node, settag, offset);
710 pathp++; 854 node = node->parent;
711 } 855 }
712 856
857 /*
858 * Small optimization: now clear that node pointer.
859 * Since all of this slot's ancestors now have the tag set
860 * from setting it above, we have no further need to walk
861 * back up the tree setting tags, until we update slot to
862 * point to another radix_tree_node.
863 */
864 node = NULL;
865
713next: 866next:
714 /* Go to next item at level determined by 'shift' */ 867 /* Go to next item at level determined by 'shift' */
715 index = ((index >> shift) + 1) << shift; 868 index = ((index >> shift) + 1) << shift;
@@ -724,8 +877,7 @@ next:
724 * last_index is guaranteed to be in the tree, what 877 * last_index is guaranteed to be in the tree, what
725 * we do below cannot wander astray. 878 * we do below cannot wander astray.
726 */ 879 */
727 slot = path[height - 1].node; 880 slot = slot->parent;
728 height++;
729 shift += RADIX_TREE_MAP_SHIFT; 881 shift += RADIX_TREE_MAP_SHIFT;
730 } 882 }
731 } 883 }
@@ -816,57 +968,6 @@ unsigned long radix_tree_prev_hole(struct radix_tree_root *root,
816} 968}
817EXPORT_SYMBOL(radix_tree_prev_hole); 969EXPORT_SYMBOL(radix_tree_prev_hole);
818 970
819static unsigned int
820__lookup(struct radix_tree_node *slot, void ***results, unsigned long *indices,
821 unsigned long index, unsigned int max_items, unsigned long *next_index)
822{
823 unsigned int nr_found = 0;
824 unsigned int shift, height;
825 unsigned long i;
826
827 height = slot->height;
828 if (height == 0)
829 goto out;
830 shift = (height-1) * RADIX_TREE_MAP_SHIFT;
831
832 for ( ; height > 1; height--) {
833 i = (index >> shift) & RADIX_TREE_MAP_MASK;
834 for (;;) {
835 if (slot->slots[i] != NULL)
836 break;
837 index &= ~((1UL << shift) - 1);
838 index += 1UL << shift;
839 if (index == 0)
840 goto out; /* 32-bit wraparound */
841 i++;
842 if (i == RADIX_TREE_MAP_SIZE)
843 goto out;
844 }
845
846 shift -= RADIX_TREE_MAP_SHIFT;
847 slot = rcu_dereference_raw(slot->slots[i]);
848 if (slot == NULL)
849 goto out;
850 }
851
852 /* Bottom level: grab some items */
853 for (i = index & RADIX_TREE_MAP_MASK; i < RADIX_TREE_MAP_SIZE; i++) {
854 if (slot->slots[i]) {
855 results[nr_found] = &(slot->slots[i]);
856 if (indices)
857 indices[nr_found] = index;
858 if (++nr_found == max_items) {
859 index++;
860 goto out;
861 }
862 }
863 index++;
864 }
865out:
866 *next_index = index;
867 return nr_found;
868}
869
870/** 971/**
871 * radix_tree_gang_lookup - perform multiple lookup on a radix tree 972 * radix_tree_gang_lookup - perform multiple lookup on a radix tree
872 * @root: radix tree root 973 * @root: radix tree root
@@ -890,48 +991,19 @@ unsigned int
890radix_tree_gang_lookup(struct radix_tree_root *root, void **results, 991radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
891 unsigned long first_index, unsigned int max_items) 992 unsigned long first_index, unsigned int max_items)
892{ 993{
893 unsigned long max_index; 994 struct radix_tree_iter iter;
894 struct radix_tree_node *node; 995 void **slot;
895 unsigned long cur_index = first_index; 996 unsigned int ret = 0;
896 unsigned int ret;
897 997
898 node = rcu_dereference_raw(root->rnode); 998 if (unlikely(!max_items))
899 if (!node)
900 return 0; 999 return 0;
901 1000
902 if (!radix_tree_is_indirect_ptr(node)) { 1001 radix_tree_for_each_slot(slot, root, &iter, first_index) {
903 if (first_index > 0) 1002 results[ret] = indirect_to_ptr(rcu_dereference_raw(*slot));
904 return 0; 1003 if (!results[ret])
905 results[0] = node; 1004 continue;
906 return 1; 1005 if (++ret == max_items)
907 }
908 node = indirect_to_ptr(node);
909
910 max_index = radix_tree_maxindex(node->height);
911
912 ret = 0;
913 while (ret < max_items) {
914 unsigned int nr_found, slots_found, i;
915 unsigned long next_index; /* Index of next search */
916
917 if (cur_index > max_index)
918 break;
919 slots_found = __lookup(node, (void ***)results + ret, NULL,
920 cur_index, max_items - ret, &next_index);
921 nr_found = 0;
922 for (i = 0; i < slots_found; i++) {
923 struct radix_tree_node *slot;
924 slot = *(((void ***)results)[ret + i]);
925 if (!slot)
926 continue;
927 results[ret + nr_found] =
928 indirect_to_ptr(rcu_dereference_raw(slot));
929 nr_found++;
930 }
931 ret += nr_found;
932 if (next_index == 0)
933 break; 1006 break;
934 cur_index = next_index;
935 } 1007 }
936 1008
937 return ret; 1009 return ret;
@@ -961,112 +1033,25 @@ radix_tree_gang_lookup_slot(struct radix_tree_root *root,
961 void ***results, unsigned long *indices, 1033 void ***results, unsigned long *indices,
962 unsigned long first_index, unsigned int max_items) 1034 unsigned long first_index, unsigned int max_items)
963{ 1035{
964 unsigned long max_index; 1036 struct radix_tree_iter iter;
965 struct radix_tree_node *node; 1037 void **slot;
966 unsigned long cur_index = first_index; 1038 unsigned int ret = 0;
967 unsigned int ret;
968 1039
969 node = rcu_dereference_raw(root->rnode); 1040 if (unlikely(!max_items))
970 if (!node)
971 return 0; 1041 return 0;
972 1042
973 if (!radix_tree_is_indirect_ptr(node)) { 1043 radix_tree_for_each_slot(slot, root, &iter, first_index) {
974 if (first_index > 0) 1044 results[ret] = slot;
975 return 0;
976 results[0] = (void **)&root->rnode;
977 if (indices) 1045 if (indices)
978 indices[0] = 0; 1046 indices[ret] = iter.index;
979 return 1; 1047 if (++ret == max_items)
980 }
981 node = indirect_to_ptr(node);
982
983 max_index = radix_tree_maxindex(node->height);
984
985 ret = 0;
986 while (ret < max_items) {
987 unsigned int slots_found;
988 unsigned long next_index; /* Index of next search */
989
990 if (cur_index > max_index)
991 break;
992 slots_found = __lookup(node, results + ret,
993 indices ? indices + ret : NULL,
994 cur_index, max_items - ret, &next_index);
995 ret += slots_found;
996 if (next_index == 0)
997 break; 1048 break;
998 cur_index = next_index;
999 } 1049 }
1000 1050
1001 return ret; 1051 return ret;
1002} 1052}
1003EXPORT_SYMBOL(radix_tree_gang_lookup_slot); 1053EXPORT_SYMBOL(radix_tree_gang_lookup_slot);
1004 1054
1005/*
1006 * FIXME: the two tag_get()s here should use find_next_bit() instead of
1007 * open-coding the search.
1008 */
1009static unsigned int
1010__lookup_tag(struct radix_tree_node *slot, void ***results, unsigned long index,
1011 unsigned int max_items, unsigned long *next_index, unsigned int tag)
1012{
1013 unsigned int nr_found = 0;
1014 unsigned int shift, height;
1015
1016 height = slot->height;
1017 if (height == 0)
1018 goto out;
1019 shift = (height-1) * RADIX_TREE_MAP_SHIFT;
1020
1021 while (height > 0) {
1022 unsigned long i = (index >> shift) & RADIX_TREE_MAP_MASK ;
1023
1024 for (;;) {
1025 if (tag_get(slot, tag, i))
1026 break;
1027 index &= ~((1UL << shift) - 1);
1028 index += 1UL << shift;
1029 if (index == 0)
1030 goto out; /* 32-bit wraparound */
1031 i++;
1032 if (i == RADIX_TREE_MAP_SIZE)
1033 goto out;
1034 }
1035 height--;
1036 if (height == 0) { /* Bottom level: grab some items */
1037 unsigned long j = index & RADIX_TREE_MAP_MASK;
1038
1039 for ( ; j < RADIX_TREE_MAP_SIZE; j++) {
1040 index++;
1041 if (!tag_get(slot, tag, j))
1042 continue;
1043 /*
1044 * Even though the tag was found set, we need to
1045 * recheck that we have a non-NULL node, because
1046 * if this lookup is lockless, it may have been
1047 * subsequently deleted.
1048 *
1049 * Similar care must be taken in any place that
1050 * lookup ->slots[x] without a lock (ie. can't
1051 * rely on its value remaining the same).
1052 */
1053 if (slot->slots[j]) {
1054 results[nr_found++] = &(slot->slots[j]);
1055 if (nr_found == max_items)
1056 goto out;
1057 }
1058 }
1059 }
1060 shift -= RADIX_TREE_MAP_SHIFT;
1061 slot = rcu_dereference_raw(slot->slots[i]);
1062 if (slot == NULL)
1063 break;
1064 }
1065out:
1066 *next_index = index;
1067 return nr_found;
1068}
1069
1070/** 1055/**
1071 * radix_tree_gang_lookup_tag - perform multiple lookup on a radix tree 1056 * radix_tree_gang_lookup_tag - perform multiple lookup on a radix tree
1072 * based on a tag 1057 * based on a tag
@@ -1085,52 +1070,19 @@ radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results,
1085 unsigned long first_index, unsigned int max_items, 1070 unsigned long first_index, unsigned int max_items,
1086 unsigned int tag) 1071 unsigned int tag)
1087{ 1072{
1088 struct radix_tree_node *node; 1073 struct radix_tree_iter iter;
1089 unsigned long max_index; 1074 void **slot;
1090 unsigned long cur_index = first_index; 1075 unsigned int ret = 0;
1091 unsigned int ret;
1092
1093 /* check the root's tag bit */
1094 if (!root_tag_get(root, tag))
1095 return 0;
1096 1076
1097 node = rcu_dereference_raw(root->rnode); 1077 if (unlikely(!max_items))
1098 if (!node)
1099 return 0; 1078 return 0;
1100 1079
1101 if (!radix_tree_is_indirect_ptr(node)) { 1080 radix_tree_for_each_tagged(slot, root, &iter, first_index, tag) {
1102 if (first_index > 0) 1081 results[ret] = indirect_to_ptr(rcu_dereference_raw(*slot));
1103 return 0; 1082 if (!results[ret])
1104 results[0] = node; 1083 continue;
1105 return 1; 1084 if (++ret == max_items)
1106 }
1107 node = indirect_to_ptr(node);
1108
1109 max_index = radix_tree_maxindex(node->height);
1110
1111 ret = 0;
1112 while (ret < max_items) {
1113 unsigned int nr_found, slots_found, i;
1114 unsigned long next_index; /* Index of next search */
1115
1116 if (cur_index > max_index)
1117 break;
1118 slots_found = __lookup_tag(node, (void ***)results + ret,
1119 cur_index, max_items - ret, &next_index, tag);
1120 nr_found = 0;
1121 for (i = 0; i < slots_found; i++) {
1122 struct radix_tree_node *slot;
1123 slot = *(((void ***)results)[ret + i]);
1124 if (!slot)
1125 continue;
1126 results[ret + nr_found] =
1127 indirect_to_ptr(rcu_dereference_raw(slot));
1128 nr_found++;
1129 }
1130 ret += nr_found;
1131 if (next_index == 0)
1132 break; 1085 break;
1133 cur_index = next_index;
1134 } 1086 }
1135 1087
1136 return ret; 1088 return ret;
@@ -1155,42 +1107,17 @@ radix_tree_gang_lookup_tag_slot(struct radix_tree_root *root, void ***results,
1155 unsigned long first_index, unsigned int max_items, 1107 unsigned long first_index, unsigned int max_items,
1156 unsigned int tag) 1108 unsigned int tag)
1157{ 1109{
1158 struct radix_tree_node *node; 1110 struct radix_tree_iter iter;
1159 unsigned long max_index; 1111 void **slot;
1160 unsigned long cur_index = first_index; 1112 unsigned int ret = 0;
1161 unsigned int ret;
1162
1163 /* check the root's tag bit */
1164 if (!root_tag_get(root, tag))
1165 return 0;
1166 1113
1167 node = rcu_dereference_raw(root->rnode); 1114 if (unlikely(!max_items))
1168 if (!node)
1169 return 0; 1115 return 0;
1170 1116
1171 if (!radix_tree_is_indirect_ptr(node)) { 1117 radix_tree_for_each_tagged(slot, root, &iter, first_index, tag) {
1172 if (first_index > 0) 1118 results[ret] = slot;
1173 return 0; 1119 if (++ret == max_items)
1174 results[0] = (void **)&root->rnode;
1175 return 1;
1176 }
1177 node = indirect_to_ptr(node);
1178
1179 max_index = radix_tree_maxindex(node->height);
1180
1181 ret = 0;
1182 while (ret < max_items) {
1183 unsigned int slots_found;
1184 unsigned long next_index; /* Index of next search */
1185
1186 if (cur_index > max_index)
1187 break; 1120 break;
1188 slots_found = __lookup_tag(node, results + ret,
1189 cur_index, max_items - ret, &next_index, tag);
1190 ret += slots_found;
1191 if (next_index == 0)
1192 break;
1193 cur_index = next_index;
1194 } 1121 }
1195 1122
1196 return ret; 1123 return ret;
@@ -1299,7 +1226,7 @@ static inline void radix_tree_shrink(struct radix_tree_root *root)
1299 /* try to shrink tree height */ 1226 /* try to shrink tree height */
1300 while (root->height > 0) { 1227 while (root->height > 0) {
1301 struct radix_tree_node *to_free = root->rnode; 1228 struct radix_tree_node *to_free = root->rnode;
1302 void *newptr; 1229 struct radix_tree_node *slot;
1303 1230
1304 BUG_ON(!radix_tree_is_indirect_ptr(to_free)); 1231 BUG_ON(!radix_tree_is_indirect_ptr(to_free));
1305 to_free = indirect_to_ptr(to_free); 1232 to_free = indirect_to_ptr(to_free);
@@ -1320,10 +1247,12 @@ static inline void radix_tree_shrink(struct radix_tree_root *root)
1320 * (to_free->slots[0]), it will be safe to dereference the new 1247 * (to_free->slots[0]), it will be safe to dereference the new
1321 * one (root->rnode) as far as dependent read barriers go. 1248 * one (root->rnode) as far as dependent read barriers go.
1322 */ 1249 */
1323 newptr = to_free->slots[0]; 1250 slot = to_free->slots[0];
1324 if (root->height > 1) 1251 if (root->height > 1) {
1325 newptr = ptr_to_indirect(newptr); 1252 slot->parent = NULL;
1326 root->rnode = newptr; 1253 slot = ptr_to_indirect(slot);
1254 }
1255 root->rnode = slot;
1327 root->height--; 1256 root->height--;
1328 1257
1329 /* 1258 /*
@@ -1363,16 +1292,12 @@ static inline void radix_tree_shrink(struct radix_tree_root *root)
1363 */ 1292 */
1364void *radix_tree_delete(struct radix_tree_root *root, unsigned long index) 1293void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
1365{ 1294{
1366 /* 1295 struct radix_tree_node *node = NULL;
1367 * The radix tree path needs to be one longer than the maximum path
1368 * since the "list" is null terminated.
1369 */
1370 struct radix_tree_path path[RADIX_TREE_MAX_PATH + 1], *pathp = path;
1371 struct radix_tree_node *slot = NULL; 1296 struct radix_tree_node *slot = NULL;
1372 struct radix_tree_node *to_free; 1297 struct radix_tree_node *to_free;
1373 unsigned int height, shift; 1298 unsigned int height, shift;
1374 int tag; 1299 int tag;
1375 int offset; 1300 int uninitialized_var(offset);
1376 1301
1377 height = root->height; 1302 height = root->height;
1378 if (index > radix_tree_maxindex(height)) 1303 if (index > radix_tree_maxindex(height))
@@ -1385,39 +1310,35 @@ void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
1385 goto out; 1310 goto out;
1386 } 1311 }
1387 slot = indirect_to_ptr(slot); 1312 slot = indirect_to_ptr(slot);
1388 1313 shift = height * RADIX_TREE_MAP_SHIFT;
1389 shift = (height - 1) * RADIX_TREE_MAP_SHIFT;
1390 pathp->node = NULL;
1391 1314
1392 do { 1315 do {
1393 if (slot == NULL) 1316 if (slot == NULL)
1394 goto out; 1317 goto out;
1395 1318
1396 pathp++; 1319 shift -= RADIX_TREE_MAP_SHIFT;
1397 offset = (index >> shift) & RADIX_TREE_MAP_MASK; 1320 offset = (index >> shift) & RADIX_TREE_MAP_MASK;
1398 pathp->offset = offset; 1321 node = slot;
1399 pathp->node = slot;
1400 slot = slot->slots[offset]; 1322 slot = slot->slots[offset];
1401 shift -= RADIX_TREE_MAP_SHIFT; 1323 } while (shift);
1402 height--;
1403 } while (height > 0);
1404 1324
1405 if (slot == NULL) 1325 if (slot == NULL)
1406 goto out; 1326 goto out;
1407 1327
1408 /* 1328 /*
1409 * Clear all tags associated with the just-deleted item 1329 * Clear all tags associated with the item to be deleted.
1330 * This way of doing it would be inefficient, but seldom is any set.
1410 */ 1331 */
1411 for (tag = 0; tag < RADIX_TREE_MAX_TAGS; tag++) { 1332 for (tag = 0; tag < RADIX_TREE_MAX_TAGS; tag++) {
1412 if (tag_get(pathp->node, tag, pathp->offset)) 1333 if (tag_get(node, tag, offset))
1413 radix_tree_tag_clear(root, index, tag); 1334 radix_tree_tag_clear(root, index, tag);
1414 } 1335 }
1415 1336
1416 to_free = NULL; 1337 to_free = NULL;
1417 /* Now free the nodes we do not need anymore */ 1338 /* Now free the nodes we do not need anymore */
1418 while (pathp->node) { 1339 while (node) {
1419 pathp->node->slots[pathp->offset] = NULL; 1340 node->slots[offset] = NULL;
1420 pathp->node->count--; 1341 node->count--;
1421 /* 1342 /*
1422 * Queue the node for deferred freeing after the 1343 * Queue the node for deferred freeing after the
1423 * last reference to it disappears (set NULL, above). 1344 * last reference to it disappears (set NULL, above).
@@ -1425,17 +1346,20 @@ void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
1425 if (to_free) 1346 if (to_free)
1426 radix_tree_node_free(to_free); 1347 radix_tree_node_free(to_free);
1427 1348
1428 if (pathp->node->count) { 1349 if (node->count) {
1429 if (pathp->node == indirect_to_ptr(root->rnode)) 1350 if (node == indirect_to_ptr(root->rnode))
1430 radix_tree_shrink(root); 1351 radix_tree_shrink(root);
1431 goto out; 1352 goto out;
1432 } 1353 }
1433 1354
1434 /* Node with zero slots in use so free it */ 1355 /* Node with zero slots in use so free it */
1435 to_free = pathp->node; 1356 to_free = node;
1436 pathp--;
1437 1357
1358 index >>= RADIX_TREE_MAP_SHIFT;
1359 offset = index & RADIX_TREE_MAP_MASK;
1360 node = node->parent;
1438 } 1361 }
1362
1439 root_tag_clear_all(root); 1363 root_tag_clear_all(root);
1440 root->height = 0; 1364 root->height = 0;
1441 root->rnode = NULL; 1365 root->rnode = NULL;
diff --git a/lib/raid6/altivec.uc b/lib/raid6/altivec.uc
index 2654d5c854be..b71012b756f4 100644
--- a/lib/raid6/altivec.uc
+++ b/lib/raid6/altivec.uc
@@ -28,8 +28,8 @@
28 28
29#include <altivec.h> 29#include <altivec.h>
30#ifdef __KERNEL__ 30#ifdef __KERNEL__
31# include <asm/system.h>
32# include <asm/cputable.h> 31# include <asm/cputable.h>
32# include <asm/switch_to.h>
33#endif 33#endif
34 34
35/* 35/*
diff --git a/lib/random32.c b/lib/random32.c
index fc3545a32771..938bde5876ac 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -35,7 +35,7 @@
35 35
36#include <linux/types.h> 36#include <linux/types.h>
37#include <linux/percpu.h> 37#include <linux/percpu.h>
38#include <linux/module.h> 38#include <linux/export.h>
39#include <linux/jiffies.h> 39#include <linux/jiffies.h>
40#include <linux/random.h> 40#include <linux/random.h>
41 41
diff --git a/lib/ratelimit.c b/lib/ratelimit.c
index c96d500577de..40e03ea2a967 100644
--- a/lib/ratelimit.c
+++ b/lib/ratelimit.c
@@ -11,7 +11,7 @@
11 11
12#include <linux/ratelimit.h> 12#include <linux/ratelimit.h>
13#include <linux/jiffies.h> 13#include <linux/jiffies.h>
14#include <linux/module.h> 14#include <linux/export.h>
15 15
16/* 16/*
17 * __ratelimit - rate limiting 17 * __ratelimit - rate limiting
diff --git a/lib/rational.c b/lib/rational.c
index 3ed247b80662..d326da3976f5 100644
--- a/lib/rational.c
+++ b/lib/rational.c
@@ -7,7 +7,8 @@
7 */ 7 */
8 8
9#include <linux/rational.h> 9#include <linux/rational.h>
10#include <linux/module.h> 10#include <linux/compiler.h>
11#include <linux/export.h>
11 12
12/* 13/*
13 * calculate best rational approximation for a given fraction 14 * calculate best rational approximation for a given fraction
diff --git a/lib/rbtree.c b/lib/rbtree.c
index a16be19a1305..d4175565dc2c 100644
--- a/lib/rbtree.c
+++ b/lib/rbtree.c
@@ -21,7 +21,7 @@
21*/ 21*/
22 22
23#include <linux/rbtree.h> 23#include <linux/rbtree.h>
24#include <linux/module.h> 24#include <linux/export.h>
25 25
26static void __rb_rotate_left(struct rb_node *node, struct rb_root *root) 26static void __rb_rotate_left(struct rb_node *node, struct rb_root *root)
27{ 27{
diff --git a/lib/rwsem-spinlock.c b/lib/rwsem-spinlock.c
index f2393c21fe85..7e0d6a58fc83 100644
--- a/lib/rwsem-spinlock.c
+++ b/lib/rwsem-spinlock.c
@@ -7,7 +7,7 @@
7 */ 7 */
8#include <linux/rwsem.h> 8#include <linux/rwsem.h>
9#include <linux/sched.h> 9#include <linux/sched.h>
10#include <linux/module.h> 10#include <linux/export.h>
11 11
12struct rwsem_waiter { 12struct rwsem_waiter {
13 struct list_head list; 13 struct list_head list;
diff --git a/lib/rwsem.c b/lib/rwsem.c
index 410aa1189b13..8337e1b9bb8d 100644
--- a/lib/rwsem.c
+++ b/lib/rwsem.c
@@ -6,7 +6,7 @@
6#include <linux/rwsem.h> 6#include <linux/rwsem.h>
7#include <linux/sched.h> 7#include <linux/sched.h>
8#include <linux/init.h> 8#include <linux/init.h>
9#include <linux/module.h> 9#include <linux/export.h>
10 10
11/* 11/*
12 * Initialize an rwsem: 12 * Initialize an rwsem:
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index 4ceb05d772ae..6096e89bee55 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -6,7 +6,7 @@
6 * This source code is licensed under the GNU General Public License, 6 * This source code is licensed under the GNU General Public License,
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/export.h>
10#include <linux/slab.h> 10#include <linux/slab.h>
11#include <linux/scatterlist.h> 11#include <linux/scatterlist.h>
12#include <linux/highmem.h> 12#include <linux/highmem.h>
@@ -390,7 +390,7 @@ bool sg_miter_next(struct sg_mapping_iter *miter)
390 miter->consumed = miter->length; 390 miter->consumed = miter->length;
391 391
392 if (miter->__flags & SG_MITER_ATOMIC) 392 if (miter->__flags & SG_MITER_ATOMIC)
393 miter->addr = kmap_atomic(miter->page, KM_BIO_SRC_IRQ) + off; 393 miter->addr = kmap_atomic(miter->page) + off;
394 else 394 else
395 miter->addr = kmap(miter->page) + off; 395 miter->addr = kmap(miter->page) + off;
396 396
@@ -424,7 +424,7 @@ void sg_miter_stop(struct sg_mapping_iter *miter)
424 424
425 if (miter->__flags & SG_MITER_ATOMIC) { 425 if (miter->__flags & SG_MITER_ATOMIC) {
426 WARN_ON(!irqs_disabled()); 426 WARN_ON(!irqs_disabled());
427 kunmap_atomic(miter->addr, KM_BIO_SRC_IRQ); 427 kunmap_atomic(miter->addr);
428 } else 428 } else
429 kunmap(miter->page); 429 kunmap(miter->page);
430 430
diff --git a/lib/sha1.c b/lib/sha1.c
index 1de509a159c8..1df191e04a24 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -6,7 +6,7 @@
6 */ 6 */
7 7
8#include <linux/kernel.h> 8#include <linux/kernel.h>
9#include <linux/module.h> 9#include <linux/export.h>
10#include <linux/bitops.h> 10#include <linux/bitops.h>
11#include <linux/cryptohash.h> 11#include <linux/cryptohash.h>
12#include <asm/unaligned.h> 12#include <asm/unaligned.h>
diff --git a/lib/smp_processor_id.c b/lib/smp_processor_id.c
index 503f087382a4..4c0d0e51d49e 100644
--- a/lib/smp_processor_id.c
+++ b/lib/smp_processor_id.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * DEBUG_PREEMPT variant of smp_processor_id(). 4 * DEBUG_PREEMPT variant of smp_processor_id().
5 */ 5 */
6#include <linux/module.h> 6#include <linux/export.h>
7#include <linux/kallsyms.h> 7#include <linux/kallsyms.h>
8#include <linux/sched.h> 8#include <linux/sched.h>
9 9
diff --git a/lib/spinlock_debug.c b/lib/spinlock_debug.c
index 5f3eacdd6178..525d160d44f0 100644
--- a/lib/spinlock_debug.c
+++ b/lib/spinlock_debug.c
@@ -11,7 +11,7 @@
11#include <linux/interrupt.h> 11#include <linux/interrupt.h>
12#include <linux/debug_locks.h> 12#include <linux/debug_locks.h>
13#include <linux/delay.h> 13#include <linux/delay.h>
14#include <linux/module.h> 14#include <linux/export.h>
15 15
16void __raw_spin_lock_init(raw_spinlock_t *lock, const char *name, 16void __raw_spin_lock_init(raw_spinlock_t *lock, const char *name,
17 struct lock_class_key *key) 17 struct lock_class_key *key)
diff --git a/lib/string.c b/lib/string.c
index dc4a86341f91..e5878de4f101 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -22,7 +22,10 @@
22#include <linux/types.h> 22#include <linux/types.h>
23#include <linux/string.h> 23#include <linux/string.h>
24#include <linux/ctype.h> 24#include <linux/ctype.h>
25#include <linux/module.h> 25#include <linux/kernel.h>
26#include <linux/export.h>
27#include <linux/bug.h>
28#include <linux/errno.h>
26 29
27#ifndef __HAVE_ARCH_STRNICMP 30#ifndef __HAVE_ARCH_STRNICMP
28/** 31/**
@@ -785,12 +788,24 @@ void *memchr_inv(const void *start, int c, size_t bytes)
785 if (bytes <= 16) 788 if (bytes <= 16)
786 return check_bytes8(start, value, bytes); 789 return check_bytes8(start, value, bytes);
787 790
788 value64 = value | value << 8 | value << 16 | value << 24; 791 value64 = value;
789 value64 = (value64 & 0xffffffff) | value64 << 32; 792#if defined(ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64
790 prefix = 8 - ((unsigned long)start) % 8; 793 value64 *= 0x0101010101010101;
794#elif defined(ARCH_HAS_FAST_MULTIPLIER)
795 value64 *= 0x01010101;
796 value64 |= value64 << 32;
797#else
798 value64 |= value64 << 8;
799 value64 |= value64 << 16;
800 value64 |= value64 << 32;
801#endif
791 802
803 prefix = (unsigned long)start % 8;
792 if (prefix) { 804 if (prefix) {
793 u8 *r = check_bytes8(start, value, prefix); 805 u8 *r;
806
807 prefix = 8 - prefix;
808 r = check_bytes8(start, value, prefix);
794 if (r) 809 if (r)
795 return r; 810 return r;
796 start += prefix; 811 start += prefix;
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index ab431d4cc970..dd4ece372699 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -5,7 +5,7 @@
5 */ 5 */
6#include <linux/kernel.h> 6#include <linux/kernel.h>
7#include <linux/math64.h> 7#include <linux/math64.h>
8#include <linux/module.h> 8#include <linux/export.h>
9#include <linux/string_helpers.h> 9#include <linux/string_helpers.h>
10 10
11/** 11/**
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 058935ef3975..414f46ed1dcd 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -20,7 +20,7 @@
20#include <linux/cache.h> 20#include <linux/cache.h>
21#include <linux/dma-mapping.h> 21#include <linux/dma-mapping.h>
22#include <linux/mm.h> 22#include <linux/mm.h>
23#include <linux/module.h> 23#include <linux/export.h>
24#include <linux/spinlock.h> 24#include <linux/spinlock.h>
25#include <linux/string.h> 25#include <linux/string.h>
26#include <linux/swiotlb.h> 26#include <linux/swiotlb.h>
@@ -349,13 +349,12 @@ void swiotlb_bounce(phys_addr_t phys, char *dma_addr, size_t size,
349 sz = min_t(size_t, PAGE_SIZE - offset, size); 349 sz = min_t(size_t, PAGE_SIZE - offset, size);
350 350
351 local_irq_save(flags); 351 local_irq_save(flags);
352 buffer = kmap_atomic(pfn_to_page(pfn), 352 buffer = kmap_atomic(pfn_to_page(pfn));
353 KM_BOUNCE_READ);
354 if (dir == DMA_TO_DEVICE) 353 if (dir == DMA_TO_DEVICE)
355 memcpy(dma_addr, buffer + offset, sz); 354 memcpy(dma_addr, buffer + offset, sz);
356 else 355 else
357 memcpy(buffer + offset, dma_addr, sz); 356 memcpy(buffer + offset, dma_addr, sz);
358 kunmap_atomic(buffer, KM_BOUNCE_READ); 357 kunmap_atomic(buffer);
359 local_irq_restore(flags); 358 local_irq_restore(flags);
360 359
361 size -= sz; 360 size -= sz;
diff --git a/lib/syscall.c b/lib/syscall.c
index a4f7067f72fa..58710eefeac8 100644
--- a/lib/syscall.c
+++ b/lib/syscall.c
@@ -1,6 +1,6 @@
1#include <linux/ptrace.h> 1#include <linux/ptrace.h>
2#include <linux/sched.h> 2#include <linux/sched.h>
3#include <linux/module.h> 3#include <linux/export.h>
4#include <asm/syscall.h> 4#include <asm/syscall.h>
5 5
6static int collect_syscall(struct task_struct *target, long *callno, 6static int collect_syscall(struct task_struct *target, long *callno,
diff --git a/lib/timerqueue.c b/lib/timerqueue.c
index 191176a43e9a..a382e4a32609 100644
--- a/lib/timerqueue.c
+++ b/lib/timerqueue.c
@@ -22,9 +22,10 @@
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */ 23 */
24 24
25#include <linux/bug.h>
25#include <linux/timerqueue.h> 26#include <linux/timerqueue.h>
26#include <linux/rbtree.h> 27#include <linux/rbtree.h>
27#include <linux/module.h> 28#include <linux/export.h>
28 29
29/** 30/**
30 * timerqueue_add - Adds timer to timerqueue. 31 * timerqueue_add - Adds timer to timerqueue.
diff --git a/lib/uuid.c b/lib/uuid.c
index 8fadd7cef46c..52a6fe6387de 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/module.h> 22#include <linux/export.h>
23#include <linux/uuid.h> 23#include <linux/uuid.h>
24#include <linux/random.h> 24#include <linux/random.h>
25 25
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 8e75003d62f6..abbabec9720a 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -17,7 +17,7 @@
17 */ 17 */
18 18
19#include <stdarg.h> 19#include <stdarg.h>
20#include <linux/module.h> 20#include <linux/module.h> /* for KSYM_SYMBOL_LEN */
21#include <linux/types.h> 21#include <linux/types.h>
22#include <linux/string.h> 22#include <linux/string.h>
23#include <linux/ctype.h> 23#include <linux/ctype.h>
@@ -212,6 +212,26 @@ char *put_dec(char *buf, unsigned long long num)
212 } 212 }
213} 213}
214 214
215/*
216 * Convert passed number to decimal string.
217 * Returns the length of string. On buffer overflow, returns 0.
218 *
219 * If speed is not important, use snprintf(). It's easy to read the code.
220 */
221int num_to_str(char *buf, int size, unsigned long long num)
222{
223 char tmp[21]; /* Enough for 2^64 in decimal */
224 int idx, len;
225
226 len = put_dec(tmp, num) - tmp;
227
228 if (len > size)
229 return 0;
230 for (idx = 0; idx < len; ++idx)
231 buf[idx] = tmp[len - idx - 1];
232 return len;
233}
234
215#define ZEROPAD 1 /* pad with zero */ 235#define ZEROPAD 1 /* pad with zero */
216#define SIGN 2 /* unsigned/signed long */ 236#define SIGN 2 /* unsigned/signed long */
217#define PLUS 4 /* show plus */ 237#define PLUS 4 /* show plus */
@@ -891,9 +911,15 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
891 case 'U': 911 case 'U':
892 return uuid_string(buf, end, ptr, spec, fmt); 912 return uuid_string(buf, end, ptr, spec, fmt);
893 case 'V': 913 case 'V':
894 return buf + vsnprintf(buf, end > buf ? end - buf : 0, 914 {
895 ((struct va_format *)ptr)->fmt, 915 va_list va;
896 *(((struct va_format *)ptr)->va)); 916
917 va_copy(va, *((struct va_format *)ptr)->va);
918 buf += vsnprintf(buf, end > buf ? end - buf : 0,
919 ((struct va_format *)ptr)->fmt, va);
920 va_end(va);
921 return buf;
922 }
897 case 'K': 923 case 'K':
898 /* 924 /*
899 * %pK cannot be used in IRQ context because its test 925 * %pK cannot be used in IRQ context because its test