diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig.debug | 74 | ||||
-rw-r--r-- | lib/Makefile | 3 | ||||
-rw-r--r-- | lib/bitmap.c | 109 | ||||
-rw-r--r-- | lib/bsearch.c | 53 | ||||
-rw-r--r-- | lib/dma-debug.c | 18 | ||||
-rw-r--r-- | lib/flex_array.c | 48 | ||||
-rw-r--r-- | lib/genalloc.c | 45 | ||||
-rw-r--r-- | lib/kstrtox.c | 26 | ||||
-rw-r--r-- | lib/lru_cache.c | 2 | ||||
-rw-r--r-- | lib/show_mem.c | 2 | ||||
-rw-r--r-- | lib/string.c | 29 | ||||
-rw-r--r-- | lib/vsprintf.c | 13 | ||||
-rw-r--r-- | lib/xz/xz_dec_lzma2.c | 6 |
13 files changed, 346 insertions, 82 deletions
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index c768bcdda1b7..28afa4c5333c 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
@@ -7,7 +7,8 @@ config PRINTK_TIME | |||
7 | included in printk output. This allows you to measure | 7 | included in printk output. This allows you to measure |
8 | the interval between kernel operations, including bootup | 8 | the interval between kernel operations, including bootup |
9 | operations. This is useful for identifying long delays | 9 | operations. This is useful for identifying long delays |
10 | in kernel startup. | 10 | in kernel startup. Or add printk.time=1 at boot-time. |
11 | See Documentation/kernel-parameters.txt | ||
11 | 12 | ||
12 | config DEFAULT_MESSAGE_LOGLEVEL | 13 | config DEFAULT_MESSAGE_LOGLEVEL |
13 | int "Default message log level (1-7)" | 14 | int "Default message log level (1-7)" |
@@ -238,6 +239,21 @@ config DETECT_HUNG_TASK | |||
238 | enabled then all held locks will also be reported. This | 239 | enabled then all held locks will also be reported. This |
239 | feature has negligible overhead. | 240 | feature has negligible overhead. |
240 | 241 | ||
242 | config DEFAULT_HUNG_TASK_TIMEOUT | ||
243 | int "Default timeout for hung task detection (in seconds)" | ||
244 | depends on DETECT_HUNG_TASK | ||
245 | default 120 | ||
246 | help | ||
247 | This option controls the default timeout (in seconds) used | ||
248 | to determine when a task has become non-responsive and should | ||
249 | be considered hung. | ||
250 | |||
251 | It can be adjusted at runtime via the kernel.hung_task_timeout | ||
252 | sysctl or by writing a value to /proc/sys/kernel/hung_task_timeout. | ||
253 | |||
254 | A timeout of 0 disables the check. The default is two minutes. | ||
255 | Keeping the default should be fine in most cases. | ||
256 | |||
241 | config BOOTPARAM_HUNG_TASK_PANIC | 257 | config BOOTPARAM_HUNG_TASK_PANIC |
242 | bool "Panic (Reboot) On Hung Tasks" | 258 | bool "Panic (Reboot) On Hung Tasks" |
243 | depends on DETECT_HUNG_TASK | 259 | depends on DETECT_HUNG_TASK |
@@ -337,7 +353,7 @@ config DEBUG_OBJECTS_WORK | |||
337 | 353 | ||
338 | config DEBUG_OBJECTS_RCU_HEAD | 354 | config DEBUG_OBJECTS_RCU_HEAD |
339 | bool "Debug RCU callbacks objects" | 355 | bool "Debug RCU callbacks objects" |
340 | depends on DEBUG_OBJECTS && PREEMPT | 356 | depends on DEBUG_OBJECTS |
341 | help | 357 | help |
342 | Enable this to turn on debugging of RCU list heads (call_rcu() usage). | 358 | Enable this to turn on debugging of RCU list heads (call_rcu() usage). |
343 | 359 | ||
@@ -398,9 +414,9 @@ config SLUB_STATS | |||
398 | config DEBUG_KMEMLEAK | 414 | config DEBUG_KMEMLEAK |
399 | bool "Kernel memory leak detector" | 415 | bool "Kernel memory leak detector" |
400 | depends on DEBUG_KERNEL && EXPERIMENTAL && !MEMORY_HOTPLUG && \ | 416 | depends on DEBUG_KERNEL && EXPERIMENTAL && !MEMORY_HOTPLUG && \ |
401 | (X86 || ARM || PPC || S390 || SPARC64 || SUPERH || MICROBLAZE || TILE) | 417 | (X86 || ARM || PPC || MIPS || S390 || SPARC64 || SUPERH || MICROBLAZE || TILE) |
402 | 418 | ||
403 | select DEBUG_FS if SYSFS | 419 | select DEBUG_FS |
404 | select STACKTRACE if STACKTRACE_SUPPORT | 420 | select STACKTRACE if STACKTRACE_SUPPORT |
405 | select KALLSYMS | 421 | select KALLSYMS |
406 | select CRC32 | 422 | select CRC32 |
@@ -654,6 +670,15 @@ config STACKTRACE | |||
654 | bool | 670 | bool |
655 | depends on STACKTRACE_SUPPORT | 671 | depends on STACKTRACE_SUPPORT |
656 | 672 | ||
673 | config DEBUG_STACK_USAGE | ||
674 | bool "Stack utilization instrumentation" | ||
675 | depends on DEBUG_KERNEL | ||
676 | help | ||
677 | Enables the display of the minimum amount of free stack which each | ||
678 | task has ever had available in the sysrq-T and sysrq-P debug output. | ||
679 | |||
680 | This option will slow down process creation somewhat. | ||
681 | |||
657 | config DEBUG_KOBJECT | 682 | config DEBUG_KOBJECT |
658 | bool "kobject debugging" | 683 | bool "kobject debugging" |
659 | depends on DEBUG_KERNEL | 684 | depends on DEBUG_KERNEL |
@@ -875,22 +900,9 @@ config RCU_TORTURE_TEST_RUNNABLE | |||
875 | Say N here if you want the RCU torture tests to start only | 900 | Say N here if you want the RCU torture tests to start only |
876 | after being manually enabled via /proc. | 901 | after being manually enabled via /proc. |
877 | 902 | ||
878 | config RCU_CPU_STALL_DETECTOR | ||
879 | bool "Check for stalled CPUs delaying RCU grace periods" | ||
880 | depends on TREE_RCU || TREE_PREEMPT_RCU | ||
881 | default y | ||
882 | help | ||
883 | This option causes RCU to printk information on which | ||
884 | CPUs are delaying the current grace period, but only when | ||
885 | the grace period extends for excessive time periods. | ||
886 | |||
887 | Say N if you want to disable such checks. | ||
888 | |||
889 | Say Y if you are unsure. | ||
890 | |||
891 | config RCU_CPU_STALL_TIMEOUT | 903 | config RCU_CPU_STALL_TIMEOUT |
892 | int "RCU CPU stall timeout in seconds" | 904 | int "RCU CPU stall timeout in seconds" |
893 | depends on RCU_CPU_STALL_DETECTOR | 905 | depends on TREE_RCU || TREE_PREEMPT_RCU |
894 | range 3 300 | 906 | range 3 300 |
895 | default 60 | 907 | default 60 |
896 | help | 908 | help |
@@ -899,22 +911,9 @@ config RCU_CPU_STALL_TIMEOUT | |||
899 | RCU grace period persists, additional CPU stall warnings are | 911 | RCU grace period persists, additional CPU stall warnings are |
900 | printed at more widely spaced intervals. | 912 | printed at more widely spaced intervals. |
901 | 913 | ||
902 | config RCU_CPU_STALL_DETECTOR_RUNNABLE | ||
903 | bool "RCU CPU stall checking starts automatically at boot" | ||
904 | depends on RCU_CPU_STALL_DETECTOR | ||
905 | default y | ||
906 | help | ||
907 | If set, start checking for RCU CPU stalls immediately on | ||
908 | boot. Otherwise, RCU CPU stall checking must be manually | ||
909 | enabled. | ||
910 | |||
911 | Say Y if you are unsure. | ||
912 | |||
913 | Say N if you wish to suppress RCU CPU stall checking during boot. | ||
914 | |||
915 | config RCU_CPU_STALL_VERBOSE | 914 | config RCU_CPU_STALL_VERBOSE |
916 | bool "Print additional per-task information for RCU_CPU_STALL_DETECTOR" | 915 | bool "Print additional per-task information for RCU_CPU_STALL_DETECTOR" |
917 | depends on RCU_CPU_STALL_DETECTOR && TREE_PREEMPT_RCU | 916 | depends on TREE_PREEMPT_RCU |
918 | default y | 917 | default y |
919 | help | 918 | help |
920 | This option causes RCU to printk detailed per-task information | 919 | This option causes RCU to printk detailed per-task information |
@@ -993,6 +992,17 @@ config DEBUG_FORCE_WEAK_PER_CPU | |||
993 | To ensure that generic code follows the above rules, this | 992 | To ensure that generic code follows the above rules, this |
994 | option forces all percpu variables to be defined as weak. | 993 | option forces all percpu variables to be defined as weak. |
995 | 994 | ||
995 | config DEBUG_PER_CPU_MAPS | ||
996 | bool "Debug access to per_cpu maps" | ||
997 | depends on DEBUG_KERNEL | ||
998 | depends on SMP | ||
999 | help | ||
1000 | Say Y to verify that the per_cpu map being accessed has | ||
1001 | been set up. This adds a fair amount of code to kernel memory | ||
1002 | and decreases performance. | ||
1003 | |||
1004 | Say N if unsure. | ||
1005 | |||
996 | config LKDTM | 1006 | config LKDTM |
997 | tristate "Linux Kernel Dump Test Tool Module" | 1007 | tristate "Linux Kernel Dump Test Tool Module" |
998 | depends on DEBUG_FS | 1008 | depends on DEBUG_FS |
diff --git a/lib/Makefile b/lib/Makefile index ef0f28571156..4b49a249064b 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -21,7 +21,8 @@ lib-y += kobject.o kref.o klist.o | |||
21 | 21 | ||
22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | 22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ | 23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ |
24 | string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o | 24 | string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o \ |
25 | bsearch.o | ||
25 | obj-y += kstrtox.o | 26 | obj-y += kstrtox.o |
26 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o | 27 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o |
27 | 28 | ||
diff --git a/lib/bitmap.c b/lib/bitmap.c index 91e0ccfdb424..41baf02924e6 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c | |||
@@ -571,8 +571,11 @@ int bitmap_scnlistprintf(char *buf, unsigned int buflen, | |||
571 | EXPORT_SYMBOL(bitmap_scnlistprintf); | 571 | EXPORT_SYMBOL(bitmap_scnlistprintf); |
572 | 572 | ||
573 | /** | 573 | /** |
574 | * bitmap_parselist - convert list format ASCII string to bitmap | 574 | * __bitmap_parselist - convert list format ASCII string to bitmap |
575 | * @bp: read nul-terminated user string from this buffer | 575 | * @bp: read nul-terminated user string from this buffer |
576 | * @buflen: buffer size in bytes. If string is smaller than this | ||
577 | * then it must be terminated with a \0. | ||
578 | * @is_user: location of buffer, 0 indicates kernel space | ||
576 | * @maskp: write resulting mask here | 579 | * @maskp: write resulting mask here |
577 | * @nmaskbits: number of bits in mask to be written | 580 | * @nmaskbits: number of bits in mask to be written |
578 | * | 581 | * |
@@ -587,20 +590,63 @@ EXPORT_SYMBOL(bitmap_scnlistprintf); | |||
587 | * %-EINVAL: invalid character in string | 590 | * %-EINVAL: invalid character in string |
588 | * %-ERANGE: bit number specified too large for mask | 591 | * %-ERANGE: bit number specified too large for mask |
589 | */ | 592 | */ |
590 | int bitmap_parselist(const char *bp, unsigned long *maskp, int nmaskbits) | 593 | static int __bitmap_parselist(const char *buf, unsigned int buflen, |
594 | int is_user, unsigned long *maskp, | ||
595 | int nmaskbits) | ||
591 | { | 596 | { |
592 | unsigned a, b; | 597 | unsigned a, b; |
598 | int c, old_c, totaldigits; | ||
599 | const char __user *ubuf = buf; | ||
600 | int exp_digit, in_range; | ||
593 | 601 | ||
602 | totaldigits = c = 0; | ||
594 | bitmap_zero(maskp, nmaskbits); | 603 | bitmap_zero(maskp, nmaskbits); |
595 | do { | 604 | do { |
596 | if (!isdigit(*bp)) | 605 | exp_digit = 1; |
597 | return -EINVAL; | 606 | in_range = 0; |
598 | b = a = simple_strtoul(bp, (char **)&bp, BASEDEC); | 607 | a = b = 0; |
599 | if (*bp == '-') { | 608 | |
600 | bp++; | 609 | /* Get the next cpu# or a range of cpu#'s */ |
601 | if (!isdigit(*bp)) | 610 | while (buflen) { |
611 | old_c = c; | ||
612 | if (is_user) { | ||
613 | if (__get_user(c, ubuf++)) | ||
614 | return -EFAULT; | ||
615 | } else | ||
616 | c = *buf++; | ||
617 | buflen--; | ||
618 | if (isspace(c)) | ||
619 | continue; | ||
620 | |||
621 | /* | ||
622 | * If the last character was a space and the current | ||
623 | * character isn't '\0', we've got embedded whitespace. | ||
624 | * This is a no-no, so throw an error. | ||
625 | */ | ||
626 | if (totaldigits && c && isspace(old_c)) | ||
627 | return -EINVAL; | ||
628 | |||
629 | /* A '\0' or a ',' signal the end of a cpu# or range */ | ||
630 | if (c == '\0' || c == ',') | ||
631 | break; | ||
632 | |||
633 | if (c == '-') { | ||
634 | if (exp_digit || in_range) | ||
635 | return -EINVAL; | ||
636 | b = 0; | ||
637 | in_range = 1; | ||
638 | exp_digit = 1; | ||
639 | continue; | ||
640 | } | ||
641 | |||
642 | if (!isdigit(c)) | ||
602 | return -EINVAL; | 643 | return -EINVAL; |
603 | b = simple_strtoul(bp, (char **)&bp, BASEDEC); | 644 | |
645 | b = b * 10 + (c - '0'); | ||
646 | if (!in_range) | ||
647 | a = b; | ||
648 | exp_digit = 0; | ||
649 | totaldigits++; | ||
604 | } | 650 | } |
605 | if (!(a <= b)) | 651 | if (!(a <= b)) |
606 | return -EINVAL; | 652 | return -EINVAL; |
@@ -610,13 +656,52 @@ int bitmap_parselist(const char *bp, unsigned long *maskp, int nmaskbits) | |||
610 | set_bit(a, maskp); | 656 | set_bit(a, maskp); |
611 | a++; | 657 | a++; |
612 | } | 658 | } |
613 | if (*bp == ',') | 659 | } while (buflen && c == ','); |
614 | bp++; | ||
615 | } while (*bp != '\0' && *bp != '\n'); | ||
616 | return 0; | 660 | return 0; |
617 | } | 661 | } |
662 | |||
663 | int bitmap_parselist(const char *bp, unsigned long *maskp, int nmaskbits) | ||
664 | { | ||
665 | char *nl = strchr(bp, '\n'); | ||
666 | int len; | ||
667 | |||
668 | if (nl) | ||
669 | len = nl - bp; | ||
670 | else | ||
671 | len = strlen(bp); | ||
672 | |||
673 | return __bitmap_parselist(bp, len, 0, maskp, nmaskbits); | ||
674 | } | ||
618 | EXPORT_SYMBOL(bitmap_parselist); | 675 | EXPORT_SYMBOL(bitmap_parselist); |
619 | 676 | ||
677 | |||
678 | /** | ||
679 | * bitmap_parselist_user() | ||
680 | * | ||
681 | * @ubuf: pointer to user buffer containing string. | ||
682 | * @ulen: buffer size in bytes. If string is smaller than this | ||
683 | * then it must be terminated with a \0. | ||
684 | * @maskp: pointer to bitmap array that will contain result. | ||
685 | * @nmaskbits: size of bitmap, in bits. | ||
686 | * | ||
687 | * Wrapper for bitmap_parselist(), providing it with user buffer. | ||
688 | * | ||
689 | * We cannot have this as an inline function in bitmap.h because it needs | ||
690 | * linux/uaccess.h to get the access_ok() declaration and this causes | ||
691 | * cyclic dependencies. | ||
692 | */ | ||
693 | int bitmap_parselist_user(const char __user *ubuf, | ||
694 | unsigned int ulen, unsigned long *maskp, | ||
695 | int nmaskbits) | ||
696 | { | ||
697 | if (!access_ok(VERIFY_READ, ubuf, ulen)) | ||
698 | return -EFAULT; | ||
699 | return __bitmap_parselist((const char *)ubuf, | ||
700 | ulen, 1, maskp, nmaskbits); | ||
701 | } | ||
702 | EXPORT_SYMBOL(bitmap_parselist_user); | ||
703 | |||
704 | |||
620 | /** | 705 | /** |
621 | * bitmap_pos_to_ord - find ordinal of set bit at given position in bitmap | 706 | * bitmap_pos_to_ord - find ordinal of set bit at given position in bitmap |
622 | * @buf: pointer to a bitmap | 707 | * @buf: pointer to a bitmap |
diff --git a/lib/bsearch.c b/lib/bsearch.c new file mode 100644 index 000000000000..5b54758e2afb --- /dev/null +++ b/lib/bsearch.c | |||
@@ -0,0 +1,53 @@ | |||
1 | /* | ||
2 | * A generic implementation of binary search for the Linux kernel | ||
3 | * | ||
4 | * Copyright (C) 2008-2009 Ksplice, Inc. | ||
5 | * Author: Tim Abbott <tabbott@ksplice.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License as | ||
9 | * published by the Free Software Foundation; version 2. | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/bsearch.h> | ||
14 | |||
15 | /* | ||
16 | * bsearch - binary search an array of elements | ||
17 | * @key: pointer to item being searched for | ||
18 | * @base: pointer to first element to search | ||
19 | * @num: number of elements | ||
20 | * @size: size of each element | ||
21 | * @cmp: pointer to comparison function | ||
22 | * | ||
23 | * This function does a binary search on the given array. The | ||
24 | * contents of the array should already be in ascending sorted order | ||
25 | * under the provided comparison function. | ||
26 | * | ||
27 | * Note that the key need not have the same type as the elements in | ||
28 | * the array, e.g. key could be a string and the comparison function | ||
29 | * could compare the string with the struct's name field. However, if | ||
30 | * the key and elements in the array are of the same type, you can use | ||
31 | * the same comparison function for both sort() and bsearch(). | ||
32 | */ | ||
33 | void *bsearch(const void *key, const void *base, size_t num, size_t size, | ||
34 | int (*cmp)(const void *key, const void *elt)) | ||
35 | { | ||
36 | size_t start = 0, end = num; | ||
37 | int result; | ||
38 | |||
39 | while (start < end) { | ||
40 | size_t mid = start + (end - start) / 2; | ||
41 | |||
42 | result = cmp(key, base + mid * size); | ||
43 | if (result < 0) | ||
44 | end = mid; | ||
45 | else if (result > 0) | ||
46 | start = mid + 1; | ||
47 | else | ||
48 | return (void *)base + mid * size; | ||
49 | } | ||
50 | |||
51 | return NULL; | ||
52 | } | ||
53 | EXPORT_SYMBOL(bsearch); | ||
diff --git a/lib/dma-debug.c b/lib/dma-debug.c index 4bfb0471f106..db07bfd9298e 100644 --- a/lib/dma-debug.c +++ b/lib/dma-debug.c | |||
@@ -649,7 +649,7 @@ out_err: | |||
649 | return -ENOMEM; | 649 | return -ENOMEM; |
650 | } | 650 | } |
651 | 651 | ||
652 | static int device_dma_allocations(struct device *dev) | 652 | static int device_dma_allocations(struct device *dev, struct dma_debug_entry **out_entry) |
653 | { | 653 | { |
654 | struct dma_debug_entry *entry; | 654 | struct dma_debug_entry *entry; |
655 | unsigned long flags; | 655 | unsigned long flags; |
@@ -660,8 +660,10 @@ static int device_dma_allocations(struct device *dev) | |||
660 | for (i = 0; i < HASH_SIZE; ++i) { | 660 | for (i = 0; i < HASH_SIZE; ++i) { |
661 | spin_lock(&dma_entry_hash[i].lock); | 661 | spin_lock(&dma_entry_hash[i].lock); |
662 | list_for_each_entry(entry, &dma_entry_hash[i].list, list) { | 662 | list_for_each_entry(entry, &dma_entry_hash[i].list, list) { |
663 | if (entry->dev == dev) | 663 | if (entry->dev == dev) { |
664 | count += 1; | 664 | count += 1; |
665 | *out_entry = entry; | ||
666 | } | ||
665 | } | 667 | } |
666 | spin_unlock(&dma_entry_hash[i].lock); | 668 | spin_unlock(&dma_entry_hash[i].lock); |
667 | } | 669 | } |
@@ -674,6 +676,7 @@ static int device_dma_allocations(struct device *dev) | |||
674 | static int dma_debug_device_change(struct notifier_block *nb, unsigned long action, void *data) | 676 | static int dma_debug_device_change(struct notifier_block *nb, unsigned long action, void *data) |
675 | { | 677 | { |
676 | struct device *dev = data; | 678 | struct device *dev = data; |
679 | struct dma_debug_entry *uninitialized_var(entry); | ||
677 | int count; | 680 | int count; |
678 | 681 | ||
679 | if (global_disable) | 682 | if (global_disable) |
@@ -681,12 +684,17 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti | |||
681 | 684 | ||
682 | switch (action) { | 685 | switch (action) { |
683 | case BUS_NOTIFY_UNBOUND_DRIVER: | 686 | case BUS_NOTIFY_UNBOUND_DRIVER: |
684 | count = device_dma_allocations(dev); | 687 | count = device_dma_allocations(dev, &entry); |
685 | if (count == 0) | 688 | if (count == 0) |
686 | break; | 689 | break; |
687 | err_printk(dev, NULL, "DMA-API: device driver has pending " | 690 | err_printk(dev, entry, "DMA-API: device driver has pending " |
688 | "DMA allocations while released from device " | 691 | "DMA allocations while released from device " |
689 | "[count=%d]\n", count); | 692 | "[count=%d]\n" |
693 | "One of leaked entries details: " | ||
694 | "[device address=0x%016llx] [size=%llu bytes] " | ||
695 | "[mapped with %s] [mapped as %s]\n", | ||
696 | count, entry->dev_addr, entry->size, | ||
697 | dir2name[entry->direction], type2name[entry->type]); | ||
690 | break; | 698 | break; |
691 | default: | 699 | default: |
692 | break; | 700 | break; |
diff --git a/lib/flex_array.c b/lib/flex_array.c index c0ea40ba2082..cab7621f98aa 100644 --- a/lib/flex_array.c +++ b/lib/flex_array.c | |||
@@ -88,8 +88,11 @@ struct flex_array *flex_array_alloc(int element_size, unsigned int total, | |||
88 | gfp_t flags) | 88 | gfp_t flags) |
89 | { | 89 | { |
90 | struct flex_array *ret; | 90 | struct flex_array *ret; |
91 | int max_size = FLEX_ARRAY_NR_BASE_PTRS * | 91 | int max_size = 0; |
92 | FLEX_ARRAY_ELEMENTS_PER_PART(element_size); | 92 | |
93 | if (element_size) | ||
94 | max_size = FLEX_ARRAY_NR_BASE_PTRS * | ||
95 | FLEX_ARRAY_ELEMENTS_PER_PART(element_size); | ||
93 | 96 | ||
94 | /* max_size will end up 0 if element_size > PAGE_SIZE */ | 97 | /* max_size will end up 0 if element_size > PAGE_SIZE */ |
95 | if (total > max_size) | 98 | if (total > max_size) |
@@ -183,15 +186,18 @@ __fa_get_part(struct flex_array *fa, int part_nr, gfp_t flags) | |||
183 | int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src, | 186 | int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src, |
184 | gfp_t flags) | 187 | gfp_t flags) |
185 | { | 188 | { |
186 | int part_nr = fa_element_to_part_nr(fa, element_nr); | 189 | int part_nr; |
187 | struct flex_array_part *part; | 190 | struct flex_array_part *part; |
188 | void *dst; | 191 | void *dst; |
189 | 192 | ||
190 | if (element_nr >= fa->total_nr_elements) | 193 | if (element_nr >= fa->total_nr_elements) |
191 | return -ENOSPC; | 194 | return -ENOSPC; |
195 | if (!fa->element_size) | ||
196 | return 0; | ||
192 | if (elements_fit_in_base(fa)) | 197 | if (elements_fit_in_base(fa)) |
193 | part = (struct flex_array_part *)&fa->parts[0]; | 198 | part = (struct flex_array_part *)&fa->parts[0]; |
194 | else { | 199 | else { |
200 | part_nr = fa_element_to_part_nr(fa, element_nr); | ||
195 | part = __fa_get_part(fa, part_nr, flags); | 201 | part = __fa_get_part(fa, part_nr, flags); |
196 | if (!part) | 202 | if (!part) |
197 | return -ENOMEM; | 203 | return -ENOMEM; |
@@ -211,15 +217,18 @@ EXPORT_SYMBOL(flex_array_put); | |||
211 | */ | 217 | */ |
212 | int flex_array_clear(struct flex_array *fa, unsigned int element_nr) | 218 | int flex_array_clear(struct flex_array *fa, unsigned int element_nr) |
213 | { | 219 | { |
214 | int part_nr = fa_element_to_part_nr(fa, element_nr); | 220 | int part_nr; |
215 | struct flex_array_part *part; | 221 | struct flex_array_part *part; |
216 | void *dst; | 222 | void *dst; |
217 | 223 | ||
218 | if (element_nr >= fa->total_nr_elements) | 224 | if (element_nr >= fa->total_nr_elements) |
219 | return -ENOSPC; | 225 | return -ENOSPC; |
226 | if (!fa->element_size) | ||
227 | return 0; | ||
220 | if (elements_fit_in_base(fa)) | 228 | if (elements_fit_in_base(fa)) |
221 | part = (struct flex_array_part *)&fa->parts[0]; | 229 | part = (struct flex_array_part *)&fa->parts[0]; |
222 | else { | 230 | else { |
231 | part_nr = fa_element_to_part_nr(fa, element_nr); | ||
223 | part = fa->parts[part_nr]; | 232 | part = fa->parts[part_nr]; |
224 | if (!part) | 233 | if (!part) |
225 | return -EINVAL; | 234 | return -EINVAL; |
@@ -232,10 +241,10 @@ EXPORT_SYMBOL(flex_array_clear); | |||
232 | 241 | ||
233 | /** | 242 | /** |
234 | * flex_array_prealloc - guarantee that array space exists | 243 | * flex_array_prealloc - guarantee that array space exists |
235 | * @fa: the flex array for which to preallocate parts | 244 | * @fa: the flex array for which to preallocate parts |
236 | * @start: index of first array element for which space is allocated | 245 | * @start: index of first array element for which space is allocated |
237 | * @end: index of last (inclusive) element for which space is allocated | 246 | * @nr_elements: number of elements for which space is allocated |
238 | * @flags: page allocation flags | 247 | * @flags: page allocation flags |
239 | * | 248 | * |
240 | * This will guarantee that no future calls to flex_array_put() | 249 | * This will guarantee that no future calls to flex_array_put() |
241 | * will allocate memory. It can be used if you are expecting to | 250 | * will allocate memory. It can be used if you are expecting to |
@@ -245,15 +254,27 @@ EXPORT_SYMBOL(flex_array_clear); | |||
245 | * Locking must be provided by the caller. | 254 | * Locking must be provided by the caller. |
246 | */ | 255 | */ |
247 | int flex_array_prealloc(struct flex_array *fa, unsigned int start, | 256 | int flex_array_prealloc(struct flex_array *fa, unsigned int start, |
248 | unsigned int end, gfp_t flags) | 257 | unsigned int nr_elements, gfp_t flags) |
249 | { | 258 | { |
250 | int start_part; | 259 | int start_part; |
251 | int end_part; | 260 | int end_part; |
252 | int part_nr; | 261 | int part_nr; |
262 | unsigned int end; | ||
253 | struct flex_array_part *part; | 263 | struct flex_array_part *part; |
254 | 264 | ||
255 | if (start >= fa->total_nr_elements || end >= fa->total_nr_elements) | 265 | if (!start && !nr_elements) |
266 | return 0; | ||
267 | if (start >= fa->total_nr_elements) | ||
268 | return -ENOSPC; | ||
269 | if (!nr_elements) | ||
270 | return 0; | ||
271 | |||
272 | end = start + nr_elements - 1; | ||
273 | |||
274 | if (end >= fa->total_nr_elements) | ||
256 | return -ENOSPC; | 275 | return -ENOSPC; |
276 | if (!fa->element_size) | ||
277 | return 0; | ||
257 | if (elements_fit_in_base(fa)) | 278 | if (elements_fit_in_base(fa)) |
258 | return 0; | 279 | return 0; |
259 | start_part = fa_element_to_part_nr(fa, start); | 280 | start_part = fa_element_to_part_nr(fa, start); |
@@ -281,14 +302,17 @@ EXPORT_SYMBOL(flex_array_prealloc); | |||
281 | */ | 302 | */ |
282 | void *flex_array_get(struct flex_array *fa, unsigned int element_nr) | 303 | void *flex_array_get(struct flex_array *fa, unsigned int element_nr) |
283 | { | 304 | { |
284 | int part_nr = fa_element_to_part_nr(fa, element_nr); | 305 | int part_nr; |
285 | struct flex_array_part *part; | 306 | struct flex_array_part *part; |
286 | 307 | ||
308 | if (!fa->element_size) | ||
309 | return NULL; | ||
287 | if (element_nr >= fa->total_nr_elements) | 310 | if (element_nr >= fa->total_nr_elements) |
288 | return NULL; | 311 | return NULL; |
289 | if (elements_fit_in_base(fa)) | 312 | if (elements_fit_in_base(fa)) |
290 | part = (struct flex_array_part *)&fa->parts[0]; | 313 | part = (struct flex_array_part *)&fa->parts[0]; |
291 | else { | 314 | else { |
315 | part_nr = fa_element_to_part_nr(fa, element_nr); | ||
292 | part = fa->parts[part_nr]; | 316 | part = fa->parts[part_nr]; |
293 | if (!part) | 317 | if (!part) |
294 | return NULL; | 318 | return NULL; |
@@ -343,6 +367,8 @@ int flex_array_shrink(struct flex_array *fa) | |||
343 | int part_nr; | 367 | int part_nr; |
344 | int ret = 0; | 368 | int ret = 0; |
345 | 369 | ||
370 | if (!fa->total_nr_elements || !fa->element_size) | ||
371 | return 0; | ||
346 | if (elements_fit_in_base(fa)) | 372 | if (elements_fit_in_base(fa)) |
347 | return ret; | 373 | return ret; |
348 | for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++) { | 374 | for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++) { |
diff --git a/lib/genalloc.c b/lib/genalloc.c index 1923f1490e72..577ddf805975 100644 --- a/lib/genalloc.c +++ b/lib/genalloc.c | |||
@@ -39,17 +39,20 @@ struct gen_pool *gen_pool_create(int min_alloc_order, int nid) | |||
39 | EXPORT_SYMBOL(gen_pool_create); | 39 | EXPORT_SYMBOL(gen_pool_create); |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * gen_pool_add - add a new chunk of special memory to the pool | 42 | * gen_pool_add_virt - add a new chunk of special memory to the pool |
43 | * @pool: pool to add new memory chunk to | 43 | * @pool: pool to add new memory chunk to |
44 | * @addr: starting address of memory chunk to add to pool | 44 | * @virt: virtual starting address of memory chunk to add to pool |
45 | * @phys: physical starting address of memory chunk to add to pool | ||
45 | * @size: size in bytes of the memory chunk to add to pool | 46 | * @size: size in bytes of the memory chunk to add to pool |
46 | * @nid: node id of the node the chunk structure and bitmap should be | 47 | * @nid: node id of the node the chunk structure and bitmap should be |
47 | * allocated on, or -1 | 48 | * allocated on, or -1 |
48 | * | 49 | * |
49 | * Add a new chunk of special memory to the specified pool. | 50 | * Add a new chunk of special memory to the specified pool. |
51 | * | ||
52 | * Returns 0 on success or a -ve errno on failure. | ||
50 | */ | 53 | */ |
51 | int gen_pool_add(struct gen_pool *pool, unsigned long addr, size_t size, | 54 | int gen_pool_add_virt(struct gen_pool *pool, unsigned long virt, phys_addr_t phys, |
52 | int nid) | 55 | size_t size, int nid) |
53 | { | 56 | { |
54 | struct gen_pool_chunk *chunk; | 57 | struct gen_pool_chunk *chunk; |
55 | int nbits = size >> pool->min_alloc_order; | 58 | int nbits = size >> pool->min_alloc_order; |
@@ -58,11 +61,12 @@ int gen_pool_add(struct gen_pool *pool, unsigned long addr, size_t size, | |||
58 | 61 | ||
59 | chunk = kmalloc_node(nbytes, GFP_KERNEL | __GFP_ZERO, nid); | 62 | chunk = kmalloc_node(nbytes, GFP_KERNEL | __GFP_ZERO, nid); |
60 | if (unlikely(chunk == NULL)) | 63 | if (unlikely(chunk == NULL)) |
61 | return -1; | 64 | return -ENOMEM; |
62 | 65 | ||
63 | spin_lock_init(&chunk->lock); | 66 | spin_lock_init(&chunk->lock); |
64 | chunk->start_addr = addr; | 67 | chunk->phys_addr = phys; |
65 | chunk->end_addr = addr + size; | 68 | chunk->start_addr = virt; |
69 | chunk->end_addr = virt + size; | ||
66 | 70 | ||
67 | write_lock(&pool->lock); | 71 | write_lock(&pool->lock); |
68 | list_add(&chunk->next_chunk, &pool->chunks); | 72 | list_add(&chunk->next_chunk, &pool->chunks); |
@@ -70,7 +74,32 @@ int gen_pool_add(struct gen_pool *pool, unsigned long addr, size_t size, | |||
70 | 74 | ||
71 | return 0; | 75 | return 0; |
72 | } | 76 | } |
73 | EXPORT_SYMBOL(gen_pool_add); | 77 | EXPORT_SYMBOL(gen_pool_add_virt); |
78 | |||
79 | /** | ||
80 | * gen_pool_virt_to_phys - return the physical address of memory | ||
81 | * @pool: pool to allocate from | ||
82 | * @addr: starting address of memory | ||
83 | * | ||
84 | * Returns the physical address on success, or -1 on error. | ||
85 | */ | ||
86 | phys_addr_t gen_pool_virt_to_phys(struct gen_pool *pool, unsigned long addr) | ||
87 | { | ||
88 | struct list_head *_chunk; | ||
89 | struct gen_pool_chunk *chunk; | ||
90 | |||
91 | read_lock(&pool->lock); | ||
92 | list_for_each(_chunk, &pool->chunks) { | ||
93 | chunk = list_entry(_chunk, struct gen_pool_chunk, next_chunk); | ||
94 | |||
95 | if (addr >= chunk->start_addr && addr < chunk->end_addr) | ||
96 | return chunk->phys_addr + addr - chunk->start_addr; | ||
97 | } | ||
98 | read_unlock(&pool->lock); | ||
99 | |||
100 | return -1; | ||
101 | } | ||
102 | EXPORT_SYMBOL(gen_pool_virt_to_phys); | ||
74 | 103 | ||
75 | /** | 104 | /** |
76 | * gen_pool_destroy - destroy a special memory pool | 105 | * gen_pool_destroy - destroy a special memory pool |
diff --git a/lib/kstrtox.c b/lib/kstrtox.c index a235f3cc471c..2dbae88090ac 100644 --- a/lib/kstrtox.c +++ b/lib/kstrtox.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/math64.h> | 17 | #include <linux/math64.h> |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/types.h> | 19 | #include <linux/types.h> |
20 | #include <asm/uaccess.h> | ||
20 | 21 | ||
21 | static inline char _tolower(const char c) | 22 | static inline char _tolower(const char c) |
22 | { | 23 | { |
@@ -222,3 +223,28 @@ int kstrtos8(const char *s, unsigned int base, s8 *res) | |||
222 | return 0; | 223 | return 0; |
223 | } | 224 | } |
224 | EXPORT_SYMBOL(kstrtos8); | 225 | EXPORT_SYMBOL(kstrtos8); |
226 | |||
227 | #define kstrto_from_user(f, g, type) \ | ||
228 | int f(const char __user *s, size_t count, unsigned int base, type *res) \ | ||
229 | { \ | ||
230 | /* sign, base 2 representation, newline, terminator */ \ | ||
231 | char buf[1 + sizeof(type) * 8 + 1 + 1]; \ | ||
232 | \ | ||
233 | count = min(count, sizeof(buf) - 1); \ | ||
234 | if (copy_from_user(buf, s, count)) \ | ||
235 | return -EFAULT; \ | ||
236 | buf[count] = '\0'; \ | ||
237 | return g(buf, base, res); \ | ||
238 | } \ | ||
239 | EXPORT_SYMBOL(f) | ||
240 | |||
241 | kstrto_from_user(kstrtoull_from_user, kstrtoull, unsigned long long); | ||
242 | kstrto_from_user(kstrtoll_from_user, kstrtoll, long long); | ||
243 | kstrto_from_user(kstrtoul_from_user, kstrtoul, unsigned long); | ||
244 | kstrto_from_user(kstrtol_from_user, kstrtol, long); | ||
245 | kstrto_from_user(kstrtouint_from_user, kstrtouint, unsigned int); | ||
246 | kstrto_from_user(kstrtoint_from_user, kstrtoint, int); | ||
247 | kstrto_from_user(kstrtou16_from_user, kstrtou16, u16); | ||
248 | kstrto_from_user(kstrtos16_from_user, kstrtos16, s16); | ||
249 | kstrto_from_user(kstrtou8_from_user, kstrtou8, u8); | ||
250 | kstrto_from_user(kstrtos8_from_user, kstrtos8, s8); | ||
diff --git a/lib/lru_cache.c b/lib/lru_cache.c index 270de9d31b8c..a07e7268d7ed 100644 --- a/lib/lru_cache.c +++ b/lib/lru_cache.c | |||
@@ -84,7 +84,7 @@ struct lru_cache *lc_create(const char *name, struct kmem_cache *cache, | |||
84 | if (e_count > LC_MAX_ACTIVE) | 84 | if (e_count > LC_MAX_ACTIVE) |
85 | return NULL; | 85 | return NULL; |
86 | 86 | ||
87 | slot = kzalloc(e_count * sizeof(struct hlist_head*), GFP_KERNEL); | 87 | slot = kcalloc(e_count, sizeof(struct hlist_head), GFP_KERNEL); |
88 | if (!slot) | 88 | if (!slot) |
89 | goto out_fail; | 89 | goto out_fail; |
90 | element = kzalloc(e_count * sizeof(struct lc_element *), GFP_KERNEL); | 90 | element = kzalloc(e_count * sizeof(struct lc_element *), GFP_KERNEL); |
diff --git a/lib/show_mem.c b/lib/show_mem.c index 90cbe4bb5960..4407f8c9b1f7 100644 --- a/lib/show_mem.c +++ b/lib/show_mem.c | |||
@@ -16,7 +16,7 @@ void show_mem(unsigned int filter) | |||
16 | nonshared = 0, highmem = 0; | 16 | nonshared = 0, highmem = 0; |
17 | 17 | ||
18 | printk("Mem-Info:\n"); | 18 | printk("Mem-Info:\n"); |
19 | __show_free_areas(filter); | 19 | show_free_areas(filter); |
20 | 20 | ||
21 | for_each_online_pgdat(pgdat) { | 21 | for_each_online_pgdat(pgdat) { |
22 | unsigned long i, flags; | 22 | unsigned long i, flags; |
diff --git a/lib/string.c b/lib/string.c index f71bead1be3e..01fad9b203e1 100644 --- a/lib/string.c +++ b/lib/string.c | |||
@@ -535,6 +535,35 @@ bool sysfs_streq(const char *s1, const char *s2) | |||
535 | } | 535 | } |
536 | EXPORT_SYMBOL(sysfs_streq); | 536 | EXPORT_SYMBOL(sysfs_streq); |
537 | 537 | ||
538 | /** | ||
539 | * strtobool - convert common user inputs into boolean values | ||
540 | * @s: input string | ||
541 | * @res: result | ||
542 | * | ||
543 | * This routine returns 0 iff the first character is one of 'Yy1Nn0'. | ||
544 | * Otherwise it will return -EINVAL. Value pointed to by res is | ||
545 | * updated upon finding a match. | ||
546 | */ | ||
547 | int strtobool(const char *s, bool *res) | ||
548 | { | ||
549 | switch (s[0]) { | ||
550 | case 'y': | ||
551 | case 'Y': | ||
552 | case '1': | ||
553 | *res = true; | ||
554 | break; | ||
555 | case 'n': | ||
556 | case 'N': | ||
557 | case '0': | ||
558 | *res = false; | ||
559 | break; | ||
560 | default: | ||
561 | return -EINVAL; | ||
562 | } | ||
563 | return 0; | ||
564 | } | ||
565 | EXPORT_SYMBOL(strtobool); | ||
566 | |||
538 | #ifndef __HAVE_ARCH_MEMSET | 567 | #ifndef __HAVE_ARCH_MEMSET |
539 | /** | 568 | /** |
540 | * memset - Fill a region of memory with the given value | 569 | * memset - Fill a region of memory with the given value |
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index bc0ac6b333dc..c11205688fb4 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -797,7 +797,7 @@ char *uuid_string(char *buf, char *end, const u8 *addr, | |||
797 | return string(buf, end, uuid, spec); | 797 | return string(buf, end, uuid, spec); |
798 | } | 798 | } |
799 | 799 | ||
800 | int kptr_restrict = 1; | 800 | int kptr_restrict __read_mostly; |
801 | 801 | ||
802 | /* | 802 | /* |
803 | * Show a '%p' thing. A kernel extension is that the '%p' is followed | 803 | * Show a '%p' thing. A kernel extension is that the '%p' is followed |
@@ -898,7 +898,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
898 | case 'U': | 898 | case 'U': |
899 | return uuid_string(buf, end, ptr, spec, fmt); | 899 | return uuid_string(buf, end, ptr, spec, fmt); |
900 | case 'V': | 900 | case 'V': |
901 | return buf + vsnprintf(buf, end - buf, | 901 | return buf + vsnprintf(buf, end > buf ? end - buf : 0, |
902 | ((struct va_format *)ptr)->fmt, | 902 | ((struct va_format *)ptr)->fmt, |
903 | *(((struct va_format *)ptr)->va)); | 903 | *(((struct va_format *)ptr)->va)); |
904 | case 'K': | 904 | case 'K': |
@@ -1161,8 +1161,7 @@ qualifier: | |||
1161 | * return is greater than or equal to @size, the resulting | 1161 | * return is greater than or equal to @size, the resulting |
1162 | * string is truncated. | 1162 | * string is truncated. |
1163 | * | 1163 | * |
1164 | * Call this function if you are already dealing with a va_list. | 1164 | * If you're not already dealing with a va_list consider using snprintf(). |
1165 | * You probably want snprintf() instead. | ||
1166 | */ | 1165 | */ |
1167 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | 1166 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) |
1168 | { | 1167 | { |
@@ -1336,8 +1335,7 @@ EXPORT_SYMBOL(vsnprintf); | |||
1336 | * the @buf not including the trailing '\0'. If @size is == 0 the function | 1335 | * the @buf not including the trailing '\0'. If @size is == 0 the function |
1337 | * returns 0. | 1336 | * returns 0. |
1338 | * | 1337 | * |
1339 | * Call this function if you are already dealing with a va_list. | 1338 | * If you're not already dealing with a va_list consider using scnprintf(). |
1340 | * You probably want scnprintf() instead. | ||
1341 | * | 1339 | * |
1342 | * See the vsnprintf() documentation for format string extensions over C99. | 1340 | * See the vsnprintf() documentation for format string extensions over C99. |
1343 | */ | 1341 | */ |
@@ -1416,8 +1414,7 @@ EXPORT_SYMBOL(scnprintf); | |||
1416 | * into @buf. Use vsnprintf() or vscnprintf() in order to avoid | 1414 | * into @buf. Use vsnprintf() or vscnprintf() in order to avoid |
1417 | * buffer overflows. | 1415 | * buffer overflows. |
1418 | * | 1416 | * |
1419 | * Call this function if you are already dealing with a va_list. | 1417 | * If you're not already dealing with a va_list consider using sprintf(). |
1420 | * You probably want sprintf() instead. | ||
1421 | * | 1418 | * |
1422 | * See the vsnprintf() documentation for format string extensions over C99. | 1419 | * See the vsnprintf() documentation for format string extensions over C99. |
1423 | */ | 1420 | */ |
diff --git a/lib/xz/xz_dec_lzma2.c b/lib/xz/xz_dec_lzma2.c index ea5fa4fe9d67..a6cdc969ea42 100644 --- a/lib/xz/xz_dec_lzma2.c +++ b/lib/xz/xz_dec_lzma2.c | |||
@@ -969,6 +969,9 @@ XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s, | |||
969 | */ | 969 | */ |
970 | tmp = b->in[b->in_pos++]; | 970 | tmp = b->in[b->in_pos++]; |
971 | 971 | ||
972 | if (tmp == 0x00) | ||
973 | return XZ_STREAM_END; | ||
974 | |||
972 | if (tmp >= 0xE0 || tmp == 0x01) { | 975 | if (tmp >= 0xE0 || tmp == 0x01) { |
973 | s->lzma2.need_props = true; | 976 | s->lzma2.need_props = true; |
974 | s->lzma2.need_dict_reset = false; | 977 | s->lzma2.need_dict_reset = false; |
@@ -1001,9 +1004,6 @@ XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s, | |||
1001 | lzma_reset(s); | 1004 | lzma_reset(s); |
1002 | } | 1005 | } |
1003 | } else { | 1006 | } else { |
1004 | if (tmp == 0x00) | ||
1005 | return XZ_STREAM_END; | ||
1006 | |||
1007 | if (tmp > 0x02) | 1007 | if (tmp > 0x02) |
1008 | return XZ_DATA_ERROR; | 1008 | return XZ_DATA_ERROR; |
1009 | 1009 | ||