aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Kconfig10
-rw-r--r--lib/Kconfig.debug74
-rw-r--r--lib/Makefile9
-rw-r--r--lib/audit.c2
-rw-r--r--lib/bitmap.c109
-rw-r--r--lib/bsearch.c53
-rw-r--r--lib/dma-debug.c18
-rw-r--r--lib/find_last_bit.c4
-rw-r--r--lib/find_next_bit.c18
-rw-r--r--lib/flex_array.c65
-rw-r--r--lib/genalloc.c45
-rw-r--r--lib/kstrtox.c26
-rw-r--r--lib/lru_cache.c2
-rw-r--r--lib/show_mem.c2
-rw-r--r--lib/string.c29
-rw-r--r--lib/vsprintf.c11
16 files changed, 367 insertions, 110 deletions
diff --git a/lib/Kconfig b/lib/Kconfig
index 9c10e38fc609..830181cc7a83 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -19,16 +19,6 @@ config RATIONAL
19config GENERIC_FIND_FIRST_BIT 19config GENERIC_FIND_FIRST_BIT
20 bool 20 bool
21 21
22config GENERIC_FIND_NEXT_BIT
23 bool
24
25config GENERIC_FIND_BIT_LE
26 bool
27
28config GENERIC_FIND_LAST_BIT
29 bool
30 default y
31
32config CRC_CCITT 22config CRC_CCITT
33 tristate "CRC-CCITT functions" 23 tristate "CRC-CCITT functions"
34 help 24 help
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
12config DEFAULT_MESSAGE_LOGLEVEL 13config 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
242config 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
241config BOOTPARAM_HUNG_TASK_PANIC 257config 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
338config DEBUG_OBJECTS_RCU_HEAD 354config 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
398config DEBUG_KMEMLEAK 414config 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
673config 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
657config DEBUG_KOBJECT 682config 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
878config 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
891config RCU_CPU_STALL_TIMEOUT 903config 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
902config 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
915config RCU_CPU_STALL_VERBOSE 914config 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
995config 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
996config LKDTM 1006config 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..6b597fdb1898 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -12,7 +12,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
12 idr.o int_sqrt.o extable.o prio_tree.o \ 12 idr.o int_sqrt.o extable.o prio_tree.o \
13 sha1.o irq_regs.o reciprocal_div.o argv_split.o \ 13 sha1.o irq_regs.o reciprocal_div.o argv_split.o \
14 proportions.o prio_heap.o ratelimit.o show_mem.o \ 14 proportions.o prio_heap.o ratelimit.o show_mem.o \
15 is_single_threaded.o plist.o decompress.o 15 is_single_threaded.o plist.o decompress.o find_next_bit.o
16 16
17lib-$(CONFIG_MMU) += ioremap.o 17lib-$(CONFIG_MMU) += ioremap.o
18lib-$(CONFIG_SMP) += cpumask.o 18lib-$(CONFIG_SMP) += cpumask.o
@@ -21,7 +21,8 @@ lib-y += kobject.o kref.o klist.o
21 21
22obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ 22obj-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 find_last_bit.o
25obj-y += kstrtox.o 26obj-y += kstrtox.o
26obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o 27obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
27 28
@@ -38,10 +39,6 @@ obj-$(CONFIG_DEBUG_LOCKING_API_SELFTESTS) += locking-selftest.o
38obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o 39obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o
39lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o 40lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
40lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o 41lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
41lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o
42lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
43lib-$(CONFIG_GENERIC_FIND_BIT_LE) += find_next_bit.o
44obj-$(CONFIG_GENERIC_FIND_LAST_BIT) += find_last_bit.o
45 42
46CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS)) 43CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
47obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o 44obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
diff --git a/lib/audit.c b/lib/audit.c
index 8e7dc1c63aa9..76bbed4a20e5 100644
--- a/lib/audit.c
+++ b/lib/audit.c
@@ -36,8 +36,10 @@ int audit_classify_arch(int arch)
36int audit_classify_syscall(int abi, unsigned syscall) 36int audit_classify_syscall(int abi, unsigned syscall)
37{ 37{
38 switch(syscall) { 38 switch(syscall) {
39#ifdef __NR_open
39 case __NR_open: 40 case __NR_open:
40 return 2; 41 return 2;
42#endif
41#ifdef __NR_openat 43#ifdef __NR_openat
42 case __NR_openat: 44 case __NR_openat:
43 return 3; 45 return 3;
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,
571EXPORT_SYMBOL(bitmap_scnlistprintf); 571EXPORT_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 */
590int bitmap_parselist(const char *bp, unsigned long *maskp, int nmaskbits) 593static 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
663int 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}
618EXPORT_SYMBOL(bitmap_parselist); 675EXPORT_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 */
693int 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}
702EXPORT_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 */
33void *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}
53EXPORT_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
652static int device_dma_allocations(struct device *dev) 652static 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)
674static int dma_debug_device_change(struct notifier_block *nb, unsigned long action, void *data) 676static 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/find_last_bit.c b/lib/find_last_bit.c
index 5d202e36bdd8..d903959ad695 100644
--- a/lib/find_last_bit.c
+++ b/lib/find_last_bit.c
@@ -15,6 +15,8 @@
15#include <asm/types.h> 15#include <asm/types.h>
16#include <asm/byteorder.h> 16#include <asm/byteorder.h>
17 17
18#ifndef find_last_bit
19
18unsigned long find_last_bit(const unsigned long *addr, unsigned long size) 20unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
19{ 21{
20 unsigned long words; 22 unsigned long words;
@@ -43,3 +45,5 @@ found:
43 return size; 45 return size;
44} 46}
45EXPORT_SYMBOL(find_last_bit); 47EXPORT_SYMBOL(find_last_bit);
48
49#endif
diff --git a/lib/find_next_bit.c b/lib/find_next_bit.c
index b0a8767282bf..4bd75a73ba00 100644
--- a/lib/find_next_bit.c
+++ b/lib/find_next_bit.c
@@ -16,7 +16,7 @@
16 16
17#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG) 17#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
18 18
19#ifdef CONFIG_GENERIC_FIND_NEXT_BIT 19#ifndef find_next_bit
20/* 20/*
21 * Find the next set bit in a memory region. 21 * Find the next set bit in a memory region.
22 */ 22 */
@@ -59,7 +59,9 @@ found_middle:
59 return result + __ffs(tmp); 59 return result + __ffs(tmp);
60} 60}
61EXPORT_SYMBOL(find_next_bit); 61EXPORT_SYMBOL(find_next_bit);
62#endif
62 63
64#ifndef find_next_zero_bit
63/* 65/*
64 * This implementation of find_{first,next}_zero_bit was stolen from 66 * This implementation of find_{first,next}_zero_bit was stolen from
65 * Linus' asm-alpha/bitops.h. 67 * Linus' asm-alpha/bitops.h.
@@ -103,9 +105,9 @@ found_middle:
103 return result + ffz(tmp); 105 return result + ffz(tmp);
104} 106}
105EXPORT_SYMBOL(find_next_zero_bit); 107EXPORT_SYMBOL(find_next_zero_bit);
106#endif /* CONFIG_GENERIC_FIND_NEXT_BIT */ 108#endif
107 109
108#ifdef CONFIG_GENERIC_FIND_FIRST_BIT 110#ifndef find_first_bit
109/* 111/*
110 * Find the first set bit in a memory region. 112 * Find the first set bit in a memory region.
111 */ 113 */
@@ -131,7 +133,9 @@ found:
131 return result + __ffs(tmp); 133 return result + __ffs(tmp);
132} 134}
133EXPORT_SYMBOL(find_first_bit); 135EXPORT_SYMBOL(find_first_bit);
136#endif
134 137
138#ifndef find_first_zero_bit
135/* 139/*
136 * Find the first cleared bit in a memory region. 140 * Find the first cleared bit in a memory region.
137 */ 141 */
@@ -157,10 +161,9 @@ found:
157 return result + ffz(tmp); 161 return result + ffz(tmp);
158} 162}
159EXPORT_SYMBOL(find_first_zero_bit); 163EXPORT_SYMBOL(find_first_zero_bit);
160#endif /* CONFIG_GENERIC_FIND_FIRST_BIT */ 164#endif
161 165
162#ifdef __BIG_ENDIAN 166#ifdef __BIG_ENDIAN
163#ifdef CONFIG_GENERIC_FIND_BIT_LE
164 167
165/* include/linux/byteorder does not support "unsigned long" type */ 168/* include/linux/byteorder does not support "unsigned long" type */
166static inline unsigned long ext2_swabp(const unsigned long * x) 169static inline unsigned long ext2_swabp(const unsigned long * x)
@@ -186,6 +189,7 @@ static inline unsigned long ext2_swab(const unsigned long y)
186#endif 189#endif
187} 190}
188 191
192#ifndef find_next_zero_bit_le
189unsigned long find_next_zero_bit_le(const void *addr, unsigned 193unsigned long find_next_zero_bit_le(const void *addr, unsigned
190 long size, unsigned long offset) 194 long size, unsigned long offset)
191{ 195{
@@ -229,7 +233,9 @@ found_middle_swap:
229 return result + ffz(ext2_swab(tmp)); 233 return result + ffz(ext2_swab(tmp));
230} 234}
231EXPORT_SYMBOL(find_next_zero_bit_le); 235EXPORT_SYMBOL(find_next_zero_bit_le);
236#endif
232 237
238#ifndef find_next_bit_le
233unsigned long find_next_bit_le(const void *addr, unsigned 239unsigned long find_next_bit_le(const void *addr, unsigned
234 long size, unsigned long offset) 240 long size, unsigned long offset)
235{ 241{
@@ -274,6 +280,6 @@ found_middle_swap:
274 return result + __ffs(ext2_swab(tmp)); 280 return result + __ffs(ext2_swab(tmp));
275} 281}
276EXPORT_SYMBOL(find_next_bit_le); 282EXPORT_SYMBOL(find_next_bit_le);
283#endif
277 284
278#endif /* CONFIG_GENERIC_FIND_BIT_LE */
279#endif /* __BIG_ENDIAN */ 285#endif /* __BIG_ENDIAN */
diff --git a/lib/flex_array.c b/lib/flex_array.c
index 854b57bd7d9d..9b8b89458c4c 100644
--- a/lib/flex_array.c
+++ b/lib/flex_array.c
@@ -24,6 +24,7 @@
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/module.h>
27#include <linux/reciprocal_div.h>
27 28
28struct flex_array_part { 29struct flex_array_part {
29 char elements[FLEX_ARRAY_PART_SIZE]; 30 char elements[FLEX_ARRAY_PART_SIZE];
@@ -70,15 +71,15 @@ static inline int elements_fit_in_base(struct flex_array *fa)
70 * Element size | Objects | Objects | 71 * Element size | Objects | Objects |
71 * PAGE_SIZE=4k | 32-bit | 64-bit | 72 * PAGE_SIZE=4k | 32-bit | 64-bit |
72 * ---------------------------------| 73 * ---------------------------------|
73 * 1 bytes | 4186112 | 2093056 | 74 * 1 bytes | 4177920 | 2088960 |
74 * 2 bytes | 2093056 | 1046528 | 75 * 2 bytes | 2088960 | 1044480 |
75 * 3 bytes | 1395030 | 697515 | 76 * 3 bytes | 1392300 | 696150 |
76 * 4 bytes | 1046528 | 523264 | 77 * 4 bytes | 1044480 | 522240 |
77 * 32 bytes | 130816 | 65408 | 78 * 32 bytes | 130560 | 65408 |
78 * 33 bytes | 126728 | 63364 | 79 * 33 bytes | 126480 | 63240 |
79 * 2048 bytes | 2044 | 1022 | 80 * 2048 bytes | 2040 | 1020 |
80 * 2049 bytes | 1022 | 511 | 81 * 2049 bytes | 1020 | 510 |
81 * void * | 1046528 | 261632 | 82 * void * | 1044480 | 261120 |
82 * 83 *
83 * Since 64-bit pointers are twice the size, we lose half the 84 * Since 64-bit pointers are twice the size, we lose half the
84 * capacity in the base structure. Also note that no effort is made 85 * capacity in the base structure. Also note that no effort is made
@@ -88,8 +89,15 @@ struct flex_array *flex_array_alloc(int element_size, unsigned int total,
88 gfp_t flags) 89 gfp_t flags)
89{ 90{
90 struct flex_array *ret; 91 struct flex_array *ret;
91 int max_size = FLEX_ARRAY_NR_BASE_PTRS * 92 int elems_per_part = 0;
92 FLEX_ARRAY_ELEMENTS_PER_PART(element_size); 93 int reciprocal_elems = 0;
94 int max_size = 0;
95
96 if (element_size) {
97 elems_per_part = FLEX_ARRAY_ELEMENTS_PER_PART(element_size);
98 reciprocal_elems = reciprocal_value(elems_per_part);
99 max_size = FLEX_ARRAY_NR_BASE_PTRS * elems_per_part;
100 }
93 101
94 /* max_size will end up 0 if element_size > PAGE_SIZE */ 102 /* max_size will end up 0 if element_size > PAGE_SIZE */
95 if (total > max_size) 103 if (total > max_size)
@@ -99,6 +107,8 @@ struct flex_array *flex_array_alloc(int element_size, unsigned int total,
99 return NULL; 107 return NULL;
100 ret->element_size = element_size; 108 ret->element_size = element_size;
101 ret->total_nr_elements = total; 109 ret->total_nr_elements = total;
110 ret->elems_per_part = elems_per_part;
111 ret->reciprocal_elems = reciprocal_elems;
102 if (elements_fit_in_base(ret) && !(flags & __GFP_ZERO)) 112 if (elements_fit_in_base(ret) && !(flags & __GFP_ZERO))
103 memset(&ret->parts[0], FLEX_ARRAY_FREE, 113 memset(&ret->parts[0], FLEX_ARRAY_FREE,
104 FLEX_ARRAY_BASE_BYTES_LEFT); 114 FLEX_ARRAY_BASE_BYTES_LEFT);
@@ -109,7 +119,7 @@ EXPORT_SYMBOL(flex_array_alloc);
109static int fa_element_to_part_nr(struct flex_array *fa, 119static int fa_element_to_part_nr(struct flex_array *fa,
110 unsigned int element_nr) 120 unsigned int element_nr)
111{ 121{
112 return element_nr / FLEX_ARRAY_ELEMENTS_PER_PART(fa->element_size); 122 return reciprocal_divide(element_nr, fa->reciprocal_elems);
113} 123}
114 124
115/** 125/**
@@ -138,12 +148,12 @@ void flex_array_free(struct flex_array *fa)
138EXPORT_SYMBOL(flex_array_free); 148EXPORT_SYMBOL(flex_array_free);
139 149
140static unsigned int index_inside_part(struct flex_array *fa, 150static unsigned int index_inside_part(struct flex_array *fa,
141 unsigned int element_nr) 151 unsigned int element_nr,
152 unsigned int part_nr)
142{ 153{
143 unsigned int part_offset; 154 unsigned int part_offset;
144 155
145 part_offset = element_nr % 156 part_offset = element_nr - part_nr * fa->elems_per_part;
146 FLEX_ARRAY_ELEMENTS_PER_PART(fa->element_size);
147 return part_offset * fa->element_size; 157 return part_offset * fa->element_size;
148} 158}
149 159
@@ -183,20 +193,23 @@ __fa_get_part(struct flex_array *fa, int part_nr, gfp_t flags)
183int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src, 193int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src,
184 gfp_t flags) 194 gfp_t flags)
185{ 195{
186 int part_nr = fa_element_to_part_nr(fa, element_nr); 196 int part_nr = 0;
187 struct flex_array_part *part; 197 struct flex_array_part *part;
188 void *dst; 198 void *dst;
189 199
190 if (element_nr >= fa->total_nr_elements) 200 if (element_nr >= fa->total_nr_elements)
191 return -ENOSPC; 201 return -ENOSPC;
202 if (!fa->element_size)
203 return 0;
192 if (elements_fit_in_base(fa)) 204 if (elements_fit_in_base(fa))
193 part = (struct flex_array_part *)&fa->parts[0]; 205 part = (struct flex_array_part *)&fa->parts[0];
194 else { 206 else {
207 part_nr = fa_element_to_part_nr(fa, element_nr);
195 part = __fa_get_part(fa, part_nr, flags); 208 part = __fa_get_part(fa, part_nr, flags);
196 if (!part) 209 if (!part)
197 return -ENOMEM; 210 return -ENOMEM;
198 } 211 }
199 dst = &part->elements[index_inside_part(fa, element_nr)]; 212 dst = &part->elements[index_inside_part(fa, element_nr, part_nr)];
200 memcpy(dst, src, fa->element_size); 213 memcpy(dst, src, fa->element_size);
201 return 0; 214 return 0;
202} 215}
@@ -211,20 +224,23 @@ EXPORT_SYMBOL(flex_array_put);
211 */ 224 */
212int flex_array_clear(struct flex_array *fa, unsigned int element_nr) 225int flex_array_clear(struct flex_array *fa, unsigned int element_nr)
213{ 226{
214 int part_nr = fa_element_to_part_nr(fa, element_nr); 227 int part_nr = 0;
215 struct flex_array_part *part; 228 struct flex_array_part *part;
216 void *dst; 229 void *dst;
217 230
218 if (element_nr >= fa->total_nr_elements) 231 if (element_nr >= fa->total_nr_elements)
219 return -ENOSPC; 232 return -ENOSPC;
233 if (!fa->element_size)
234 return 0;
220 if (elements_fit_in_base(fa)) 235 if (elements_fit_in_base(fa))
221 part = (struct flex_array_part *)&fa->parts[0]; 236 part = (struct flex_array_part *)&fa->parts[0];
222 else { 237 else {
238 part_nr = fa_element_to_part_nr(fa, element_nr);
223 part = fa->parts[part_nr]; 239 part = fa->parts[part_nr];
224 if (!part) 240 if (!part)
225 return -EINVAL; 241 return -EINVAL;
226 } 242 }
227 dst = &part->elements[index_inside_part(fa, element_nr)]; 243 dst = &part->elements[index_inside_part(fa, element_nr, part_nr)];
228 memset(dst, FLEX_ARRAY_FREE, fa->element_size); 244 memset(dst, FLEX_ARRAY_FREE, fa->element_size);
229 return 0; 245 return 0;
230} 246}
@@ -264,6 +280,8 @@ int flex_array_prealloc(struct flex_array *fa, unsigned int start,
264 280
265 if (end >= fa->total_nr_elements) 281 if (end >= fa->total_nr_elements)
266 return -ENOSPC; 282 return -ENOSPC;
283 if (!fa->element_size)
284 return 0;
267 if (elements_fit_in_base(fa)) 285 if (elements_fit_in_base(fa))
268 return 0; 286 return 0;
269 start_part = fa_element_to_part_nr(fa, start); 287 start_part = fa_element_to_part_nr(fa, start);
@@ -291,19 +309,22 @@ EXPORT_SYMBOL(flex_array_prealloc);
291 */ 309 */
292void *flex_array_get(struct flex_array *fa, unsigned int element_nr) 310void *flex_array_get(struct flex_array *fa, unsigned int element_nr)
293{ 311{
294 int part_nr = fa_element_to_part_nr(fa, element_nr); 312 int part_nr = 0;
295 struct flex_array_part *part; 313 struct flex_array_part *part;
296 314
315 if (!fa->element_size)
316 return NULL;
297 if (element_nr >= fa->total_nr_elements) 317 if (element_nr >= fa->total_nr_elements)
298 return NULL; 318 return NULL;
299 if (elements_fit_in_base(fa)) 319 if (elements_fit_in_base(fa))
300 part = (struct flex_array_part *)&fa->parts[0]; 320 part = (struct flex_array_part *)&fa->parts[0];
301 else { 321 else {
322 part_nr = fa_element_to_part_nr(fa, element_nr);
302 part = fa->parts[part_nr]; 323 part = fa->parts[part_nr];
303 if (!part) 324 if (!part)
304 return NULL; 325 return NULL;
305 } 326 }
306 return &part->elements[index_inside_part(fa, element_nr)]; 327 return &part->elements[index_inside_part(fa, element_nr, part_nr)];
307} 328}
308EXPORT_SYMBOL(flex_array_get); 329EXPORT_SYMBOL(flex_array_get);
309 330
@@ -353,7 +374,7 @@ int flex_array_shrink(struct flex_array *fa)
353 int part_nr; 374 int part_nr;
354 int ret = 0; 375 int ret = 0;
355 376
356 if (!fa->total_nr_elements) 377 if (!fa->total_nr_elements || !fa->element_size)
357 return 0; 378 return 0;
358 if (elements_fit_in_base(fa)) 379 if (elements_fit_in_base(fa))
359 return ret; 380 return ret;
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)
39EXPORT_SYMBOL(gen_pool_create); 39EXPORT_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 */
51int gen_pool_add(struct gen_pool *pool, unsigned long addr, size_t size, 54int 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}
73EXPORT_SYMBOL(gen_pool_add); 77EXPORT_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 */
86phys_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}
102EXPORT_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
21static inline char _tolower(const char c) 22static 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}
224EXPORT_SYMBOL(kstrtos8); 225EXPORT_SYMBOL(kstrtos8);
226
227#define kstrto_from_user(f, g, type) \
228int 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} \
239EXPORT_SYMBOL(f)
240
241kstrto_from_user(kstrtoull_from_user, kstrtoull, unsigned long long);
242kstrto_from_user(kstrtoll_from_user, kstrtoll, long long);
243kstrto_from_user(kstrtoul_from_user, kstrtoul, unsigned long);
244kstrto_from_user(kstrtol_from_user, kstrtol, long);
245kstrto_from_user(kstrtouint_from_user, kstrtouint, unsigned int);
246kstrto_from_user(kstrtoint_from_user, kstrtoint, int);
247kstrto_from_user(kstrtou16_from_user, kstrtou16, u16);
248kstrto_from_user(kstrtos16_from_user, kstrtos16, s16);
249kstrto_from_user(kstrtou8_from_user, kstrtou8, u8);
250kstrto_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}
536EXPORT_SYMBOL(sysfs_streq); 536EXPORT_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 */
547int 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}
565EXPORT_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 dfd60192bc2e..c11205688fb4 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -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 */
1167int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) 1166int 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 */