aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Kconfig.debug29
-rw-r--r--lib/bcd.c8
-rw-r--r--lib/crc32.c9
-rw-r--r--lib/decompress.c9
-rw-r--r--lib/digsig.c6
-rw-r--r--lib/dynamic_debug.c56
-rw-r--r--lib/flex_proportions.c2
-rw-r--r--lib/gcd.c3
-rw-r--r--lib/gen_crc32table.c6
-rw-r--r--lib/genalloc.c88
-rw-r--r--lib/idr.c32
-rw-r--r--lib/kobject_uevent.c5
-rw-r--r--lib/nlattr.c4
-rw-r--r--lib/parser.c10
-rw-r--r--lib/plist.c4
-rw-r--r--lib/scatterlist.c16
-rw-r--r--lib/spinlock_debug.c32
-rw-r--r--lib/swiotlb.c33
-rw-r--r--lib/vsprintf.c139
19 files changed, 326 insertions, 165 deletions
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 2403a63b5da..7fba3a98967 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -196,12 +196,13 @@ config LOCKUP_DETECTOR
196 thresholds can be controlled through the sysctl watchdog_thresh. 196 thresholds can be controlled through the sysctl watchdog_thresh.
197 197
198config HARDLOCKUP_DETECTOR 198config HARDLOCKUP_DETECTOR
199 def_bool LOCKUP_DETECTOR && PERF_EVENTS && HAVE_PERF_EVENTS_NMI && \ 199 def_bool y
200 !HAVE_NMI_WATCHDOG 200 depends on LOCKUP_DETECTOR && !HAVE_NMI_WATCHDOG
201 depends on PERF_EVENTS && HAVE_PERF_EVENTS_NMI
201 202
202config BOOTPARAM_HARDLOCKUP_PANIC 203config BOOTPARAM_HARDLOCKUP_PANIC
203 bool "Panic (Reboot) On Hard Lockups" 204 bool "Panic (Reboot) On Hard Lockups"
204 depends on LOCKUP_DETECTOR 205 depends on HARDLOCKUP_DETECTOR
205 help 206 help
206 Say Y here to enable the kernel to panic on "hard lockups", 207 Say Y here to enable the kernel to panic on "hard lockups",
207 which are bugs that cause the kernel to loop in kernel 208 which are bugs that cause the kernel to loop in kernel
@@ -212,7 +213,7 @@ config BOOTPARAM_HARDLOCKUP_PANIC
212 213
213config BOOTPARAM_HARDLOCKUP_PANIC_VALUE 214config BOOTPARAM_HARDLOCKUP_PANIC_VALUE
214 int 215 int
215 depends on LOCKUP_DETECTOR 216 depends on HARDLOCKUP_DETECTOR
216 range 0 1 217 range 0 1
217 default 0 if !BOOTPARAM_HARDLOCKUP_PANIC 218 default 0 if !BOOTPARAM_HARDLOCKUP_PANIC
218 default 1 if BOOTPARAM_HARDLOCKUP_PANIC 219 default 1 if BOOTPARAM_HARDLOCKUP_PANIC
@@ -452,7 +453,8 @@ config SLUB_STATS
452config DEBUG_KMEMLEAK 453config DEBUG_KMEMLEAK
453 bool "Kernel memory leak detector" 454 bool "Kernel memory leak detector"
454 depends on DEBUG_KERNEL && EXPERIMENTAL && \ 455 depends on DEBUG_KERNEL && EXPERIMENTAL && \
455 (X86 || ARM || PPC || MIPS || S390 || SPARC64 || SUPERH || MICROBLAZE || TILE) 456 (X86 || ARM || PPC || MIPS || S390 || SPARC64 || SUPERH || \
457 MICROBLAZE || TILE || ARM64)
456 458
457 select DEBUG_FS 459 select DEBUG_FS
458 select STACKTRACE if STACKTRACE_SUPPORT 460 select STACKTRACE if STACKTRACE_SUPPORT
@@ -629,6 +631,20 @@ config PROVE_RCU_REPEATEDLY
629 631
630 Say N if you are unsure. 632 Say N if you are unsure.
631 633
634config PROVE_RCU_DELAY
635 bool "RCU debugging: preemptible RCU race provocation"
636 depends on DEBUG_KERNEL && PREEMPT_RCU
637 default n
638 help
639 There is a class of races that involve an unlikely preemption
640 of __rcu_read_unlock() just after ->rcu_read_lock_nesting has
641 been set to INT_MIN. This feature inserts a delay at that
642 point to increase the probability of these races.
643
644 Say Y to increase probability of preemption of __rcu_read_unlock().
645
646 Say N if you are unsure.
647
632config SPARSE_RCU_POINTER 648config SPARSE_RCU_POINTER
633 bool "RCU debugging: sparse-based checks for pointer usage" 649 bool "RCU debugging: sparse-based checks for pointer usage"
634 default n 650 default n
@@ -739,7 +755,8 @@ config DEBUG_BUGVERBOSE
739 bool "Verbose BUG() reporting (adds 70K)" if DEBUG_KERNEL && EXPERT 755 bool "Verbose BUG() reporting (adds 70K)" if DEBUG_KERNEL && EXPERT
740 depends on BUG 756 depends on BUG
741 depends on ARM || AVR32 || M32R || M68K || SPARC32 || SPARC64 || \ 757 depends on ARM || AVR32 || M32R || M68K || SPARC32 || SPARC64 || \
742 FRV || SUPERH || GENERIC_BUG || BLACKFIN || MN10300 || TILE 758 FRV || SUPERH || GENERIC_BUG || BLACKFIN || MN10300 || \
759 TILE || ARM64
743 default y 760 default y
744 help 761 help
745 Say Y here to make BUG() panics output the file name and line number 762 Say Y here to make BUG() panics output the file name and line number
diff --git a/lib/bcd.c b/lib/bcd.c
index 55efaf74234..40d304efe27 100644
--- a/lib/bcd.c
+++ b/lib/bcd.c
@@ -1,14 +1,14 @@
1#include <linux/bcd.h> 1#include <linux/bcd.h>
2#include <linux/export.h> 2#include <linux/export.h>
3 3
4unsigned bcd2bin(unsigned char val) 4unsigned _bcd2bin(unsigned char val)
5{ 5{
6 return (val & 0x0f) + (val >> 4) * 10; 6 return (val & 0x0f) + (val >> 4) * 10;
7} 7}
8EXPORT_SYMBOL(bcd2bin); 8EXPORT_SYMBOL(_bcd2bin);
9 9
10unsigned char bin2bcd(unsigned val) 10unsigned char _bin2bcd(unsigned val)
11{ 11{
12 return ((val / 10) << 4) + val % 10; 12 return ((val / 10) << 4) + val % 10;
13} 13}
14EXPORT_SYMBOL(bin2bcd); 14EXPORT_SYMBOL(_bin2bcd);
diff --git a/lib/crc32.c b/lib/crc32.c
index 61774b8db4d..072fbd8234d 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -188,11 +188,13 @@ u32 __pure __crc32c_le(u32 crc, unsigned char const *p, size_t len)
188#else 188#else
189u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) 189u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)
190{ 190{
191 return crc32_le_generic(crc, p, len, crc32table_le, CRCPOLY_LE); 191 return crc32_le_generic(crc, p, len,
192 (const u32 (*)[256])crc32table_le, CRCPOLY_LE);
192} 193}
193u32 __pure __crc32c_le(u32 crc, unsigned char const *p, size_t len) 194u32 __pure __crc32c_le(u32 crc, unsigned char const *p, size_t len)
194{ 195{
195 return crc32_le_generic(crc, p, len, crc32ctable_le, CRC32C_POLY_LE); 196 return crc32_le_generic(crc, p, len,
197 (const u32 (*)[256])crc32ctable_le, CRC32C_POLY_LE);
196} 198}
197#endif 199#endif
198EXPORT_SYMBOL(crc32_le); 200EXPORT_SYMBOL(crc32_le);
@@ -253,7 +255,8 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
253#else 255#else
254u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) 256u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
255{ 257{
256 return crc32_be_generic(crc, p, len, crc32table_be, CRCPOLY_BE); 258 return crc32_be_generic(crc, p, len,
259 (const u32 (*)[256])crc32table_be, CRCPOLY_BE);
257} 260}
258#endif 261#endif
259EXPORT_SYMBOL(crc32_be); 262EXPORT_SYMBOL(crc32_be);
diff --git a/lib/decompress.c b/lib/decompress.c
index 3d766b7f60a..31a80427728 100644
--- a/lib/decompress.c
+++ b/lib/decompress.c
@@ -14,6 +14,7 @@
14 14
15#include <linux/types.h> 15#include <linux/types.h>
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/init.h>
17 18
18#ifndef CONFIG_DECOMPRESS_GZIP 19#ifndef CONFIG_DECOMPRESS_GZIP
19# define gunzip NULL 20# define gunzip NULL
@@ -31,11 +32,13 @@
31# define unlzo NULL 32# define unlzo NULL
32#endif 33#endif
33 34
34static const struct compress_format { 35struct compress_format {
35 unsigned char magic[2]; 36 unsigned char magic[2];
36 const char *name; 37 const char *name;
37 decompress_fn decompressor; 38 decompress_fn decompressor;
38} compressed_formats[] = { 39};
40
41static const struct compress_format compressed_formats[] __initdata = {
39 { {037, 0213}, "gzip", gunzip }, 42 { {037, 0213}, "gzip", gunzip },
40 { {037, 0236}, "gzip", gunzip }, 43 { {037, 0236}, "gzip", gunzip },
41 { {0x42, 0x5a}, "bzip2", bunzip2 }, 44 { {0x42, 0x5a}, "bzip2", bunzip2 },
@@ -45,7 +48,7 @@ static const struct compress_format {
45 { {0, 0}, NULL, NULL } 48 { {0, 0}, NULL, NULL }
46}; 49};
47 50
48decompress_fn decompress_method(const unsigned char *inbuf, int len, 51decompress_fn __init decompress_method(const unsigned char *inbuf, int len,
49 const char **name) 52 const char **name)
50{ 53{
51 const struct compress_format *cf; 54 const struct compress_format *cf;
diff --git a/lib/digsig.c b/lib/digsig.c
index 286d558033e..8c0e62975c8 100644
--- a/lib/digsig.c
+++ b/lib/digsig.c
@@ -163,9 +163,11 @@ static int digsig_verify_rsa(struct key *key,
163 memcpy(out1 + head, p, l); 163 memcpy(out1 + head, p, l);
164 164
165 err = pkcs_1_v1_5_decode_emsa(out1, len, mblen, out2, &len); 165 err = pkcs_1_v1_5_decode_emsa(out1, len, mblen, out2, &len);
166 if (err)
167 goto err;
166 168
167 if (!err && len == hlen) 169 if (len != hlen || memcmp(out2, h, hlen))
168 err = memcmp(out2, h, hlen); 170 err = -EINVAL;
169 171
170err: 172err:
171 mpi_free(in); 173 mpi_free(in);
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 7ca29a0a301..e7f7d993357 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -521,25 +521,25 @@ static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf)
521 int pos_after_tid; 521 int pos_after_tid;
522 int pos = 0; 522 int pos = 0;
523 523
524 pos += snprintf(buf + pos, remaining(pos), "%s", KERN_DEBUG); 524 *buf = '\0';
525
525 if (desc->flags & _DPRINTK_FLAGS_INCL_TID) { 526 if (desc->flags & _DPRINTK_FLAGS_INCL_TID) {
526 if (in_interrupt()) 527 if (in_interrupt())
527 pos += snprintf(buf + pos, remaining(pos), "%s ", 528 pos += snprintf(buf + pos, remaining(pos), "<intr> ");
528 "<intr>");
529 else 529 else
530 pos += snprintf(buf + pos, remaining(pos), "[%d] ", 530 pos += snprintf(buf + pos, remaining(pos), "[%d] ",
531 task_pid_vnr(current)); 531 task_pid_vnr(current));
532 } 532 }
533 pos_after_tid = pos; 533 pos_after_tid = pos;
534 if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME) 534 if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME)
535 pos += snprintf(buf + pos, remaining(pos), "%s:", 535 pos += snprintf(buf + pos, remaining(pos), "%s:",
536 desc->modname); 536 desc->modname);
537 if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME) 537 if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME)
538 pos += snprintf(buf + pos, remaining(pos), "%s:", 538 pos += snprintf(buf + pos, remaining(pos), "%s:",
539 desc->function); 539 desc->function);
540 if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO) 540 if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO)
541 pos += snprintf(buf + pos, remaining(pos), "%d:", 541 pos += snprintf(buf + pos, remaining(pos), "%d:",
542 desc->lineno); 542 desc->lineno);
543 if (pos - pos_after_tid) 543 if (pos - pos_after_tid)
544 pos += snprintf(buf + pos, remaining(pos), " "); 544 pos += snprintf(buf + pos, remaining(pos), " ");
545 if (pos >= PREFIX_SIZE) 545 if (pos >= PREFIX_SIZE)
@@ -559,9 +559,13 @@ int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
559 BUG_ON(!fmt); 559 BUG_ON(!fmt);
560 560
561 va_start(args, fmt); 561 va_start(args, fmt);
562
562 vaf.fmt = fmt; 563 vaf.fmt = fmt;
563 vaf.va = &args; 564 vaf.va = &args;
564 res = printk("%s%pV", dynamic_emit_prefix(descriptor, buf), &vaf); 565
566 res = printk(KERN_DEBUG "%s%pV",
567 dynamic_emit_prefix(descriptor, buf), &vaf);
568
565 va_end(args); 569 va_end(args);
566 570
567 return res; 571 return res;
@@ -574,15 +578,26 @@ int __dynamic_dev_dbg(struct _ddebug *descriptor,
574 struct va_format vaf; 578 struct va_format vaf;
575 va_list args; 579 va_list args;
576 int res; 580 int res;
577 char buf[PREFIX_SIZE];
578 581
579 BUG_ON(!descriptor); 582 BUG_ON(!descriptor);
580 BUG_ON(!fmt); 583 BUG_ON(!fmt);
581 584
582 va_start(args, fmt); 585 va_start(args, fmt);
586
583 vaf.fmt = fmt; 587 vaf.fmt = fmt;
584 vaf.va = &args; 588 vaf.va = &args;
585 res = __dev_printk(dynamic_emit_prefix(descriptor, buf), dev, &vaf); 589
590 if (!dev) {
591 res = printk(KERN_DEBUG "(NULL device *): %pV", &vaf);
592 } else {
593 char buf[PREFIX_SIZE];
594
595 res = dev_printk_emit(7, dev, "%s%s %s: %pV",
596 dynamic_emit_prefix(descriptor, buf),
597 dev_driver_string(dev), dev_name(dev),
598 &vaf);
599 }
600
586 va_end(args); 601 va_end(args);
587 602
588 return res; 603 return res;
@@ -592,20 +607,35 @@ EXPORT_SYMBOL(__dynamic_dev_dbg);
592#ifdef CONFIG_NET 607#ifdef CONFIG_NET
593 608
594int __dynamic_netdev_dbg(struct _ddebug *descriptor, 609int __dynamic_netdev_dbg(struct _ddebug *descriptor,
595 const struct net_device *dev, const char *fmt, ...) 610 const struct net_device *dev, const char *fmt, ...)
596{ 611{
597 struct va_format vaf; 612 struct va_format vaf;
598 va_list args; 613 va_list args;
599 int res; 614 int res;
600 char buf[PREFIX_SIZE];
601 615
602 BUG_ON(!descriptor); 616 BUG_ON(!descriptor);
603 BUG_ON(!fmt); 617 BUG_ON(!fmt);
604 618
605 va_start(args, fmt); 619 va_start(args, fmt);
620
606 vaf.fmt = fmt; 621 vaf.fmt = fmt;
607 vaf.va = &args; 622 vaf.va = &args;
608 res = __netdev_printk(dynamic_emit_prefix(descriptor, buf), dev, &vaf); 623
624 if (dev && dev->dev.parent) {
625 char buf[PREFIX_SIZE];
626
627 res = dev_printk_emit(7, dev->dev.parent,
628 "%s%s %s %s: %pV",
629 dynamic_emit_prefix(descriptor, buf),
630 dev_driver_string(dev->dev.parent),
631 dev_name(dev->dev.parent),
632 netdev_name(dev), &vaf);
633 } else if (dev) {
634 res = printk(KERN_DEBUG "%s: %pV", netdev_name(dev), &vaf);
635 } else {
636 res = printk(KERN_DEBUG "(NULL net_device): %pV", &vaf);
637 }
638
609 va_end(args); 639 va_end(args);
610 640
611 return res; 641 return res;
diff --git a/lib/flex_proportions.c b/lib/flex_proportions.c
index c785554f952..ebf3bac460b 100644
--- a/lib/flex_proportions.c
+++ b/lib/flex_proportions.c
@@ -62,7 +62,7 @@ void fprop_global_destroy(struct fprop_global *p)
62 */ 62 */
63bool fprop_new_period(struct fprop_global *p, int periods) 63bool fprop_new_period(struct fprop_global *p, int periods)
64{ 64{
65 u64 events; 65 s64 events;
66 unsigned long flags; 66 unsigned long flags;
67 67
68 local_irq_save(flags); 68 local_irq_save(flags);
diff --git a/lib/gcd.c b/lib/gcd.c
index cce4f3cd14b..3657f129d7b 100644
--- a/lib/gcd.c
+++ b/lib/gcd.c
@@ -9,6 +9,9 @@ unsigned long gcd(unsigned long a, unsigned long b)
9 9
10 if (a < b) 10 if (a < b)
11 swap(a, b); 11 swap(a, b);
12
13 if (!b)
14 return a;
12 while ((r = a % b) != 0) { 15 while ((r = a % b) != 0) {
13 a = b; 16 a = b;
14 b = r; 17 b = r;
diff --git a/lib/gen_crc32table.c b/lib/gen_crc32table.c
index 8f8d5439e2d..71fcfcd9641 100644
--- a/lib/gen_crc32table.c
+++ b/lib/gen_crc32table.c
@@ -109,7 +109,7 @@ int main(int argc, char** argv)
109 109
110 if (CRC_LE_BITS > 1) { 110 if (CRC_LE_BITS > 1) {
111 crc32init_le(); 111 crc32init_le();
112 printf("static const u32 __cacheline_aligned " 112 printf("static u32 __cacheline_aligned "
113 "crc32table_le[%d][%d] = {", 113 "crc32table_le[%d][%d] = {",
114 LE_TABLE_ROWS, LE_TABLE_SIZE); 114 LE_TABLE_ROWS, LE_TABLE_SIZE);
115 output_table(crc32table_le, LE_TABLE_ROWS, 115 output_table(crc32table_le, LE_TABLE_ROWS,
@@ -119,7 +119,7 @@ int main(int argc, char** argv)
119 119
120 if (CRC_BE_BITS > 1) { 120 if (CRC_BE_BITS > 1) {
121 crc32init_be(); 121 crc32init_be();
122 printf("static const u32 __cacheline_aligned " 122 printf("static u32 __cacheline_aligned "
123 "crc32table_be[%d][%d] = {", 123 "crc32table_be[%d][%d] = {",
124 BE_TABLE_ROWS, BE_TABLE_SIZE); 124 BE_TABLE_ROWS, BE_TABLE_SIZE);
125 output_table(crc32table_be, LE_TABLE_ROWS, 125 output_table(crc32table_be, LE_TABLE_ROWS,
@@ -128,7 +128,7 @@ int main(int argc, char** argv)
128 } 128 }
129 if (CRC_LE_BITS > 1) { 129 if (CRC_LE_BITS > 1) {
130 crc32cinit_le(); 130 crc32cinit_le();
131 printf("static const u32 __cacheline_aligned " 131 printf("static u32 __cacheline_aligned "
132 "crc32ctable_le[%d][%d] = {", 132 "crc32ctable_le[%d][%d] = {",
133 LE_TABLE_ROWS, LE_TABLE_SIZE); 133 LE_TABLE_ROWS, LE_TABLE_SIZE);
134 output_table(crc32ctable_le, LE_TABLE_ROWS, 134 output_table(crc32ctable_le, LE_TABLE_ROWS,
diff --git a/lib/genalloc.c b/lib/genalloc.c
index 6bc04aab6ec..ca208a92628 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -152,6 +152,8 @@ struct gen_pool *gen_pool_create(int min_alloc_order, int nid)
152 spin_lock_init(&pool->lock); 152 spin_lock_init(&pool->lock);
153 INIT_LIST_HEAD(&pool->chunks); 153 INIT_LIST_HEAD(&pool->chunks);
154 pool->min_alloc_order = min_alloc_order; 154 pool->min_alloc_order = min_alloc_order;
155 pool->algo = gen_pool_first_fit;
156 pool->data = NULL;
155 } 157 }
156 return pool; 158 return pool;
157} 159}
@@ -255,8 +257,9 @@ EXPORT_SYMBOL(gen_pool_destroy);
255 * @size: number of bytes to allocate from the pool 257 * @size: number of bytes to allocate from the pool
256 * 258 *
257 * Allocate the requested number of bytes from the specified pool. 259 * Allocate the requested number of bytes from the specified pool.
258 * Uses a first-fit algorithm. Can not be used in NMI handler on 260 * Uses the pool allocation function (with first-fit algorithm by default).
259 * architectures without NMI-safe cmpxchg implementation. 261 * Can not be used in NMI handler on architectures without
262 * NMI-safe cmpxchg implementation.
260 */ 263 */
261unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size) 264unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size)
262{ 265{
@@ -280,8 +283,8 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size)
280 283
281 end_bit = (chunk->end_addr - chunk->start_addr) >> order; 284 end_bit = (chunk->end_addr - chunk->start_addr) >> order;
282retry: 285retry:
283 start_bit = bitmap_find_next_zero_area(chunk->bits, end_bit, 286 start_bit = pool->algo(chunk->bits, end_bit, start_bit, nbits,
284 start_bit, nbits, 0); 287 pool->data);
285 if (start_bit >= end_bit) 288 if (start_bit >= end_bit)
286 continue; 289 continue;
287 remain = bitmap_set_ll(chunk->bits, start_bit, nbits); 290 remain = bitmap_set_ll(chunk->bits, start_bit, nbits);
@@ -400,3 +403,80 @@ size_t gen_pool_size(struct gen_pool *pool)
400 return size; 403 return size;
401} 404}
402EXPORT_SYMBOL_GPL(gen_pool_size); 405EXPORT_SYMBOL_GPL(gen_pool_size);
406
407/**
408 * gen_pool_set_algo - set the allocation algorithm
409 * @pool: pool to change allocation algorithm
410 * @algo: custom algorithm function
411 * @data: additional data used by @algo
412 *
413 * Call @algo for each memory allocation in the pool.
414 * If @algo is NULL use gen_pool_first_fit as default
415 * memory allocation function.
416 */
417void gen_pool_set_algo(struct gen_pool *pool, genpool_algo_t algo, void *data)
418{
419 rcu_read_lock();
420
421 pool->algo = algo;
422 if (!pool->algo)
423 pool->algo = gen_pool_first_fit;
424
425 pool->data = data;
426
427 rcu_read_unlock();
428}
429EXPORT_SYMBOL(gen_pool_set_algo);
430
431/**
432 * gen_pool_first_fit - find the first available region
433 * of memory matching the size requirement (no alignment constraint)
434 * @map: The address to base the search on
435 * @size: The bitmap size in bits
436 * @start: The bitnumber to start searching at
437 * @nr: The number of zeroed bits we're looking for
438 * @data: additional data - unused
439 */
440unsigned long gen_pool_first_fit(unsigned long *map, unsigned long size,
441 unsigned long start, unsigned int nr, void *data)
442{
443 return bitmap_find_next_zero_area(map, size, start, nr, 0);
444}
445EXPORT_SYMBOL(gen_pool_first_fit);
446
447/**
448 * gen_pool_best_fit - find the best fitting region of memory
449 * macthing the size requirement (no alignment constraint)
450 * @map: The address to base the search on
451 * @size: The bitmap size in bits
452 * @start: The bitnumber to start searching at
453 * @nr: The number of zeroed bits we're looking for
454 * @data: additional data - unused
455 *
456 * Iterate over the bitmap to find the smallest free region
457 * which we can allocate the memory.
458 */
459unsigned long gen_pool_best_fit(unsigned long *map, unsigned long size,
460 unsigned long start, unsigned int nr, void *data)
461{
462 unsigned long start_bit = size;
463 unsigned long len = size + 1;
464 unsigned long index;
465
466 index = bitmap_find_next_zero_area(map, size, start, nr, 0);
467
468 while (index < size) {
469 int next_bit = find_next_bit(map, size, index + nr);
470 if ((next_bit - index) < len) {
471 len = next_bit - index;
472 start_bit = index;
473 if (len == nr)
474 return start_bit;
475 }
476 index = bitmap_find_next_zero_area(map, size,
477 next_bit + 1, nr, 0);
478 }
479
480 return start_bit;
481}
482EXPORT_SYMBOL(gen_pool_best_fit);
diff --git a/lib/idr.c b/lib/idr.c
index 4046e29c0a9..648239079dd 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -20,7 +20,7 @@
20 * that id to this code and it returns your pointer. 20 * that id to this code and it returns your pointer.
21 21
22 * You can release ids at any time. When all ids are released, most of 22 * You can release ids at any time. When all ids are released, most of
23 * the memory is returned (we keep IDR_FREE_MAX) in a local pool so we 23 * the memory is returned (we keep MAX_IDR_FREE) in a local pool so we
24 * don't need to go to the memory "store" during an id allocate, just 24 * don't need to go to the memory "store" during an id allocate, just
25 * so you don't need to be too concerned about locking and conflicts 25 * so you don't need to be too concerned about locking and conflicts
26 * with the slab allocator. 26 * with the slab allocator.
@@ -122,7 +122,7 @@ static void idr_mark_full(struct idr_layer **pa, int id)
122 */ 122 */
123int idr_pre_get(struct idr *idp, gfp_t gfp_mask) 123int idr_pre_get(struct idr *idp, gfp_t gfp_mask)
124{ 124{
125 while (idp->id_free_cnt < IDR_FREE_MAX) { 125 while (idp->id_free_cnt < MAX_IDR_FREE) {
126 struct idr_layer *new; 126 struct idr_layer *new;
127 new = kmem_cache_zalloc(idr_layer_cache, gfp_mask); 127 new = kmem_cache_zalloc(idr_layer_cache, gfp_mask);
128 if (new == NULL) 128 if (new == NULL)
@@ -179,7 +179,7 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa)
179 sh = IDR_BITS*l; 179 sh = IDR_BITS*l;
180 id = ((id >> sh) ^ n ^ m) << sh; 180 id = ((id >> sh) ^ n ^ m) << sh;
181 } 181 }
182 if ((id >= MAX_ID_BIT) || (id < 0)) 182 if ((id >= MAX_IDR_BIT) || (id < 0))
183 return IDR_NOMORE_SPACE; 183 return IDR_NOMORE_SPACE;
184 if (l == 0) 184 if (l == 0)
185 break; 185 break;
@@ -223,7 +223,7 @@ build_up:
223 * Add a new layer to the top of the tree if the requested 223 * Add a new layer to the top of the tree if the requested
224 * id is larger than the currently allocated space. 224 * id is larger than the currently allocated space.
225 */ 225 */
226 while ((layers < (MAX_LEVEL - 1)) && (id >= (1 << (layers*IDR_BITS)))) { 226 while ((layers < (MAX_IDR_LEVEL - 1)) && (id >= (1 << (layers*IDR_BITS)))) {
227 layers++; 227 layers++;
228 if (!p->count) { 228 if (!p->count) {
229 /* special case: if the tree is currently empty, 229 /* special case: if the tree is currently empty,
@@ -265,7 +265,7 @@ build_up:
265 265
266static int idr_get_new_above_int(struct idr *idp, void *ptr, int starting_id) 266static int idr_get_new_above_int(struct idr *idp, void *ptr, int starting_id)
267{ 267{
268 struct idr_layer *pa[MAX_LEVEL]; 268 struct idr_layer *pa[MAX_IDR_LEVEL];
269 int id; 269 int id;
270 270
271 id = idr_get_empty_slot(idp, starting_id, pa); 271 id = idr_get_empty_slot(idp, starting_id, pa);
@@ -357,7 +357,7 @@ static void idr_remove_warning(int id)
357static void sub_remove(struct idr *idp, int shift, int id) 357static void sub_remove(struct idr *idp, int shift, int id)
358{ 358{
359 struct idr_layer *p = idp->top; 359 struct idr_layer *p = idp->top;
360 struct idr_layer **pa[MAX_LEVEL]; 360 struct idr_layer **pa[MAX_IDR_LEVEL];
361 struct idr_layer ***paa = &pa[0]; 361 struct idr_layer ***paa = &pa[0];
362 struct idr_layer *to_free; 362 struct idr_layer *to_free;
363 int n; 363 int n;
@@ -402,7 +402,7 @@ void idr_remove(struct idr *idp, int id)
402 struct idr_layer *to_free; 402 struct idr_layer *to_free;
403 403
404 /* Mask off upper bits we don't use for the search. */ 404 /* Mask off upper bits we don't use for the search. */
405 id &= MAX_ID_MASK; 405 id &= MAX_IDR_MASK;
406 406
407 sub_remove(idp, (idp->layers - 1) * IDR_BITS, id); 407 sub_remove(idp, (idp->layers - 1) * IDR_BITS, id);
408 if (idp->top && idp->top->count == 1 && (idp->layers > 1) && 408 if (idp->top && idp->top->count == 1 && (idp->layers > 1) &&
@@ -420,7 +420,7 @@ void idr_remove(struct idr *idp, int id)
420 to_free->bitmap = to_free->count = 0; 420 to_free->bitmap = to_free->count = 0;
421 free_layer(to_free); 421 free_layer(to_free);
422 } 422 }
423 while (idp->id_free_cnt >= IDR_FREE_MAX) { 423 while (idp->id_free_cnt >= MAX_IDR_FREE) {
424 p = get_from_free_list(idp); 424 p = get_from_free_list(idp);
425 /* 425 /*
426 * Note: we don't call the rcu callback here, since the only 426 * Note: we don't call the rcu callback here, since the only
@@ -451,7 +451,7 @@ void idr_remove_all(struct idr *idp)
451 int n, id, max; 451 int n, id, max;
452 int bt_mask; 452 int bt_mask;
453 struct idr_layer *p; 453 struct idr_layer *p;
454 struct idr_layer *pa[MAX_LEVEL]; 454 struct idr_layer *pa[MAX_IDR_LEVEL];
455 struct idr_layer **paa = &pa[0]; 455 struct idr_layer **paa = &pa[0];
456 456
457 n = idp->layers * IDR_BITS; 457 n = idp->layers * IDR_BITS;
@@ -517,7 +517,7 @@ void *idr_find(struct idr *idp, int id)
517 n = (p->layer+1) * IDR_BITS; 517 n = (p->layer+1) * IDR_BITS;
518 518
519 /* Mask off upper bits we don't use for the search. */ 519 /* Mask off upper bits we don't use for the search. */
520 id &= MAX_ID_MASK; 520 id &= MAX_IDR_MASK;
521 521
522 if (id >= (1 << n)) 522 if (id >= (1 << n))
523 return NULL; 523 return NULL;
@@ -555,7 +555,7 @@ int idr_for_each(struct idr *idp,
555{ 555{
556 int n, id, max, error = 0; 556 int n, id, max, error = 0;
557 struct idr_layer *p; 557 struct idr_layer *p;
558 struct idr_layer *pa[MAX_LEVEL]; 558 struct idr_layer *pa[MAX_IDR_LEVEL];
559 struct idr_layer **paa = &pa[0]; 559 struct idr_layer **paa = &pa[0];
560 560
561 n = idp->layers * IDR_BITS; 561 n = idp->layers * IDR_BITS;
@@ -601,7 +601,7 @@ EXPORT_SYMBOL(idr_for_each);
601 */ 601 */
602void *idr_get_next(struct idr *idp, int *nextidp) 602void *idr_get_next(struct idr *idp, int *nextidp)
603{ 603{
604 struct idr_layer *p, *pa[MAX_LEVEL]; 604 struct idr_layer *p, *pa[MAX_IDR_LEVEL];
605 struct idr_layer **paa = &pa[0]; 605 struct idr_layer **paa = &pa[0];
606 int id = *nextidp; 606 int id = *nextidp;
607 int n, max; 607 int n, max;
@@ -659,7 +659,7 @@ void *idr_replace(struct idr *idp, void *ptr, int id)
659 659
660 n = (p->layer+1) * IDR_BITS; 660 n = (p->layer+1) * IDR_BITS;
661 661
662 id &= MAX_ID_MASK; 662 id &= MAX_IDR_MASK;
663 663
664 if (id >= (1 << n)) 664 if (id >= (1 << n))
665 return ERR_PTR(-EINVAL); 665 return ERR_PTR(-EINVAL);
@@ -780,7 +780,7 @@ EXPORT_SYMBOL(ida_pre_get);
780 */ 780 */
781int ida_get_new_above(struct ida *ida, int starting_id, int *p_id) 781int ida_get_new_above(struct ida *ida, int starting_id, int *p_id)
782{ 782{
783 struct idr_layer *pa[MAX_LEVEL]; 783 struct idr_layer *pa[MAX_IDR_LEVEL];
784 struct ida_bitmap *bitmap; 784 struct ida_bitmap *bitmap;
785 unsigned long flags; 785 unsigned long flags;
786 int idr_id = starting_id / IDA_BITMAP_BITS; 786 int idr_id = starting_id / IDA_BITMAP_BITS;
@@ -793,7 +793,7 @@ int ida_get_new_above(struct ida *ida, int starting_id, int *p_id)
793 if (t < 0) 793 if (t < 0)
794 return _idr_rc_to_errno(t); 794 return _idr_rc_to_errno(t);
795 795
796 if (t * IDA_BITMAP_BITS >= MAX_ID_BIT) 796 if (t * IDA_BITMAP_BITS >= MAX_IDR_BIT)
797 return -ENOSPC; 797 return -ENOSPC;
798 798
799 if (t != idr_id) 799 if (t != idr_id)
@@ -827,7 +827,7 @@ int ida_get_new_above(struct ida *ida, int starting_id, int *p_id)
827 } 827 }
828 828
829 id = idr_id * IDA_BITMAP_BITS + t; 829 id = idr_id * IDA_BITMAP_BITS + t;
830 if (id >= MAX_ID_BIT) 830 if (id >= MAX_IDR_BIT)
831 return -ENOSPC; 831 return -ENOSPC;
832 832
833 __set_bit(t, bitmap->bitmap); 833 __set_bit(t, bitmap->bitmap);
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 0401d2916d9..52e5abbc41d 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -375,14 +375,14 @@ static int uevent_net_init(struct net *net)
375 struct uevent_sock *ue_sk; 375 struct uevent_sock *ue_sk;
376 struct netlink_kernel_cfg cfg = { 376 struct netlink_kernel_cfg cfg = {
377 .groups = 1, 377 .groups = 1,
378 .flags = NL_CFG_F_NONROOT_RECV,
378 }; 379 };
379 380
380 ue_sk = kzalloc(sizeof(*ue_sk), GFP_KERNEL); 381 ue_sk = kzalloc(sizeof(*ue_sk), GFP_KERNEL);
381 if (!ue_sk) 382 if (!ue_sk)
382 return -ENOMEM; 383 return -ENOMEM;
383 384
384 ue_sk->sk = netlink_kernel_create(net, NETLINK_KOBJECT_UEVENT, 385 ue_sk->sk = netlink_kernel_create(net, NETLINK_KOBJECT_UEVENT, &cfg);
385 THIS_MODULE, &cfg);
386 if (!ue_sk->sk) { 386 if (!ue_sk->sk) {
387 printk(KERN_ERR 387 printk(KERN_ERR
388 "kobject_uevent: unable to create netlink socket!\n"); 388 "kobject_uevent: unable to create netlink socket!\n");
@@ -422,7 +422,6 @@ static struct pernet_operations uevent_net_ops = {
422 422
423static int __init kobject_uevent_init(void) 423static int __init kobject_uevent_init(void)
424{ 424{
425 netlink_set_nonroot(NETLINK_KOBJECT_UEVENT, NL_NONROOT_RECV);
426 return register_pernet_subsys(&uevent_net_ops); 425 return register_pernet_subsys(&uevent_net_ops);
427} 426}
428 427
diff --git a/lib/nlattr.c b/lib/nlattr.c
index 4226dfeb517..18eca7809b0 100644
--- a/lib/nlattr.c
+++ b/lib/nlattr.c
@@ -22,6 +22,10 @@ static const u16 nla_attr_minlen[NLA_TYPE_MAX+1] = {
22 [NLA_U64] = sizeof(u64), 22 [NLA_U64] = sizeof(u64),
23 [NLA_MSECS] = sizeof(u64), 23 [NLA_MSECS] = sizeof(u64),
24 [NLA_NESTED] = NLA_HDRLEN, 24 [NLA_NESTED] = NLA_HDRLEN,
25 [NLA_S8] = sizeof(s8),
26 [NLA_S16] = sizeof(s16),
27 [NLA_S32] = sizeof(s32),
28 [NLA_S64] = sizeof(s64),
25}; 29};
26 30
27static int validate_nla(const struct nlattr *nla, int maxtype, 31static int validate_nla(const struct nlattr *nla, int maxtype,
diff --git a/lib/parser.c b/lib/parser.c
index c4341008483..52cfa69f73d 100644
--- a/lib/parser.c
+++ b/lib/parser.c
@@ -122,13 +122,14 @@ int match_token(char *s, const match_table_t table, substring_t args[])
122 * 122 *
123 * Description: Given a &substring_t and a base, attempts to parse the substring 123 * Description: Given a &substring_t and a base, attempts to parse the substring
124 * as a number in that base. On success, sets @result to the integer represented 124 * as a number in that base. On success, sets @result to the integer represented
125 * by the string and returns 0. Returns either -ENOMEM or -EINVAL on failure. 125 * by the string and returns 0. Returns -ENOMEM, -EINVAL, or -ERANGE on failure.
126 */ 126 */
127static int match_number(substring_t *s, int *result, int base) 127static int match_number(substring_t *s, int *result, int base)
128{ 128{
129 char *endp; 129 char *endp;
130 char *buf; 130 char *buf;
131 int ret; 131 int ret;
132 long val;
132 size_t len = s->to - s->from; 133 size_t len = s->to - s->from;
133 134
134 buf = kmalloc(len + 1, GFP_KERNEL); 135 buf = kmalloc(len + 1, GFP_KERNEL);
@@ -136,10 +137,15 @@ static int match_number(substring_t *s, int *result, int base)
136 return -ENOMEM; 137 return -ENOMEM;
137 memcpy(buf, s->from, len); 138 memcpy(buf, s->from, len);
138 buf[len] = '\0'; 139 buf[len] = '\0';
139 *result = simple_strtol(buf, &endp, base); 140
140 ret = 0; 141 ret = 0;
142 val = simple_strtol(buf, &endp, base);
141 if (endp == buf) 143 if (endp == buf)
142 ret = -EINVAL; 144 ret = -EINVAL;
145 else if (val < (long)INT_MIN || val > (long)INT_MAX)
146 ret = -ERANGE;
147 else
148 *result = (int) val;
143 kfree(buf); 149 kfree(buf);
144 return ret; 150 return ret;
145} 151}
diff --git a/lib/plist.c b/lib/plist.c
index 6ab0e521c48..1ebc95f7a46 100644
--- a/lib/plist.c
+++ b/lib/plist.c
@@ -175,7 +175,7 @@ static int __init plist_test(void)
175 int nr_expect = 0, i, loop; 175 int nr_expect = 0, i, loop;
176 unsigned int r = local_clock(); 176 unsigned int r = local_clock();
177 177
178 printk(KERN_INFO "start plist test\n"); 178 pr_debug("start plist test\n");
179 plist_head_init(&test_head); 179 plist_head_init(&test_head);
180 for (i = 0; i < ARRAY_SIZE(test_node); i++) 180 for (i = 0; i < ARRAY_SIZE(test_node); i++)
181 plist_node_init(test_node + i, 0); 181 plist_node_init(test_node + i, 0);
@@ -203,7 +203,7 @@ static int __init plist_test(void)
203 plist_test_check(nr_expect); 203 plist_test_check(nr_expect);
204 } 204 }
205 205
206 printk(KERN_INFO "end plist test\n"); 206 pr_debug("end plist test\n");
207 return 0; 207 return 0;
208} 208}
209 209
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index fadae774a20..e76d85cf317 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -404,14 +404,13 @@ EXPORT_SYMBOL(sg_miter_start);
404 * @miter: sg mapping iter to proceed 404 * @miter: sg mapping iter to proceed
405 * 405 *
406 * Description: 406 * Description:
407 * Proceeds @miter@ to the next mapping. @miter@ should have been 407 * Proceeds @miter to the next mapping. @miter should have been started
408 * started using sg_miter_start(). On successful return, 408 * using sg_miter_start(). On successful return, @miter->page,
409 * @miter@->page, @miter@->addr and @miter@->length point to the 409 * @miter->addr and @miter->length point to the current mapping.
410 * current mapping.
411 * 410 *
412 * Context: 411 * Context:
413 * IRQ disabled if SG_MITER_ATOMIC. IRQ must stay disabled till 412 * Preemption disabled if SG_MITER_ATOMIC. Preemption must stay disabled
414 * @miter@ is stopped. May sleep if !SG_MITER_ATOMIC. 413 * till @miter is stopped. May sleep if !SG_MITER_ATOMIC.
415 * 414 *
416 * Returns: 415 * Returns:
417 * true if @miter contains the next mapping. false if end of sg 416 * true if @miter contains the next mapping. false if end of sg
@@ -465,7 +464,8 @@ EXPORT_SYMBOL(sg_miter_next);
465 * resources (kmap) need to be released during iteration. 464 * resources (kmap) need to be released during iteration.
466 * 465 *
467 * Context: 466 * Context:
468 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise. 467 * Preemption disabled if the SG_MITER_ATOMIC is set. Don't care
468 * otherwise.
469 */ 469 */
470void sg_miter_stop(struct sg_mapping_iter *miter) 470void sg_miter_stop(struct sg_mapping_iter *miter)
471{ 471{
@@ -479,7 +479,7 @@ void sg_miter_stop(struct sg_mapping_iter *miter)
479 flush_kernel_dcache_page(miter->page); 479 flush_kernel_dcache_page(miter->page);
480 480
481 if (miter->__flags & SG_MITER_ATOMIC) { 481 if (miter->__flags & SG_MITER_ATOMIC) {
482 WARN_ON(!irqs_disabled()); 482 WARN_ON_ONCE(preemptible());
483 kunmap_atomic(miter->addr); 483 kunmap_atomic(miter->addr);
484 } else 484 } else
485 kunmap(miter->page); 485 kunmap(miter->page);
diff --git a/lib/spinlock_debug.c b/lib/spinlock_debug.c
index eb10578ae05..0374a596cff 100644
--- a/lib/spinlock_debug.c
+++ b/lib/spinlock_debug.c
@@ -107,23 +107,27 @@ static void __spin_lock_debug(raw_spinlock_t *lock)
107{ 107{
108 u64 i; 108 u64 i;
109 u64 loops = loops_per_jiffy * HZ; 109 u64 loops = loops_per_jiffy * HZ;
110 int print_once = 1;
111 110
112 for (;;) { 111 for (i = 0; i < loops; i++) {
113 for (i = 0; i < loops; i++) { 112 if (arch_spin_trylock(&lock->raw_lock))
114 if (arch_spin_trylock(&lock->raw_lock)) 113 return;
115 return; 114 __delay(1);
116 __delay(1); 115 }
117 } 116 /* lockup suspected: */
118 /* lockup suspected: */ 117 spin_dump(lock, "lockup suspected");
119 if (print_once) {
120 print_once = 0;
121 spin_dump(lock, "lockup suspected");
122#ifdef CONFIG_SMP 118#ifdef CONFIG_SMP
123 trigger_all_cpu_backtrace(); 119 trigger_all_cpu_backtrace();
124#endif 120#endif
125 } 121
126 } 122 /*
123 * The trylock above was causing a livelock. Give the lower level arch
124 * specific lock code a chance to acquire the lock. We have already
125 * printed a warning/backtrace at this point. The non-debug arch
126 * specific code might actually succeed in acquiring the lock. If it is
127 * not successful, the end-result is the same - there is no forward
128 * progress.
129 */
130 arch_spin_lock(&lock->raw_lock);
127} 131}
128 132
129void do_raw_spin_lock(raw_spinlock_t *lock) 133void do_raw_spin_lock(raw_spinlock_t *lock)
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 45bc1f83a5a..f114bf6a8e1 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -170,7 +170,7 @@ void __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
170 * Statically reserve bounce buffer space and initialize bounce buffer data 170 * Statically reserve bounce buffer space and initialize bounce buffer data
171 * structures for the software IO TLB used to implement the DMA API. 171 * structures for the software IO TLB used to implement the DMA API.
172 */ 172 */
173void __init 173static void __init
174swiotlb_init_with_default_size(size_t default_size, int verbose) 174swiotlb_init_with_default_size(size_t default_size, int verbose)
175{ 175{
176 unsigned long bytes; 176 unsigned long bytes;
@@ -206,8 +206,9 @@ swiotlb_init(int verbose)
206int 206int
207swiotlb_late_init_with_default_size(size_t default_size) 207swiotlb_late_init_with_default_size(size_t default_size)
208{ 208{
209 unsigned long i, bytes, req_nslabs = io_tlb_nslabs; 209 unsigned long bytes, req_nslabs = io_tlb_nslabs;
210 unsigned int order; 210 unsigned int order;
211 int rc = 0;
211 212
212 if (!io_tlb_nslabs) { 213 if (!io_tlb_nslabs) {
213 io_tlb_nslabs = (default_size >> IO_TLB_SHIFT); 214 io_tlb_nslabs = (default_size >> IO_TLB_SHIFT);
@@ -229,16 +230,32 @@ swiotlb_late_init_with_default_size(size_t default_size)
229 order--; 230 order--;
230 } 231 }
231 232
232 if (!io_tlb_start) 233 if (!io_tlb_start) {
233 goto cleanup1; 234 io_tlb_nslabs = req_nslabs;
234 235 return -ENOMEM;
236 }
235 if (order != get_order(bytes)) { 237 if (order != get_order(bytes)) {
236 printk(KERN_WARNING "Warning: only able to allocate %ld MB " 238 printk(KERN_WARNING "Warning: only able to allocate %ld MB "
237 "for software IO TLB\n", (PAGE_SIZE << order) >> 20); 239 "for software IO TLB\n", (PAGE_SIZE << order) >> 20);
238 io_tlb_nslabs = SLABS_PER_PAGE << order; 240 io_tlb_nslabs = SLABS_PER_PAGE << order;
239 bytes = io_tlb_nslabs << IO_TLB_SHIFT;
240 } 241 }
242 rc = swiotlb_late_init_with_tbl(io_tlb_start, io_tlb_nslabs);
243 if (rc)
244 free_pages((unsigned long)io_tlb_start, order);
245 return rc;
246}
247
248int
249swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
250{
251 unsigned long i, bytes;
252
253 bytes = nslabs << IO_TLB_SHIFT;
254
255 io_tlb_nslabs = nslabs;
256 io_tlb_start = tlb;
241 io_tlb_end = io_tlb_start + bytes; 257 io_tlb_end = io_tlb_start + bytes;
258
242 memset(io_tlb_start, 0, bytes); 259 memset(io_tlb_start, 0, bytes);
243 260
244 /* 261 /*
@@ -288,10 +305,8 @@ cleanup3:
288 io_tlb_list = NULL; 305 io_tlb_list = NULL;
289cleanup2: 306cleanup2:
290 io_tlb_end = NULL; 307 io_tlb_end = NULL;
291 free_pages((unsigned long)io_tlb_start, order);
292 io_tlb_start = NULL; 308 io_tlb_start = NULL;
293cleanup1: 309 io_tlb_nslabs = 0;
294 io_tlb_nslabs = req_nslabs;
295 return -ENOMEM; 310 return -ENOMEM;
296} 311}
297 312
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 0e337541f00..39c99fea7c0 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -174,35 +174,25 @@ char *put_dec_trunc8(char *buf, unsigned r)
174 unsigned q; 174 unsigned q;
175 175
176 /* Copy of previous function's body with added early returns */ 176 /* Copy of previous function's body with added early returns */
177 q = (r * (uint64_t)0x1999999a) >> 32; 177 while (r >= 10000) {
178 *buf++ = (r - 10 * q) + '0'; /* 2 */ 178 q = r + '0';
179 if (q == 0) 179 r = (r * (uint64_t)0x1999999a) >> 32;
180 return buf; 180 *buf++ = q - 10*r;
181 r = (q * (uint64_t)0x1999999a) >> 32; 181 }
182 *buf++ = (q - 10 * r) + '0'; /* 3 */ 182
183 if (r == 0) 183 q = (r * 0x199a) >> 16; /* r <= 9999 */
184 return buf; 184 *buf++ = (r - 10 * q) + '0';
185 q = (r * (uint64_t)0x1999999a) >> 32;
186 *buf++ = (r - 10 * q) + '0'; /* 4 */
187 if (q == 0)
188 return buf;
189 r = (q * (uint64_t)0x1999999a) >> 32;
190 *buf++ = (q - 10 * r) + '0'; /* 5 */
191 if (r == 0)
192 return buf;
193 q = (r * 0x199a) >> 16;
194 *buf++ = (r - 10 * q) + '0'; /* 6 */
195 if (q == 0) 185 if (q == 0)
196 return buf; 186 return buf;
197 r = (q * 0xcd) >> 11; 187 r = (q * 0xcd) >> 11; /* q <= 999 */
198 *buf++ = (q - 10 * r) + '0'; /* 7 */ 188 *buf++ = (q - 10 * r) + '0';
199 if (r == 0) 189 if (r == 0)
200 return buf; 190 return buf;
201 q = (r * 0xcd) >> 11; 191 q = (r * 0xcd) >> 11; /* r <= 99 */
202 *buf++ = (r - 10 * q) + '0'; /* 8 */ 192 *buf++ = (r - 10 * q) + '0';
203 if (q == 0) 193 if (q == 0)
204 return buf; 194 return buf;
205 *buf++ = q + '0'; /* 9 */ 195 *buf++ = q + '0'; /* q <= 9 */
206 return buf; 196 return buf;
207} 197}
208 198
@@ -243,18 +233,34 @@ char *put_dec(char *buf, unsigned long long n)
243 233
244/* Second algorithm: valid only for 64-bit long longs */ 234/* Second algorithm: valid only for 64-bit long longs */
245 235
236/* See comment in put_dec_full9 for choice of constants */
246static noinline_for_stack 237static noinline_for_stack
247char *put_dec_full4(char *buf, unsigned q) 238void put_dec_full4(char *buf, unsigned q)
248{ 239{
249 unsigned r; 240 unsigned r;
250 r = (q * 0xcccd) >> 19; 241 r = (q * 0xccd) >> 15;
251 *buf++ = (q - 10 * r) + '0'; 242 buf[0] = (q - 10 * r) + '0';
252 q = (r * 0x199a) >> 16; 243 q = (r * 0xcd) >> 11;
253 *buf++ = (r - 10 * q) + '0'; 244 buf[1] = (r - 10 * q) + '0';
254 r = (q * 0xcd) >> 11; 245 r = (q * 0xcd) >> 11;
255 *buf++ = (q - 10 * r) + '0'; 246 buf[2] = (q - 10 * r) + '0';
256 *buf++ = r + '0'; 247 buf[3] = r + '0';
257 return buf; 248}
249
250/*
251 * Call put_dec_full4 on x % 10000, return x / 10000.
252 * The approximation x/10000 == (x * 0x346DC5D7) >> 43
253 * holds for all x < 1,128,869,999. The largest value this
254 * helper will ever be asked to convert is 1,125,520,955.
255 * (d1 in the put_dec code, assuming n is all-ones).
256 */
257static
258unsigned put_dec_helper4(char *buf, unsigned x)
259{
260 uint32_t q = (x * (uint64_t)0x346DC5D7) >> 43;
261
262 put_dec_full4(buf, x - q * 10000);
263 return q;
258} 264}
259 265
260/* Based on code by Douglas W. Jones found at 266/* Based on code by Douglas W. Jones found at
@@ -276,28 +282,19 @@ char *put_dec(char *buf, unsigned long long n)
276 d3 = (h >> 16); /* implicit "& 0xffff" */ 282 d3 = (h >> 16); /* implicit "& 0xffff" */
277 283
278 q = 656 * d3 + 7296 * d2 + 5536 * d1 + ((uint32_t)n & 0xffff); 284 q = 656 * d3 + 7296 * d2 + 5536 * d1 + ((uint32_t)n & 0xffff);
285 q = put_dec_helper4(buf, q);
286
287 q += 7671 * d3 + 9496 * d2 + 6 * d1;
288 q = put_dec_helper4(buf+4, q);
289
290 q += 4749 * d3 + 42 * d2;
291 q = put_dec_helper4(buf+8, q);
279 292
280 buf = put_dec_full4(buf, q % 10000); 293 q += 281 * d3;
281 q = q / 10000; 294 buf += 12;
282 295 if (q)
283 d1 = q + 7671 * d3 + 9496 * d2 + 6 * d1; 296 buf = put_dec_trunc8(buf, q);
284 buf = put_dec_full4(buf, d1 % 10000); 297 else while (buf[-1] == '0')
285 q = d1 / 10000;
286
287 d2 = q + 4749 * d3 + 42 * d2;
288 buf = put_dec_full4(buf, d2 % 10000);
289 q = d2 / 10000;
290
291 d3 = q + 281 * d3;
292 if (!d3)
293 goto done;
294 buf = put_dec_full4(buf, d3 % 10000);
295 q = d3 / 10000;
296 if (!q)
297 goto done;
298 buf = put_dec_full4(buf, q);
299 done:
300 while (buf[-1] == '0')
301 --buf; 298 --buf;
302 299
303 return buf; 300 return buf;
@@ -990,7 +987,7 @@ int kptr_restrict __read_mostly;
990 * - 'm' For a 6-byte MAC address, it prints the hex address without colons 987 * - 'm' For a 6-byte MAC address, it prints the hex address without colons
991 * - 'MF' For a 6-byte MAC FDDI address, it prints the address 988 * - 'MF' For a 6-byte MAC FDDI address, it prints the address
992 * with a dash-separated hex notation 989 * with a dash-separated hex notation
993 * - '[mM]R For a 6-byte MAC address, Reverse order (Bluetooth) 990 * - '[mM]R' For a 6-byte MAC address, Reverse order (Bluetooth)
994 * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way 991 * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
995 * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4) 992 * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
996 * IPv6 uses colon separated network-order 16 bit hex with leading 0's 993 * IPv6 uses colon separated network-order 16 bit hex with leading 0's
@@ -1341,7 +1338,10 @@ qualifier:
1341 * %pR output the address range in a struct resource with decoded flags 1338 * %pR output the address range in a struct resource with decoded flags
1342 * %pr output the address range in a struct resource with raw flags 1339 * %pr output the address range in a struct resource with raw flags
1343 * %pM output a 6-byte MAC address with colons 1340 * %pM output a 6-byte MAC address with colons
1341 * %pMR output a 6-byte MAC address with colons in reversed order
1342 * %pMF output a 6-byte MAC address with dashes
1344 * %pm output a 6-byte MAC address without colons 1343 * %pm output a 6-byte MAC address without colons
1344 * %pmR output a 6-byte MAC address without colons in reversed order
1345 * %pI4 print an IPv4 address without leading zeros 1345 * %pI4 print an IPv4 address without leading zeros
1346 * %pi4 print an IPv4 address with leading zeros 1346 * %pi4 print an IPv4 address with leading zeros
1347 * %pI6 print an IPv6 address with colons 1347 * %pI6 print an IPv6 address with colons
@@ -2017,7 +2017,7 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
2017 s16 field_width; 2017 s16 field_width;
2018 bool is_sign; 2018 bool is_sign;
2019 2019
2020 while (*fmt && *str) { 2020 while (*fmt) {
2021 /* skip any white space in format */ 2021 /* skip any white space in format */
2022 /* white space in format matchs any amount of 2022 /* white space in format matchs any amount of
2023 * white space, including none, in the input. 2023 * white space, including none, in the input.
@@ -2042,6 +2042,8 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
2042 * advance both strings to next white space 2042 * advance both strings to next white space
2043 */ 2043 */
2044 if (*fmt == '*') { 2044 if (*fmt == '*') {
2045 if (!*str)
2046 break;
2045 while (!isspace(*fmt) && *fmt != '%' && *fmt) 2047 while (!isspace(*fmt) && *fmt != '%' && *fmt)
2046 fmt++; 2048 fmt++;
2047 while (!isspace(*str) && *str) 2049 while (!isspace(*str) && *str)
@@ -2070,7 +2072,17 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
2070 } 2072 }
2071 } 2073 }
2072 2074
2073 if (!*fmt || !*str) 2075 if (!*fmt)
2076 break;
2077
2078 if (*fmt == 'n') {
2079 /* return number of characters read so far */
2080 *va_arg(args, int *) = str - buf;
2081 ++fmt;
2082 continue;
2083 }
2084
2085 if (!*str)
2074 break; 2086 break;
2075 2087
2076 base = 10; 2088 base = 10;
@@ -2103,13 +2115,6 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
2103 num++; 2115 num++;
2104 } 2116 }
2105 continue; 2117 continue;
2106 case 'n':
2107 /* return number of characters read so far */
2108 {
2109 int *i = (int *)va_arg(args, int*);
2110 *i = str - buf;
2111 }
2112 continue;
2113 case 'o': 2118 case 'o':
2114 base = 8; 2119 base = 8;
2115 break; 2120 break;
@@ -2210,16 +2215,6 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
2210 str = next; 2215 str = next;
2211 } 2216 }
2212 2217
2213 /*
2214 * Now we've come all the way through so either the input string or the
2215 * format ended. In the former case, there can be a %n at the current
2216 * position in the format that needs to be filled.
2217 */
2218 if (*fmt == '%' && *(fmt + 1) == 'n') {
2219 int *p = (int *)va_arg(args, int *);
2220 *p = str - buf;
2221 }
2222
2223 return num; 2218 return num;
2224} 2219}
2225EXPORT_SYMBOL(vsscanf); 2220EXPORT_SYMBOL(vsscanf);