diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 4 | ||||
-rw-r--r-- | lib/Kconfig.debug | 123 | ||||
-rw-r--r-- | lib/Makefile | 5 | ||||
-rw-r--r-- | lib/cmdline.c | 2 | ||||
-rw-r--r-- | lib/debugobjects.c | 31 | ||||
-rw-r--r-- | lib/dynamic_printk.c | 418 | ||||
-rw-r--r-- | lib/iommu-helper.c | 14 | ||||
-rw-r--r-- | lib/klist.c | 96 | ||||
-rw-r--r-- | lib/kobject.c | 38 | ||||
-rw-r--r-- | lib/parser.c | 2 | ||||
-rw-r--r-- | lib/percpu_counter.c | 8 | ||||
-rw-r--r-- | lib/scatterlist.c | 4 | ||||
-rw-r--r-- | lib/string_helpers.c | 64 | ||||
-rw-r--r-- | lib/swiotlb.c | 49 | ||||
-rw-r--r-- | lib/vsprintf.c | 246 |
15 files changed, 893 insertions, 211 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index c7ad7a5b3535..85cf7ea978aa 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
@@ -8,10 +8,10 @@ config BITREVERSE | |||
8 | tristate | 8 | tristate |
9 | 9 | ||
10 | config GENERIC_FIND_FIRST_BIT | 10 | config GENERIC_FIND_FIRST_BIT |
11 | def_bool n | 11 | bool |
12 | 12 | ||
13 | config GENERIC_FIND_NEXT_BIT | 13 | config GENERIC_FIND_NEXT_BIT |
14 | def_bool n | 14 | bool |
15 | 15 | ||
16 | config CRC_CCITT | 16 | config CRC_CCITT |
17 | tristate "CRC-CCITT functions" | 17 | tristate "CRC-CCITT functions" |
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 8b5a7d304a5f..b0f239e443bc 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
@@ -394,7 +394,7 @@ config LOCKDEP | |||
394 | bool | 394 | bool |
395 | depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT | 395 | depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT |
396 | select STACKTRACE | 396 | select STACKTRACE |
397 | select FRAME_POINTER if !X86 && !MIPS | 397 | select FRAME_POINTER if !X86 && !MIPS && !PPC |
398 | select KALLSYMS | 398 | select KALLSYMS |
399 | select KALLSYMS_ALL | 399 | select KALLSYMS_ALL |
400 | 400 | ||
@@ -495,6 +495,15 @@ config DEBUG_VM | |||
495 | 495 | ||
496 | If unsure, say N. | 496 | If unsure, say N. |
497 | 497 | ||
498 | config DEBUG_VIRTUAL | ||
499 | bool "Debug VM translations" | ||
500 | depends on DEBUG_KERNEL && X86 | ||
501 | help | ||
502 | Enable some costly sanity checks in virtual to page code. This can | ||
503 | catch mistakes with virt_to_page() and friends. | ||
504 | |||
505 | If unsure, say N. | ||
506 | |||
498 | config DEBUG_WRITECOUNT | 507 | config DEBUG_WRITECOUNT |
499 | bool "Debug filesystem writers count" | 508 | bool "Debug filesystem writers count" |
500 | depends on DEBUG_KERNEL | 509 | depends on DEBUG_KERNEL |
@@ -597,6 +606,19 @@ config RCU_TORTURE_TEST_RUNNABLE | |||
597 | Say N here if you want the RCU torture tests to start only | 606 | Say N here if you want the RCU torture tests to start only |
598 | after being manually enabled via /proc. | 607 | after being manually enabled via /proc. |
599 | 608 | ||
609 | config RCU_CPU_STALL_DETECTOR | ||
610 | bool "Check for stalled CPUs delaying RCU grace periods" | ||
611 | depends on CLASSIC_RCU | ||
612 | default n | ||
613 | help | ||
614 | This option causes RCU to printk information on which | ||
615 | CPUs are delaying the current grace period, but only when | ||
616 | the grace period extends for excessive time periods. | ||
617 | |||
618 | Say Y if you want RCU to perform such checks. | ||
619 | |||
620 | Say N if you are unsure. | ||
621 | |||
600 | config KPROBES_SANITY_TEST | 622 | config KPROBES_SANITY_TEST |
601 | bool "Kprobes sanity tests" | 623 | bool "Kprobes sanity tests" |
602 | depends on DEBUG_KERNEL | 624 | depends on DEBUG_KERNEL |
@@ -624,6 +646,33 @@ config BACKTRACE_SELF_TEST | |||
624 | 646 | ||
625 | Say N if you are unsure. | 647 | Say N if you are unsure. |
626 | 648 | ||
649 | config DEBUG_BLOCK_EXT_DEVT | ||
650 | bool "Force extended block device numbers and spread them" | ||
651 | depends on DEBUG_KERNEL | ||
652 | depends on BLOCK | ||
653 | default n | ||
654 | help | ||
655 | BIG FAT WARNING: ENABLING THIS OPTION MIGHT BREAK BOOTING ON | ||
656 | SOME DISTRIBUTIONS. DO NOT ENABLE THIS UNLESS YOU KNOW WHAT | ||
657 | YOU ARE DOING. Distros, please enable this and fix whatever | ||
658 | is broken. | ||
659 | |||
660 | Conventionally, block device numbers are allocated from | ||
661 | predetermined contiguous area. However, extended block area | ||
662 | may introduce non-contiguous block device numbers. This | ||
663 | option forces most block device numbers to be allocated from | ||
664 | the extended space and spreads them to discover kernel or | ||
665 | userland code paths which assume predetermined contiguous | ||
666 | device number allocation. | ||
667 | |||
668 | Note that turning on this debug option shuffles all the | ||
669 | device numbers for all IDE and SCSI devices including libata | ||
670 | ones, so root partition specified using device number | ||
671 | directly (via rdev or root=MAJ:MIN) won't work anymore. | ||
672 | Textual device names (root=/dev/sdXn) will continue to work. | ||
673 | |||
674 | Say N if you are unsure. | ||
675 | |||
627 | config LKDTM | 676 | config LKDTM |
628 | tristate "Linux Kernel Dump Test Tool Module" | 677 | tristate "Linux Kernel Dump Test Tool Module" |
629 | depends on DEBUG_KERNEL | 678 | depends on DEBUG_KERNEL |
@@ -661,10 +710,21 @@ config FAIL_PAGE_ALLOC | |||
661 | 710 | ||
662 | config FAIL_MAKE_REQUEST | 711 | config FAIL_MAKE_REQUEST |
663 | bool "Fault-injection capability for disk IO" | 712 | bool "Fault-injection capability for disk IO" |
664 | depends on FAULT_INJECTION | 713 | depends on FAULT_INJECTION && BLOCK |
665 | help | 714 | help |
666 | Provide fault-injection capability for disk IO. | 715 | Provide fault-injection capability for disk IO. |
667 | 716 | ||
717 | config FAIL_IO_TIMEOUT | ||
718 | bool "Faul-injection capability for faking disk interrupts" | ||
719 | depends on FAULT_INJECTION && BLOCK | ||
720 | help | ||
721 | Provide fault-injection capability on end IO handling. This | ||
722 | will make the block layer "forget" an interrupt as configured, | ||
723 | thus exercising the error handling. | ||
724 | |||
725 | Only works with drivers that use the generic timeout handling, | ||
726 | for others it wont do anything. | ||
727 | |||
668 | config FAULT_INJECTION_DEBUG_FS | 728 | config FAULT_INJECTION_DEBUG_FS |
669 | bool "Debugfs entries for fault-injection capabilities" | 729 | bool "Debugfs entries for fault-injection capabilities" |
670 | depends on FAULT_INJECTION && SYSFS && DEBUG_FS | 730 | depends on FAULT_INJECTION && SYSFS && DEBUG_FS |
@@ -676,13 +736,13 @@ config FAULT_INJECTION_STACKTRACE_FILTER | |||
676 | depends on FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT | 736 | depends on FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT |
677 | depends on !X86_64 | 737 | depends on !X86_64 |
678 | select STACKTRACE | 738 | select STACKTRACE |
679 | select FRAME_POINTER | 739 | select FRAME_POINTER if !PPC |
680 | help | 740 | help |
681 | Provide stacktrace filter for fault-injection capabilities | 741 | Provide stacktrace filter for fault-injection capabilities |
682 | 742 | ||
683 | config LATENCYTOP | 743 | config LATENCYTOP |
684 | bool "Latency measuring infrastructure" | 744 | bool "Latency measuring infrastructure" |
685 | select FRAME_POINTER if !MIPS | 745 | select FRAME_POINTER if !MIPS && !PPC |
686 | select KALLSYMS | 746 | select KALLSYMS |
687 | select KALLSYMS_ALL | 747 | select KALLSYMS_ALL |
688 | select STACKTRACE | 748 | select STACKTRACE |
@@ -752,6 +812,61 @@ menuconfig BUILD_DOCSRC | |||
752 | 812 | ||
753 | Say N if you are unsure. | 813 | Say N if you are unsure. |
754 | 814 | ||
815 | config DYNAMIC_PRINTK_DEBUG | ||
816 | bool "Enable dynamic printk() call support" | ||
817 | default n | ||
818 | depends on PRINTK | ||
819 | select PRINTK_DEBUG | ||
820 | help | ||
821 | |||
822 | Compiles debug level messages into the kernel, which would not | ||
823 | otherwise be available at runtime. These messages can then be | ||
824 | enabled/disabled on a per module basis. This mechanism implicitly | ||
825 | enables all pr_debug() and dev_dbg() calls. The impact of this | ||
826 | compile option is a larger kernel text size of about 2%. | ||
827 | |||
828 | Usage: | ||
829 | |||
830 | Dynamic debugging is controlled by the debugfs file, | ||
831 | dynamic_printk/modules. This file contains a list of the modules that | ||
832 | can be enabled. The format of the file is the module name, followed | ||
833 | by a set of flags that can be enabled. The first flag is always the | ||
834 | 'enabled' flag. For example: | ||
835 | |||
836 | <module_name> <enabled=0/1> | ||
837 | . | ||
838 | . | ||
839 | . | ||
840 | |||
841 | <module_name> : Name of the module in which the debug call resides | ||
842 | <enabled=0/1> : whether the messages are enabled or not | ||
843 | |||
844 | From a live system: | ||
845 | |||
846 | snd_hda_intel enabled=0 | ||
847 | fixup enabled=0 | ||
848 | driver enabled=0 | ||
849 | |||
850 | Enable a module: | ||
851 | |||
852 | $echo "set enabled=1 <module_name>" > dynamic_printk/modules | ||
853 | |||
854 | Disable a module: | ||
855 | |||
856 | $echo "set enabled=0 <module_name>" > dynamic_printk/modules | ||
857 | |||
858 | Enable all modules: | ||
859 | |||
860 | $echo "set enabled=1 all" > dynamic_printk/modules | ||
861 | |||
862 | Disable all modules: | ||
863 | |||
864 | $echo "set enabled=0 all" > dynamic_printk/modules | ||
865 | |||
866 | Finally, passing "dynamic_printk" at the command line enables | ||
867 | debugging for all modules. This mode can be turned off via the above | ||
868 | disable command. | ||
869 | |||
755 | source "samples/Kconfig" | 870 | source "samples/Kconfig" |
756 | 871 | ||
757 | source "lib/Kconfig.kgdb" | 872 | source "lib/Kconfig.kgdb" |
diff --git a/lib/Makefile b/lib/Makefile index 3b1f94bbe9de..16feaab057b2 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -19,7 +19,8 @@ lib-$(CONFIG_SMP) += cpumask.o | |||
19 | lib-y += kobject.o kref.o klist.o | 19 | lib-y += kobject.o kref.o klist.o |
20 | 20 | ||
21 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | 21 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
22 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o | 22 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ |
23 | string_helpers.o | ||
23 | 24 | ||
24 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) | 25 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) |
25 | CFLAGS_kobject.o += -DDEBUG | 26 | CFLAGS_kobject.o += -DDEBUG |
@@ -80,6 +81,8 @@ obj-$(CONFIG_HAVE_LMB) += lmb.o | |||
80 | 81 | ||
81 | obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o | 82 | obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o |
82 | 83 | ||
84 | obj-$(CONFIG_DYNAMIC_PRINTK_DEBUG) += dynamic_printk.o | ||
85 | |||
83 | hostprogs-y := gen_crc32table | 86 | hostprogs-y := gen_crc32table |
84 | clean-files := crc32table.h | 87 | clean-files := crc32table.h |
85 | 88 | ||
diff --git a/lib/cmdline.c b/lib/cmdline.c index 5ba8a942a478..f5f3ad8b62ff 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c | |||
@@ -126,7 +126,7 @@ char *get_options(const char *str, int nints, int *ints) | |||
126 | * megabyte, or one gigabyte, respectively. | 126 | * megabyte, or one gigabyte, respectively. |
127 | */ | 127 | */ |
128 | 128 | ||
129 | unsigned long long memparse(char *ptr, char **retptr) | 129 | unsigned long long memparse(const char *ptr, char **retptr) |
130 | { | 130 | { |
131 | char *endptr; /* local pointer to end of parsed string */ | 131 | char *endptr; /* local pointer to end of parsed string */ |
132 | 132 | ||
diff --git a/lib/debugobjects.c b/lib/debugobjects.c index 45a6bde762d1..e3ab374e1334 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c | |||
@@ -112,6 +112,7 @@ static struct debug_obj *lookup_object(void *addr, struct debug_bucket *b) | |||
112 | 112 | ||
113 | /* | 113 | /* |
114 | * Allocate a new object. If the pool is empty, switch off the debugger. | 114 | * Allocate a new object. If the pool is empty, switch off the debugger. |
115 | * Must be called with interrupts disabled. | ||
115 | */ | 116 | */ |
116 | static struct debug_obj * | 117 | static struct debug_obj * |
117 | alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr) | 118 | alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr) |
@@ -148,17 +149,18 @@ alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr) | |||
148 | static void free_object(struct debug_obj *obj) | 149 | static void free_object(struct debug_obj *obj) |
149 | { | 150 | { |
150 | unsigned long idx = (unsigned long)(obj - obj_static_pool); | 151 | unsigned long idx = (unsigned long)(obj - obj_static_pool); |
152 | unsigned long flags; | ||
151 | 153 | ||
152 | if (obj_pool_free < ODEBUG_POOL_SIZE || idx < ODEBUG_POOL_SIZE) { | 154 | if (obj_pool_free < ODEBUG_POOL_SIZE || idx < ODEBUG_POOL_SIZE) { |
153 | spin_lock(&pool_lock); | 155 | spin_lock_irqsave(&pool_lock, flags); |
154 | hlist_add_head(&obj->node, &obj_pool); | 156 | hlist_add_head(&obj->node, &obj_pool); |
155 | obj_pool_free++; | 157 | obj_pool_free++; |
156 | obj_pool_used--; | 158 | obj_pool_used--; |
157 | spin_unlock(&pool_lock); | 159 | spin_unlock_irqrestore(&pool_lock, flags); |
158 | } else { | 160 | } else { |
159 | spin_lock(&pool_lock); | 161 | spin_lock_irqsave(&pool_lock, flags); |
160 | obj_pool_used--; | 162 | obj_pool_used--; |
161 | spin_unlock(&pool_lock); | 163 | spin_unlock_irqrestore(&pool_lock, flags); |
162 | kmem_cache_free(obj_cache, obj); | 164 | kmem_cache_free(obj_cache, obj); |
163 | } | 165 | } |
164 | } | 166 | } |
@@ -171,6 +173,7 @@ static void debug_objects_oom(void) | |||
171 | { | 173 | { |
172 | struct debug_bucket *db = obj_hash; | 174 | struct debug_bucket *db = obj_hash; |
173 | struct hlist_node *node, *tmp; | 175 | struct hlist_node *node, *tmp; |
176 | HLIST_HEAD(freelist); | ||
174 | struct debug_obj *obj; | 177 | struct debug_obj *obj; |
175 | unsigned long flags; | 178 | unsigned long flags; |
176 | int i; | 179 | int i; |
@@ -179,11 +182,14 @@ static void debug_objects_oom(void) | |||
179 | 182 | ||
180 | for (i = 0; i < ODEBUG_HASH_SIZE; i++, db++) { | 183 | for (i = 0; i < ODEBUG_HASH_SIZE; i++, db++) { |
181 | spin_lock_irqsave(&db->lock, flags); | 184 | spin_lock_irqsave(&db->lock, flags); |
182 | hlist_for_each_entry_safe(obj, node, tmp, &db->list, node) { | 185 | hlist_move_list(&db->list, &freelist); |
186 | spin_unlock_irqrestore(&db->lock, flags); | ||
187 | |||
188 | /* Now free them */ | ||
189 | hlist_for_each_entry_safe(obj, node, tmp, &freelist, node) { | ||
183 | hlist_del(&obj->node); | 190 | hlist_del(&obj->node); |
184 | free_object(obj); | 191 | free_object(obj); |
185 | } | 192 | } |
186 | spin_unlock_irqrestore(&db->lock, flags); | ||
187 | } | 193 | } |
188 | } | 194 | } |
189 | 195 | ||
@@ -498,8 +504,9 @@ void debug_object_free(void *addr, struct debug_obj_descr *descr) | |||
498 | return; | 504 | return; |
499 | default: | 505 | default: |
500 | hlist_del(&obj->node); | 506 | hlist_del(&obj->node); |
507 | spin_unlock_irqrestore(&db->lock, flags); | ||
501 | free_object(obj); | 508 | free_object(obj); |
502 | break; | 509 | return; |
503 | } | 510 | } |
504 | out_unlock: | 511 | out_unlock: |
505 | spin_unlock_irqrestore(&db->lock, flags); | 512 | spin_unlock_irqrestore(&db->lock, flags); |
@@ -510,6 +517,7 @@ static void __debug_check_no_obj_freed(const void *address, unsigned long size) | |||
510 | { | 517 | { |
511 | unsigned long flags, oaddr, saddr, eaddr, paddr, chunks; | 518 | unsigned long flags, oaddr, saddr, eaddr, paddr, chunks; |
512 | struct hlist_node *node, *tmp; | 519 | struct hlist_node *node, *tmp; |
520 | HLIST_HEAD(freelist); | ||
513 | struct debug_obj_descr *descr; | 521 | struct debug_obj_descr *descr; |
514 | enum debug_obj_state state; | 522 | enum debug_obj_state state; |
515 | struct debug_bucket *db; | 523 | struct debug_bucket *db; |
@@ -545,11 +553,18 @@ repeat: | |||
545 | goto repeat; | 553 | goto repeat; |
546 | default: | 554 | default: |
547 | hlist_del(&obj->node); | 555 | hlist_del(&obj->node); |
548 | free_object(obj); | 556 | hlist_add_head(&obj->node, &freelist); |
549 | break; | 557 | break; |
550 | } | 558 | } |
551 | } | 559 | } |
552 | spin_unlock_irqrestore(&db->lock, flags); | 560 | spin_unlock_irqrestore(&db->lock, flags); |
561 | |||
562 | /* Now free them */ | ||
563 | hlist_for_each_entry_safe(obj, node, tmp, &freelist, node) { | ||
564 | hlist_del(&obj->node); | ||
565 | free_object(obj); | ||
566 | } | ||
567 | |||
553 | if (cnt > debug_objects_maxchain) | 568 | if (cnt > debug_objects_maxchain) |
554 | debug_objects_maxchain = cnt; | 569 | debug_objects_maxchain = cnt; |
555 | } | 570 | } |
diff --git a/lib/dynamic_printk.c b/lib/dynamic_printk.c new file mode 100644 index 000000000000..d640f87bdc9e --- /dev/null +++ b/lib/dynamic_printk.c | |||
@@ -0,0 +1,418 @@ | |||
1 | /* | ||
2 | * lib/dynamic_printk.c | ||
3 | * | ||
4 | * make pr_debug()/dev_dbg() calls runtime configurable based upon their | ||
5 | * their source module. | ||
6 | * | ||
7 | * Copyright (C) 2008 Red Hat, Inc., Jason Baron <jbaron@redhat.com> | ||
8 | */ | ||
9 | |||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/uaccess.h> | ||
13 | #include <linux/seq_file.h> | ||
14 | #include <linux/debugfs.h> | ||
15 | #include <linux/fs.h> | ||
16 | |||
17 | extern struct mod_debug __start___verbose[]; | ||
18 | extern struct mod_debug __stop___verbose[]; | ||
19 | |||
20 | struct debug_name { | ||
21 | struct hlist_node hlist; | ||
22 | struct hlist_node hlist2; | ||
23 | int hash1; | ||
24 | int hash2; | ||
25 | char *name; | ||
26 | int enable; | ||
27 | int type; | ||
28 | }; | ||
29 | |||
30 | static int nr_entries; | ||
31 | static int num_enabled; | ||
32 | int dynamic_enabled = DYNAMIC_ENABLED_NONE; | ||
33 | static struct hlist_head module_table[DEBUG_HASH_TABLE_SIZE] = | ||
34 | { [0 ... DEBUG_HASH_TABLE_SIZE-1] = HLIST_HEAD_INIT }; | ||
35 | static struct hlist_head module_table2[DEBUG_HASH_TABLE_SIZE] = | ||
36 | { [0 ... DEBUG_HASH_TABLE_SIZE-1] = HLIST_HEAD_INIT }; | ||
37 | static DECLARE_MUTEX(debug_list_mutex); | ||
38 | |||
39 | /* dynamic_printk_enabled, and dynamic_printk_enabled2 are bitmasks in which | ||
40 | * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They | ||
41 | * use independent hash functions, to reduce the chance of false positives. | ||
42 | */ | ||
43 | long long dynamic_printk_enabled; | ||
44 | EXPORT_SYMBOL_GPL(dynamic_printk_enabled); | ||
45 | long long dynamic_printk_enabled2; | ||
46 | EXPORT_SYMBOL_GPL(dynamic_printk_enabled2); | ||
47 | |||
48 | /* returns the debug module pointer. */ | ||
49 | static struct debug_name *find_debug_module(char *module_name) | ||
50 | { | ||
51 | int i; | ||
52 | struct hlist_head *head; | ||
53 | struct hlist_node *node; | ||
54 | struct debug_name *element; | ||
55 | |||
56 | element = NULL; | ||
57 | for (i = 0; i < DEBUG_HASH_TABLE_SIZE; i++) { | ||
58 | head = &module_table[i]; | ||
59 | hlist_for_each_entry_rcu(element, node, head, hlist) | ||
60 | if (!strcmp(element->name, module_name)) | ||
61 | return element; | ||
62 | } | ||
63 | return NULL; | ||
64 | } | ||
65 | |||
66 | /* returns the debug module pointer. */ | ||
67 | static struct debug_name *find_debug_module_hash(char *module_name, int hash) | ||
68 | { | ||
69 | struct hlist_head *head; | ||
70 | struct hlist_node *node; | ||
71 | struct debug_name *element; | ||
72 | |||
73 | element = NULL; | ||
74 | head = &module_table[hash]; | ||
75 | hlist_for_each_entry_rcu(element, node, head, hlist) | ||
76 | if (!strcmp(element->name, module_name)) | ||
77 | return element; | ||
78 | return NULL; | ||
79 | } | ||
80 | |||
81 | /* caller must hold mutex*/ | ||
82 | static int __add_debug_module(char *mod_name, int hash, int hash2) | ||
83 | { | ||
84 | struct debug_name *new; | ||
85 | char *module_name; | ||
86 | int ret = 0; | ||
87 | |||
88 | if (find_debug_module(mod_name)) { | ||
89 | ret = -EINVAL; | ||
90 | goto out; | ||
91 | } | ||
92 | module_name = kmalloc(strlen(mod_name) + 1, GFP_KERNEL); | ||
93 | if (!module_name) { | ||
94 | ret = -ENOMEM; | ||
95 | goto out; | ||
96 | } | ||
97 | module_name = strcpy(module_name, mod_name); | ||
98 | module_name[strlen(mod_name)] = '\0'; | ||
99 | new = kzalloc(sizeof(struct debug_name), GFP_KERNEL); | ||
100 | if (!new) { | ||
101 | kfree(module_name); | ||
102 | ret = -ENOMEM; | ||
103 | goto out; | ||
104 | } | ||
105 | INIT_HLIST_NODE(&new->hlist); | ||
106 | INIT_HLIST_NODE(&new->hlist2); | ||
107 | new->name = module_name; | ||
108 | new->hash1 = hash; | ||
109 | new->hash2 = hash2; | ||
110 | hlist_add_head_rcu(&new->hlist, &module_table[hash]); | ||
111 | hlist_add_head_rcu(&new->hlist2, &module_table2[hash2]); | ||
112 | nr_entries++; | ||
113 | out: | ||
114 | return ret; | ||
115 | } | ||
116 | |||
117 | int unregister_dynamic_debug_module(char *mod_name) | ||
118 | { | ||
119 | struct debug_name *element; | ||
120 | int ret = 0; | ||
121 | |||
122 | down(&debug_list_mutex); | ||
123 | element = find_debug_module(mod_name); | ||
124 | if (!element) { | ||
125 | ret = -EINVAL; | ||
126 | goto out; | ||
127 | } | ||
128 | hlist_del_rcu(&element->hlist); | ||
129 | hlist_del_rcu(&element->hlist2); | ||
130 | synchronize_rcu(); | ||
131 | kfree(element->name); | ||
132 | if (element->enable) | ||
133 | num_enabled--; | ||
134 | kfree(element); | ||
135 | nr_entries--; | ||
136 | out: | ||
137 | up(&debug_list_mutex); | ||
138 | return 0; | ||
139 | } | ||
140 | EXPORT_SYMBOL_GPL(unregister_dynamic_debug_module); | ||
141 | |||
142 | int register_dynamic_debug_module(char *mod_name, int type, char *share_name, | ||
143 | char *flags, int hash, int hash2) | ||
144 | { | ||
145 | struct debug_name *elem; | ||
146 | int ret = 0; | ||
147 | |||
148 | down(&debug_list_mutex); | ||
149 | elem = find_debug_module(mod_name); | ||
150 | if (!elem) { | ||
151 | if (__add_debug_module(mod_name, hash, hash2)) | ||
152 | goto out; | ||
153 | elem = find_debug_module(mod_name); | ||
154 | if (dynamic_enabled == DYNAMIC_ENABLED_ALL && | ||
155 | !strcmp(mod_name, share_name)) { | ||
156 | elem->enable = true; | ||
157 | num_enabled++; | ||
158 | } | ||
159 | } | ||
160 | elem->type |= type; | ||
161 | out: | ||
162 | up(&debug_list_mutex); | ||
163 | return ret; | ||
164 | } | ||
165 | EXPORT_SYMBOL_GPL(register_dynamic_debug_module); | ||
166 | |||
167 | int __dynamic_dbg_enabled_helper(char *mod_name, int type, int value, int hash) | ||
168 | { | ||
169 | struct debug_name *elem; | ||
170 | int ret = 0; | ||
171 | |||
172 | if (dynamic_enabled == DYNAMIC_ENABLED_ALL) | ||
173 | return 1; | ||
174 | rcu_read_lock(); | ||
175 | elem = find_debug_module_hash(mod_name, hash); | ||
176 | if (elem && elem->enable) | ||
177 | ret = 1; | ||
178 | rcu_read_unlock(); | ||
179 | return ret; | ||
180 | } | ||
181 | EXPORT_SYMBOL_GPL(__dynamic_dbg_enabled_helper); | ||
182 | |||
183 | static void set_all(bool enable) | ||
184 | { | ||
185 | struct debug_name *e; | ||
186 | struct hlist_node *node; | ||
187 | int i; | ||
188 | long long enable_mask; | ||
189 | |||
190 | for (i = 0; i < DEBUG_HASH_TABLE_SIZE; i++) { | ||
191 | if (module_table[i].first != NULL) { | ||
192 | hlist_for_each_entry(e, node, &module_table[i], hlist) { | ||
193 | e->enable = enable; | ||
194 | } | ||
195 | } | ||
196 | } | ||
197 | if (enable) | ||
198 | enable_mask = ULLONG_MAX; | ||
199 | else | ||
200 | enable_mask = 0; | ||
201 | dynamic_printk_enabled = enable_mask; | ||
202 | dynamic_printk_enabled2 = enable_mask; | ||
203 | } | ||
204 | |||
205 | static int disabled_hash(int i, bool first_table) | ||
206 | { | ||
207 | struct debug_name *e; | ||
208 | struct hlist_node *node; | ||
209 | |||
210 | if (first_table) { | ||
211 | hlist_for_each_entry(e, node, &module_table[i], hlist) { | ||
212 | if (e->enable) | ||
213 | return 0; | ||
214 | } | ||
215 | } else { | ||
216 | hlist_for_each_entry(e, node, &module_table2[i], hlist2) { | ||
217 | if (e->enable) | ||
218 | return 0; | ||
219 | } | ||
220 | } | ||
221 | return 1; | ||
222 | } | ||
223 | |||
224 | static ssize_t pr_debug_write(struct file *file, const char __user *buf, | ||
225 | size_t length, loff_t *ppos) | ||
226 | { | ||
227 | char *buffer, *s, *value_str, *setting_str; | ||
228 | int err, value; | ||
229 | struct debug_name *elem = NULL; | ||
230 | int all = 0; | ||
231 | |||
232 | if (length > PAGE_SIZE || length < 0) | ||
233 | return -EINVAL; | ||
234 | |||
235 | buffer = (char *)__get_free_page(GFP_KERNEL); | ||
236 | if (!buffer) | ||
237 | return -ENOMEM; | ||
238 | |||
239 | err = -EFAULT; | ||
240 | if (copy_from_user(buffer, buf, length)) | ||
241 | goto out; | ||
242 | |||
243 | err = -EINVAL; | ||
244 | if (length < PAGE_SIZE) | ||
245 | buffer[length] = '\0'; | ||
246 | else if (buffer[PAGE_SIZE-1]) | ||
247 | goto out; | ||
248 | |||
249 | err = -EINVAL; | ||
250 | down(&debug_list_mutex); | ||
251 | |||
252 | if (strncmp("set", buffer, 3)) | ||
253 | goto out_up; | ||
254 | s = buffer + 3; | ||
255 | setting_str = strsep(&s, "="); | ||
256 | if (s == NULL) | ||
257 | goto out_up; | ||
258 | setting_str = strstrip(setting_str); | ||
259 | value_str = strsep(&s, " "); | ||
260 | if (s == NULL) | ||
261 | goto out_up; | ||
262 | s = strstrip(s); | ||
263 | if (!strncmp(s, "all", 3)) | ||
264 | all = 1; | ||
265 | else | ||
266 | elem = find_debug_module(s); | ||
267 | if (!strncmp(setting_str, "enable", 6)) { | ||
268 | value = !!simple_strtol(value_str, NULL, 10); | ||
269 | if (all) { | ||
270 | if (value) { | ||
271 | set_all(true); | ||
272 | num_enabled = nr_entries; | ||
273 | dynamic_enabled = DYNAMIC_ENABLED_ALL; | ||
274 | } else { | ||
275 | set_all(false); | ||
276 | num_enabled = 0; | ||
277 | dynamic_enabled = DYNAMIC_ENABLED_NONE; | ||
278 | } | ||
279 | err = 0; | ||
280 | } else { | ||
281 | if (elem) { | ||
282 | if (value && (elem->enable == 0)) { | ||
283 | dynamic_printk_enabled |= | ||
284 | (1LL << elem->hash1); | ||
285 | dynamic_printk_enabled2 |= | ||
286 | (1LL << elem->hash2); | ||
287 | elem->enable = 1; | ||
288 | num_enabled++; | ||
289 | dynamic_enabled = DYNAMIC_ENABLED_SOME; | ||
290 | err = 0; | ||
291 | printk(KERN_DEBUG | ||
292 | "debugging enabled for module %s", | ||
293 | elem->name); | ||
294 | } else if (!value && (elem->enable == 1)) { | ||
295 | elem->enable = 0; | ||
296 | num_enabled--; | ||
297 | if (disabled_hash(elem->hash1, true)) | ||
298 | dynamic_printk_enabled &= | ||
299 | ~(1LL << elem->hash1); | ||
300 | if (disabled_hash(elem->hash2, false)) | ||
301 | dynamic_printk_enabled2 &= | ||
302 | ~(1LL << elem->hash2); | ||
303 | if (num_enabled) | ||
304 | dynamic_enabled = | ||
305 | DYNAMIC_ENABLED_SOME; | ||
306 | else | ||
307 | dynamic_enabled = | ||
308 | DYNAMIC_ENABLED_NONE; | ||
309 | err = 0; | ||
310 | printk(KERN_DEBUG | ||
311 | "debugging disabled for module " | ||
312 | "%s", elem->name); | ||
313 | } | ||
314 | } | ||
315 | } | ||
316 | } | ||
317 | if (!err) | ||
318 | err = length; | ||
319 | out_up: | ||
320 | up(&debug_list_mutex); | ||
321 | out: | ||
322 | free_page((unsigned long)buffer); | ||
323 | return err; | ||
324 | } | ||
325 | |||
326 | static void *pr_debug_seq_start(struct seq_file *f, loff_t *pos) | ||
327 | { | ||
328 | return (*pos < DEBUG_HASH_TABLE_SIZE) ? pos : NULL; | ||
329 | } | ||
330 | |||
331 | static void *pr_debug_seq_next(struct seq_file *s, void *v, loff_t *pos) | ||
332 | { | ||
333 | (*pos)++; | ||
334 | if (*pos >= DEBUG_HASH_TABLE_SIZE) | ||
335 | return NULL; | ||
336 | return pos; | ||
337 | } | ||
338 | |||
339 | static void pr_debug_seq_stop(struct seq_file *s, void *v) | ||
340 | { | ||
341 | /* Nothing to do */ | ||
342 | } | ||
343 | |||
344 | static int pr_debug_seq_show(struct seq_file *s, void *v) | ||
345 | { | ||
346 | struct hlist_head *head; | ||
347 | struct hlist_node *node; | ||
348 | struct debug_name *elem; | ||
349 | unsigned int i = *(loff_t *) v; | ||
350 | |||
351 | rcu_read_lock(); | ||
352 | head = &module_table[i]; | ||
353 | hlist_for_each_entry_rcu(elem, node, head, hlist) { | ||
354 | seq_printf(s, "%s enabled=%d", elem->name, elem->enable); | ||
355 | seq_printf(s, "\n"); | ||
356 | } | ||
357 | rcu_read_unlock(); | ||
358 | return 0; | ||
359 | } | ||
360 | |||
361 | static struct seq_operations pr_debug_seq_ops = { | ||
362 | .start = pr_debug_seq_start, | ||
363 | .next = pr_debug_seq_next, | ||
364 | .stop = pr_debug_seq_stop, | ||
365 | .show = pr_debug_seq_show | ||
366 | }; | ||
367 | |||
368 | static int pr_debug_open(struct inode *inode, struct file *filp) | ||
369 | { | ||
370 | return seq_open(filp, &pr_debug_seq_ops); | ||
371 | } | ||
372 | |||
373 | static const struct file_operations pr_debug_operations = { | ||
374 | .open = pr_debug_open, | ||
375 | .read = seq_read, | ||
376 | .write = pr_debug_write, | ||
377 | .llseek = seq_lseek, | ||
378 | .release = seq_release, | ||
379 | }; | ||
380 | |||
381 | static int __init dynamic_printk_init(void) | ||
382 | { | ||
383 | struct dentry *dir, *file; | ||
384 | struct mod_debug *iter; | ||
385 | unsigned long value; | ||
386 | |||
387 | dir = debugfs_create_dir("dynamic_printk", NULL); | ||
388 | if (!dir) | ||
389 | return -ENOMEM; | ||
390 | file = debugfs_create_file("modules", 0644, dir, NULL, | ||
391 | &pr_debug_operations); | ||
392 | if (!file) { | ||
393 | debugfs_remove(dir); | ||
394 | return -ENOMEM; | ||
395 | } | ||
396 | for (value = (unsigned long)__start___verbose; | ||
397 | value < (unsigned long)__stop___verbose; | ||
398 | value += sizeof(struct mod_debug)) { | ||
399 | iter = (struct mod_debug *)value; | ||
400 | register_dynamic_debug_module(iter->modname, | ||
401 | iter->type, | ||
402 | iter->logical_modname, | ||
403 | iter->flag_names, iter->hash, iter->hash2); | ||
404 | } | ||
405 | return 0; | ||
406 | } | ||
407 | module_init(dynamic_printk_init); | ||
408 | /* may want to move this earlier so we can get traces as early as possible */ | ||
409 | |||
410 | static int __init dynamic_printk_setup(char *str) | ||
411 | { | ||
412 | if (str) | ||
413 | return -ENOENT; | ||
414 | set_all(true); | ||
415 | return 0; | ||
416 | } | ||
417 | /* Use early_param(), so we can get debug output as early as possible */ | ||
418 | early_param("dynamic_printk", dynamic_printk_setup); | ||
diff --git a/lib/iommu-helper.c b/lib/iommu-helper.c index a3b8d4c3f77a..75dbda03f4fb 100644 --- a/lib/iommu-helper.c +++ b/lib/iommu-helper.c | |||
@@ -30,8 +30,7 @@ again: | |||
30 | return index; | 30 | return index; |
31 | } | 31 | } |
32 | 32 | ||
33 | static inline void set_bit_area(unsigned long *map, unsigned long i, | 33 | void iommu_area_reserve(unsigned long *map, unsigned long i, int len) |
34 | int len) | ||
35 | { | 34 | { |
36 | unsigned long end = i + len; | 35 | unsigned long end = i + len; |
37 | while (i < end) { | 36 | while (i < end) { |
@@ -64,7 +63,7 @@ again: | |||
64 | start = index + 1; | 63 | start = index + 1; |
65 | goto again; | 64 | goto again; |
66 | } | 65 | } |
67 | set_bit_area(map, index, nr); | 66 | iommu_area_reserve(map, index, nr); |
68 | } | 67 | } |
69 | return index; | 68 | return index; |
70 | } | 69 | } |
@@ -80,3 +79,12 @@ void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr) | |||
80 | } | 79 | } |
81 | } | 80 | } |
82 | EXPORT_SYMBOL(iommu_area_free); | 81 | EXPORT_SYMBOL(iommu_area_free); |
82 | |||
83 | unsigned long iommu_num_pages(unsigned long addr, unsigned long len, | ||
84 | unsigned long io_page_size) | ||
85 | { | ||
86 | unsigned long size = (addr & (io_page_size - 1)) + len; | ||
87 | |||
88 | return DIV_ROUND_UP(size, io_page_size); | ||
89 | } | ||
90 | EXPORT_SYMBOL(iommu_num_pages); | ||
diff --git a/lib/klist.c b/lib/klist.c index cca37f96faa2..bbdd3015c2c7 100644 --- a/lib/klist.c +++ b/lib/klist.c | |||
@@ -37,6 +37,37 @@ | |||
37 | #include <linux/klist.h> | 37 | #include <linux/klist.h> |
38 | #include <linux/module.h> | 38 | #include <linux/module.h> |
39 | 39 | ||
40 | /* | ||
41 | * Use the lowest bit of n_klist to mark deleted nodes and exclude | ||
42 | * dead ones from iteration. | ||
43 | */ | ||
44 | #define KNODE_DEAD 1LU | ||
45 | #define KNODE_KLIST_MASK ~KNODE_DEAD | ||
46 | |||
47 | static struct klist *knode_klist(struct klist_node *knode) | ||
48 | { | ||
49 | return (struct klist *) | ||
50 | ((unsigned long)knode->n_klist & KNODE_KLIST_MASK); | ||
51 | } | ||
52 | |||
53 | static bool knode_dead(struct klist_node *knode) | ||
54 | { | ||
55 | return (unsigned long)knode->n_klist & KNODE_DEAD; | ||
56 | } | ||
57 | |||
58 | static void knode_set_klist(struct klist_node *knode, struct klist *klist) | ||
59 | { | ||
60 | knode->n_klist = klist; | ||
61 | /* no knode deserves to start its life dead */ | ||
62 | WARN_ON(knode_dead(knode)); | ||
63 | } | ||
64 | |||
65 | static void knode_kill(struct klist_node *knode) | ||
66 | { | ||
67 | /* and no knode should die twice ever either, see we're very humane */ | ||
68 | WARN_ON(knode_dead(knode)); | ||
69 | *(unsigned long *)&knode->n_klist |= KNODE_DEAD; | ||
70 | } | ||
40 | 71 | ||
41 | /** | 72 | /** |
42 | * klist_init - Initialize a klist structure. | 73 | * klist_init - Initialize a klist structure. |
@@ -79,7 +110,7 @@ static void klist_node_init(struct klist *k, struct klist_node *n) | |||
79 | INIT_LIST_HEAD(&n->n_node); | 110 | INIT_LIST_HEAD(&n->n_node); |
80 | init_completion(&n->n_removed); | 111 | init_completion(&n->n_removed); |
81 | kref_init(&n->n_ref); | 112 | kref_init(&n->n_ref); |
82 | n->n_klist = k; | 113 | knode_set_klist(n, k); |
83 | if (k->get) | 114 | if (k->get) |
84 | k->get(n); | 115 | k->get(n); |
85 | } | 116 | } |
@@ -115,7 +146,7 @@ EXPORT_SYMBOL_GPL(klist_add_tail); | |||
115 | */ | 146 | */ |
116 | void klist_add_after(struct klist_node *n, struct klist_node *pos) | 147 | void klist_add_after(struct klist_node *n, struct klist_node *pos) |
117 | { | 148 | { |
118 | struct klist *k = pos->n_klist; | 149 | struct klist *k = knode_klist(pos); |
119 | 150 | ||
120 | klist_node_init(k, n); | 151 | klist_node_init(k, n); |
121 | spin_lock(&k->k_lock); | 152 | spin_lock(&k->k_lock); |
@@ -131,7 +162,7 @@ EXPORT_SYMBOL_GPL(klist_add_after); | |||
131 | */ | 162 | */ |
132 | void klist_add_before(struct klist_node *n, struct klist_node *pos) | 163 | void klist_add_before(struct klist_node *n, struct klist_node *pos) |
133 | { | 164 | { |
134 | struct klist *k = pos->n_klist; | 165 | struct klist *k = knode_klist(pos); |
135 | 166 | ||
136 | klist_node_init(k, n); | 167 | klist_node_init(k, n); |
137 | spin_lock(&k->k_lock); | 168 | spin_lock(&k->k_lock); |
@@ -144,9 +175,10 @@ static void klist_release(struct kref *kref) | |||
144 | { | 175 | { |
145 | struct klist_node *n = container_of(kref, struct klist_node, n_ref); | 176 | struct klist_node *n = container_of(kref, struct klist_node, n_ref); |
146 | 177 | ||
178 | WARN_ON(!knode_dead(n)); | ||
147 | list_del(&n->n_node); | 179 | list_del(&n->n_node); |
148 | complete(&n->n_removed); | 180 | complete(&n->n_removed); |
149 | n->n_klist = NULL; | 181 | knode_set_klist(n, NULL); |
150 | } | 182 | } |
151 | 183 | ||
152 | static int klist_dec_and_del(struct klist_node *n) | 184 | static int klist_dec_and_del(struct klist_node *n) |
@@ -154,22 +186,29 @@ static int klist_dec_and_del(struct klist_node *n) | |||
154 | return kref_put(&n->n_ref, klist_release); | 186 | return kref_put(&n->n_ref, klist_release); |
155 | } | 187 | } |
156 | 188 | ||
157 | /** | 189 | static void klist_put(struct klist_node *n, bool kill) |
158 | * klist_del - Decrement the reference count of node and try to remove. | ||
159 | * @n: node we're deleting. | ||
160 | */ | ||
161 | void klist_del(struct klist_node *n) | ||
162 | { | 190 | { |
163 | struct klist *k = n->n_klist; | 191 | struct klist *k = knode_klist(n); |
164 | void (*put)(struct klist_node *) = k->put; | 192 | void (*put)(struct klist_node *) = k->put; |
165 | 193 | ||
166 | spin_lock(&k->k_lock); | 194 | spin_lock(&k->k_lock); |
195 | if (kill) | ||
196 | knode_kill(n); | ||
167 | if (!klist_dec_and_del(n)) | 197 | if (!klist_dec_and_del(n)) |
168 | put = NULL; | 198 | put = NULL; |
169 | spin_unlock(&k->k_lock); | 199 | spin_unlock(&k->k_lock); |
170 | if (put) | 200 | if (put) |
171 | put(n); | 201 | put(n); |
172 | } | 202 | } |
203 | |||
204 | /** | ||
205 | * klist_del - Decrement the reference count of node and try to remove. | ||
206 | * @n: node we're deleting. | ||
207 | */ | ||
208 | void klist_del(struct klist_node *n) | ||
209 | { | ||
210 | klist_put(n, true); | ||
211 | } | ||
173 | EXPORT_SYMBOL_GPL(klist_del); | 212 | EXPORT_SYMBOL_GPL(klist_del); |
174 | 213 | ||
175 | /** | 214 | /** |
@@ -206,7 +245,6 @@ void klist_iter_init_node(struct klist *k, struct klist_iter *i, | |||
206 | struct klist_node *n) | 245 | struct klist_node *n) |
207 | { | 246 | { |
208 | i->i_klist = k; | 247 | i->i_klist = k; |
209 | i->i_head = &k->k_list; | ||
210 | i->i_cur = n; | 248 | i->i_cur = n; |
211 | if (n) | 249 | if (n) |
212 | kref_get(&n->n_ref); | 250 | kref_get(&n->n_ref); |
@@ -237,7 +275,7 @@ EXPORT_SYMBOL_GPL(klist_iter_init); | |||
237 | void klist_iter_exit(struct klist_iter *i) | 275 | void klist_iter_exit(struct klist_iter *i) |
238 | { | 276 | { |
239 | if (i->i_cur) { | 277 | if (i->i_cur) { |
240 | klist_del(i->i_cur); | 278 | klist_put(i->i_cur, false); |
241 | i->i_cur = NULL; | 279 | i->i_cur = NULL; |
242 | } | 280 | } |
243 | } | 281 | } |
@@ -258,27 +296,33 @@ static struct klist_node *to_klist_node(struct list_head *n) | |||
258 | */ | 296 | */ |
259 | struct klist_node *klist_next(struct klist_iter *i) | 297 | struct klist_node *klist_next(struct klist_iter *i) |
260 | { | 298 | { |
261 | struct list_head *next; | ||
262 | struct klist_node *lnode = i->i_cur; | ||
263 | struct klist_node *knode = NULL; | ||
264 | void (*put)(struct klist_node *) = i->i_klist->put; | 299 | void (*put)(struct klist_node *) = i->i_klist->put; |
300 | struct klist_node *last = i->i_cur; | ||
301 | struct klist_node *next; | ||
265 | 302 | ||
266 | spin_lock(&i->i_klist->k_lock); | 303 | spin_lock(&i->i_klist->k_lock); |
267 | if (lnode) { | 304 | |
268 | next = lnode->n_node.next; | 305 | if (last) { |
269 | if (!klist_dec_and_del(lnode)) | 306 | next = to_klist_node(last->n_node.next); |
307 | if (!klist_dec_and_del(last)) | ||
270 | put = NULL; | 308 | put = NULL; |
271 | } else | 309 | } else |
272 | next = i->i_head->next; | 310 | next = to_klist_node(i->i_klist->k_list.next); |
273 | 311 | ||
274 | if (next != i->i_head) { | 312 | i->i_cur = NULL; |
275 | knode = to_klist_node(next); | 313 | while (next != to_klist_node(&i->i_klist->k_list)) { |
276 | kref_get(&knode->n_ref); | 314 | if (likely(!knode_dead(next))) { |
315 | kref_get(&next->n_ref); | ||
316 | i->i_cur = next; | ||
317 | break; | ||
318 | } | ||
319 | next = to_klist_node(next->n_node.next); | ||
277 | } | 320 | } |
278 | i->i_cur = knode; | 321 | |
279 | spin_unlock(&i->i_klist->k_lock); | 322 | spin_unlock(&i->i_klist->k_lock); |
280 | if (put && lnode) | 323 | |
281 | put(lnode); | 324 | if (put && last) |
282 | return knode; | 325 | put(last); |
326 | return i->i_cur; | ||
283 | } | 327 | } |
284 | EXPORT_SYMBOL_GPL(klist_next); | 328 | EXPORT_SYMBOL_GPL(klist_next); |
diff --git a/lib/kobject.c b/lib/kobject.c index bd732ffebc85..0487d1f64806 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
@@ -223,8 +223,7 @@ static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, | |||
223 | return -ENOMEM; | 223 | return -ENOMEM; |
224 | 224 | ||
225 | /* ewww... some of these buggers have '/' in the name ... */ | 225 | /* ewww... some of these buggers have '/' in the name ... */ |
226 | s = strchr(kobj->name, '/'); | 226 | while ((s = strchr(kobj->name, '/'))) |
227 | if (s) | ||
228 | s[0] = '!'; | 227 | s[0] = '!'; |
229 | 228 | ||
230 | kfree(old_name); | 229 | kfree(old_name); |
@@ -388,11 +387,17 @@ EXPORT_SYMBOL_GPL(kobject_init_and_add); | |||
388 | * kobject_rename - change the name of an object | 387 | * kobject_rename - change the name of an object |
389 | * @kobj: object in question. | 388 | * @kobj: object in question. |
390 | * @new_name: object's new name | 389 | * @new_name: object's new name |
390 | * | ||
391 | * It is the responsibility of the caller to provide mutual | ||
392 | * exclusion between two different calls of kobject_rename | ||
393 | * on the same kobject and to ensure that new_name is valid and | ||
394 | * won't conflict with other kobjects. | ||
391 | */ | 395 | */ |
392 | int kobject_rename(struct kobject *kobj, const char *new_name) | 396 | int kobject_rename(struct kobject *kobj, const char *new_name) |
393 | { | 397 | { |
394 | int error = 0; | 398 | int error = 0; |
395 | const char *devpath = NULL; | 399 | const char *devpath = NULL; |
400 | const char *dup_name = NULL, *name; | ||
396 | char *devpath_string = NULL; | 401 | char *devpath_string = NULL; |
397 | char *envp[2]; | 402 | char *envp[2]; |
398 | 403 | ||
@@ -402,19 +407,6 @@ int kobject_rename(struct kobject *kobj, const char *new_name) | |||
402 | if (!kobj->parent) | 407 | if (!kobj->parent) |
403 | return -EINVAL; | 408 | return -EINVAL; |
404 | 409 | ||
405 | /* see if this name is already in use */ | ||
406 | if (kobj->kset) { | ||
407 | struct kobject *temp_kobj; | ||
408 | temp_kobj = kset_find_obj(kobj->kset, new_name); | ||
409 | if (temp_kobj) { | ||
410 | printk(KERN_WARNING "kobject '%s' cannot be renamed " | ||
411 | "to '%s' as '%s' is already in existence.\n", | ||
412 | kobject_name(kobj), new_name, new_name); | ||
413 | kobject_put(temp_kobj); | ||
414 | return -EINVAL; | ||
415 | } | ||
416 | } | ||
417 | |||
418 | devpath = kobject_get_path(kobj, GFP_KERNEL); | 410 | devpath = kobject_get_path(kobj, GFP_KERNEL); |
419 | if (!devpath) { | 411 | if (!devpath) { |
420 | error = -ENOMEM; | 412 | error = -ENOMEM; |
@@ -429,15 +421,27 @@ int kobject_rename(struct kobject *kobj, const char *new_name) | |||
429 | envp[0] = devpath_string; | 421 | envp[0] = devpath_string; |
430 | envp[1] = NULL; | 422 | envp[1] = NULL; |
431 | 423 | ||
424 | name = dup_name = kstrdup(new_name, GFP_KERNEL); | ||
425 | if (!name) { | ||
426 | error = -ENOMEM; | ||
427 | goto out; | ||
428 | } | ||
429 | |||
432 | error = sysfs_rename_dir(kobj, new_name); | 430 | error = sysfs_rename_dir(kobj, new_name); |
431 | if (error) | ||
432 | goto out; | ||
433 | |||
434 | /* Install the new kobject name */ | ||
435 | dup_name = kobj->name; | ||
436 | kobj->name = name; | ||
433 | 437 | ||
434 | /* This function is mostly/only used for network interface. | 438 | /* This function is mostly/only used for network interface. |
435 | * Some hotplug package track interfaces by their name and | 439 | * Some hotplug package track interfaces by their name and |
436 | * therefore want to know when the name is changed by the user. */ | 440 | * therefore want to know when the name is changed by the user. */ |
437 | if (!error) | 441 | kobject_uevent_env(kobj, KOBJ_MOVE, envp); |
438 | kobject_uevent_env(kobj, KOBJ_MOVE, envp); | ||
439 | 442 | ||
440 | out: | 443 | out: |
444 | kfree(dup_name); | ||
441 | kfree(devpath_string); | 445 | kfree(devpath_string); |
442 | kfree(devpath); | 446 | kfree(devpath); |
443 | kobject_put(kobj); | 447 | kobject_put(kobj); |
diff --git a/lib/parser.c b/lib/parser.c index 4f0cbc03e0e8..b00d02059a5f 100644 --- a/lib/parser.c +++ b/lib/parser.c | |||
@@ -100,7 +100,7 @@ static int match_one(char *s, const char *p, substring_t args[]) | |||
100 | * format identifiers which will be taken into account when matching the | 100 | * format identifiers which will be taken into account when matching the |
101 | * tokens, and whose locations will be returned in the @args array. | 101 | * tokens, and whose locations will be returned in the @args array. |
102 | */ | 102 | */ |
103 | int match_token(char *s, match_table_t table, substring_t args[]) | 103 | int match_token(char *s, const match_table_t table, substring_t args[]) |
104 | { | 104 | { |
105 | const struct match_token *p; | 105 | const struct match_token *p; |
106 | 106 | ||
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c index 4a8ba4bf5f6f..a8663890a88c 100644 --- a/lib/percpu_counter.c +++ b/lib/percpu_counter.c | |||
@@ -52,7 +52,7 @@ EXPORT_SYMBOL(__percpu_counter_add); | |||
52 | * Add up all the per-cpu counts, return the result. This is a more accurate | 52 | * Add up all the per-cpu counts, return the result. This is a more accurate |
53 | * but much slower version of percpu_counter_read_positive() | 53 | * but much slower version of percpu_counter_read_positive() |
54 | */ | 54 | */ |
55 | s64 __percpu_counter_sum(struct percpu_counter *fbc, int set) | 55 | s64 __percpu_counter_sum(struct percpu_counter *fbc) |
56 | { | 56 | { |
57 | s64 ret; | 57 | s64 ret; |
58 | int cpu; | 58 | int cpu; |
@@ -62,11 +62,9 @@ s64 __percpu_counter_sum(struct percpu_counter *fbc, int set) | |||
62 | for_each_online_cpu(cpu) { | 62 | for_each_online_cpu(cpu) { |
63 | s32 *pcount = per_cpu_ptr(fbc->counters, cpu); | 63 | s32 *pcount = per_cpu_ptr(fbc->counters, cpu); |
64 | ret += *pcount; | 64 | ret += *pcount; |
65 | if (set) | 65 | *pcount = 0; |
66 | *pcount = 0; | ||
67 | } | 66 | } |
68 | if (set) | 67 | fbc->count = ret; |
69 | fbc->count = ret; | ||
70 | 68 | ||
71 | spin_unlock(&fbc->lock); | 69 | spin_unlock(&fbc->lock); |
72 | return ret; | 70 | return ret; |
diff --git a/lib/scatterlist.c b/lib/scatterlist.c index 876ba6d5b670..8d2688ff1352 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c | |||
@@ -422,9 +422,12 @@ static size_t sg_copy_buffer(struct scatterlist *sgl, unsigned int nents, | |||
422 | { | 422 | { |
423 | unsigned int offset = 0; | 423 | unsigned int offset = 0; |
424 | struct sg_mapping_iter miter; | 424 | struct sg_mapping_iter miter; |
425 | unsigned long flags; | ||
425 | 426 | ||
426 | sg_miter_start(&miter, sgl, nents, SG_MITER_ATOMIC); | 427 | sg_miter_start(&miter, sgl, nents, SG_MITER_ATOMIC); |
427 | 428 | ||
429 | local_irq_save(flags); | ||
430 | |||
428 | while (sg_miter_next(&miter) && offset < buflen) { | 431 | while (sg_miter_next(&miter) && offset < buflen) { |
429 | unsigned int len; | 432 | unsigned int len; |
430 | 433 | ||
@@ -442,6 +445,7 @@ static size_t sg_copy_buffer(struct scatterlist *sgl, unsigned int nents, | |||
442 | 445 | ||
443 | sg_miter_stop(&miter); | 446 | sg_miter_stop(&miter); |
444 | 447 | ||
448 | local_irq_restore(flags); | ||
445 | return offset; | 449 | return offset; |
446 | } | 450 | } |
447 | 451 | ||
diff --git a/lib/string_helpers.c b/lib/string_helpers.c new file mode 100644 index 000000000000..8347925030ff --- /dev/null +++ b/lib/string_helpers.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | * Helpers for formatting and printing strings | ||
3 | * | ||
4 | * Copyright 31 August 2008 James Bottomley | ||
5 | */ | ||
6 | #include <linux/kernel.h> | ||
7 | #include <linux/math64.h> | ||
8 | #include <linux/module.h> | ||
9 | #include <linux/string_helpers.h> | ||
10 | |||
11 | /** | ||
12 | * string_get_size - get the size in the specified units | ||
13 | * @size: The size to be converted | ||
14 | * @units: units to use (powers of 1000 or 1024) | ||
15 | * @buf: buffer to format to | ||
16 | * @len: length of buffer | ||
17 | * | ||
18 | * This function returns a string formatted to 3 significant figures | ||
19 | * giving the size in the required units. Returns 0 on success or | ||
20 | * error on failure. @buf is always zero terminated. | ||
21 | * | ||
22 | */ | ||
23 | int string_get_size(u64 size, const enum string_size_units units, | ||
24 | char *buf, int len) | ||
25 | { | ||
26 | const char *units_10[] = { "B", "KB", "MB", "GB", "TB", "PB", | ||
27 | "EB", "ZB", "YB", NULL}; | ||
28 | const char *units_2[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", | ||
29 | "EiB", "ZiB", "YiB", NULL }; | ||
30 | const char **units_str[] = { | ||
31 | [STRING_UNITS_10] = units_10, | ||
32 | [STRING_UNITS_2] = units_2, | ||
33 | }; | ||
34 | const int divisor[] = { | ||
35 | [STRING_UNITS_10] = 1000, | ||
36 | [STRING_UNITS_2] = 1024, | ||
37 | }; | ||
38 | int i, j; | ||
39 | u64 remainder = 0, sf_cap; | ||
40 | char tmp[8]; | ||
41 | |||
42 | tmp[0] = '\0'; | ||
43 | |||
44 | for (i = 0; size > divisor[units] && units_str[units][i]; i++) | ||
45 | remainder = do_div(size, divisor[units]); | ||
46 | |||
47 | sf_cap = size; | ||
48 | for (j = 0; sf_cap*10 < 1000; j++) | ||
49 | sf_cap *= 10; | ||
50 | |||
51 | if (j) { | ||
52 | remainder *= 1000; | ||
53 | do_div(remainder, divisor[units]); | ||
54 | snprintf(tmp, sizeof(tmp), ".%03lld", | ||
55 | (unsigned long long)remainder); | ||
56 | tmp[j+1] = '\0'; | ||
57 | } | ||
58 | |||
59 | snprintf(buf, len, "%lld%s%s", (unsigned long long)size, | ||
60 | tmp, units_str[units][i]); | ||
61 | |||
62 | return 0; | ||
63 | } | ||
64 | EXPORT_SYMBOL(string_get_size); | ||
diff --git a/lib/swiotlb.c b/lib/swiotlb.c index 977edbdbc1de..f8eebd489149 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c | |||
@@ -274,13 +274,14 @@ cleanup1: | |||
274 | } | 274 | } |
275 | 275 | ||
276 | static int | 276 | static int |
277 | address_needs_mapping(struct device *hwdev, dma_addr_t addr) | 277 | address_needs_mapping(struct device *hwdev, dma_addr_t addr, size_t size) |
278 | { | 278 | { |
279 | dma_addr_t mask = 0xffffffff; | 279 | return !is_buffer_dma_capable(dma_get_mask(hwdev), addr, size); |
280 | /* If the device has a mask, use it, otherwise default to 32 bits */ | 280 | } |
281 | if (hwdev && hwdev->dma_mask) | 281 | |
282 | mask = *hwdev->dma_mask; | 282 | static int is_swiotlb_buffer(char *addr) |
283 | return (addr & ~mask) != 0; | 283 | { |
284 | return addr >= io_tlb_start && addr < io_tlb_end; | ||
284 | } | 285 | } |
285 | 286 | ||
286 | /* | 287 | /* |
@@ -467,15 +468,8 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size, | |||
467 | void *ret; | 468 | void *ret; |
468 | int order = get_order(size); | 469 | int order = get_order(size); |
469 | 470 | ||
470 | /* | ||
471 | * XXX fix me: the DMA API should pass us an explicit DMA mask | ||
472 | * instead, or use ZONE_DMA32 (ia64 overloads ZONE_DMA to be a ~32 | ||
473 | * bit range instead of a 16MB one). | ||
474 | */ | ||
475 | flags |= GFP_DMA; | ||
476 | |||
477 | ret = (void *)__get_free_pages(flags, order); | 471 | ret = (void *)__get_free_pages(flags, order); |
478 | if (ret && address_needs_mapping(hwdev, virt_to_bus(ret))) { | 472 | if (ret && address_needs_mapping(hwdev, virt_to_bus(ret), size)) { |
479 | /* | 473 | /* |
480 | * The allocated memory isn't reachable by the device. | 474 | * The allocated memory isn't reachable by the device. |
481 | * Fall back on swiotlb_map_single(). | 475 | * Fall back on swiotlb_map_single(). |
@@ -490,19 +484,16 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size, | |||
490 | * swiotlb_map_single(), which will grab memory from | 484 | * swiotlb_map_single(), which will grab memory from |
491 | * the lowest available address range. | 485 | * the lowest available address range. |
492 | */ | 486 | */ |
493 | dma_addr_t handle; | 487 | ret = map_single(hwdev, NULL, size, DMA_FROM_DEVICE); |
494 | handle = swiotlb_map_single(NULL, NULL, size, DMA_FROM_DEVICE); | 488 | if (!ret) |
495 | if (swiotlb_dma_mapping_error(hwdev, handle)) | ||
496 | return NULL; | 489 | return NULL; |
497 | |||
498 | ret = bus_to_virt(handle); | ||
499 | } | 490 | } |
500 | 491 | ||
501 | memset(ret, 0, size); | 492 | memset(ret, 0, size); |
502 | dev_addr = virt_to_bus(ret); | 493 | dev_addr = virt_to_bus(ret); |
503 | 494 | ||
504 | /* Confirm address can be DMA'd by device */ | 495 | /* Confirm address can be DMA'd by device */ |
505 | if (address_needs_mapping(hwdev, dev_addr)) { | 496 | if (address_needs_mapping(hwdev, dev_addr, size)) { |
506 | printk("hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n", | 497 | printk("hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n", |
507 | (unsigned long long)*hwdev->dma_mask, | 498 | (unsigned long long)*hwdev->dma_mask, |
508 | (unsigned long long)dev_addr); | 499 | (unsigned long long)dev_addr); |
@@ -518,12 +509,11 @@ swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr, | |||
518 | dma_addr_t dma_handle) | 509 | dma_addr_t dma_handle) |
519 | { | 510 | { |
520 | WARN_ON(irqs_disabled()); | 511 | WARN_ON(irqs_disabled()); |
521 | if (!(vaddr >= (void *)io_tlb_start | 512 | if (!is_swiotlb_buffer(vaddr)) |
522 | && vaddr < (void *)io_tlb_end)) | ||
523 | free_pages((unsigned long) vaddr, get_order(size)); | 513 | free_pages((unsigned long) vaddr, get_order(size)); |
524 | else | 514 | else |
525 | /* DMA_TO_DEVICE to avoid memcpy in unmap_single */ | 515 | /* DMA_TO_DEVICE to avoid memcpy in unmap_single */ |
526 | swiotlb_unmap_single (hwdev, dma_handle, size, DMA_TO_DEVICE); | 516 | unmap_single(hwdev, vaddr, size, DMA_TO_DEVICE); |
527 | } | 517 | } |
528 | 518 | ||
529 | static void | 519 | static void |
@@ -567,7 +557,7 @@ swiotlb_map_single_attrs(struct device *hwdev, void *ptr, size_t size, | |||
567 | * we can safely return the device addr and not worry about bounce | 557 | * we can safely return the device addr and not worry about bounce |
568 | * buffering it. | 558 | * buffering it. |
569 | */ | 559 | */ |
570 | if (!address_needs_mapping(hwdev, dev_addr) && !swiotlb_force) | 560 | if (!address_needs_mapping(hwdev, dev_addr, size) && !swiotlb_force) |
571 | return dev_addr; | 561 | return dev_addr; |
572 | 562 | ||
573 | /* | 563 | /* |
@@ -584,7 +574,7 @@ swiotlb_map_single_attrs(struct device *hwdev, void *ptr, size_t size, | |||
584 | /* | 574 | /* |
585 | * Ensure that the address returned is DMA'ble | 575 | * Ensure that the address returned is DMA'ble |
586 | */ | 576 | */ |
587 | if (address_needs_mapping(hwdev, dev_addr)) | 577 | if (address_needs_mapping(hwdev, dev_addr, size)) |
588 | panic("map_single: bounce buffer is not DMA'ble"); | 578 | panic("map_single: bounce buffer is not DMA'ble"); |
589 | 579 | ||
590 | return dev_addr; | 580 | return dev_addr; |
@@ -612,7 +602,7 @@ swiotlb_unmap_single_attrs(struct device *hwdev, dma_addr_t dev_addr, | |||
612 | char *dma_addr = bus_to_virt(dev_addr); | 602 | char *dma_addr = bus_to_virt(dev_addr); |
613 | 603 | ||
614 | BUG_ON(dir == DMA_NONE); | 604 | BUG_ON(dir == DMA_NONE); |
615 | if (dma_addr >= io_tlb_start && dma_addr < io_tlb_end) | 605 | if (is_swiotlb_buffer(dma_addr)) |
616 | unmap_single(hwdev, dma_addr, size, dir); | 606 | unmap_single(hwdev, dma_addr, size, dir); |
617 | else if (dir == DMA_FROM_DEVICE) | 607 | else if (dir == DMA_FROM_DEVICE) |
618 | dma_mark_clean(dma_addr, size); | 608 | dma_mark_clean(dma_addr, size); |
@@ -642,7 +632,7 @@ swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr, | |||
642 | char *dma_addr = bus_to_virt(dev_addr); | 632 | char *dma_addr = bus_to_virt(dev_addr); |
643 | 633 | ||
644 | BUG_ON(dir == DMA_NONE); | 634 | BUG_ON(dir == DMA_NONE); |
645 | if (dma_addr >= io_tlb_start && dma_addr < io_tlb_end) | 635 | if (is_swiotlb_buffer(dma_addr)) |
646 | sync_single(hwdev, dma_addr, size, dir, target); | 636 | sync_single(hwdev, dma_addr, size, dir, target); |
647 | else if (dir == DMA_FROM_DEVICE) | 637 | else if (dir == DMA_FROM_DEVICE) |
648 | dma_mark_clean(dma_addr, size); | 638 | dma_mark_clean(dma_addr, size); |
@@ -673,7 +663,7 @@ swiotlb_sync_single_range(struct device *hwdev, dma_addr_t dev_addr, | |||
673 | char *dma_addr = bus_to_virt(dev_addr) + offset; | 663 | char *dma_addr = bus_to_virt(dev_addr) + offset; |
674 | 664 | ||
675 | BUG_ON(dir == DMA_NONE); | 665 | BUG_ON(dir == DMA_NONE); |
676 | if (dma_addr >= io_tlb_start && dma_addr < io_tlb_end) | 666 | if (is_swiotlb_buffer(dma_addr)) |
677 | sync_single(hwdev, dma_addr, size, dir, target); | 667 | sync_single(hwdev, dma_addr, size, dir, target); |
678 | else if (dir == DMA_FROM_DEVICE) | 668 | else if (dir == DMA_FROM_DEVICE) |
679 | dma_mark_clean(dma_addr, size); | 669 | dma_mark_clean(dma_addr, size); |
@@ -727,7 +717,8 @@ swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems, | |||
727 | for_each_sg(sgl, sg, nelems, i) { | 717 | for_each_sg(sgl, sg, nelems, i) { |
728 | addr = SG_ENT_VIRT_ADDRESS(sg); | 718 | addr = SG_ENT_VIRT_ADDRESS(sg); |
729 | dev_addr = virt_to_bus(addr); | 719 | dev_addr = virt_to_bus(addr); |
730 | if (swiotlb_force || address_needs_mapping(hwdev, dev_addr)) { | 720 | if (swiotlb_force || |
721 | address_needs_mapping(hwdev, dev_addr, sg->length)) { | ||
731 | void *map = map_single(hwdev, addr, sg->length, dir); | 722 | void *map = map_single(hwdev, addr, sg->length, dir); |
732 | if (!map) { | 723 | if (!map) { |
733 | /* Don't panic here, we expect map_sg users | 724 | /* Don't panic here, we expect map_sg users |
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index d8d1d1142248..cceecb6a963d 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -27,44 +27,53 @@ | |||
27 | 27 | ||
28 | #include <asm/page.h> /* for PAGE_SIZE */ | 28 | #include <asm/page.h> /* for PAGE_SIZE */ |
29 | #include <asm/div64.h> | 29 | #include <asm/div64.h> |
30 | #include <asm/sections.h> /* for dereference_function_descriptor() */ | ||
30 | 31 | ||
31 | /* Works only for digits and letters, but small and fast */ | 32 | /* Works only for digits and letters, but small and fast */ |
32 | #define TOLOWER(x) ((x) | 0x20) | 33 | #define TOLOWER(x) ((x) | 0x20) |
33 | 34 | ||
35 | static unsigned int simple_guess_base(const char *cp) | ||
36 | { | ||
37 | if (cp[0] == '0') { | ||
38 | if (TOLOWER(cp[1]) == 'x' && isxdigit(cp[2])) | ||
39 | return 16; | ||
40 | else | ||
41 | return 8; | ||
42 | } else { | ||
43 | return 10; | ||
44 | } | ||
45 | } | ||
46 | |||
34 | /** | 47 | /** |
35 | * simple_strtoul - convert a string to an unsigned long | 48 | * simple_strtoul - convert a string to an unsigned long |
36 | * @cp: The start of the string | 49 | * @cp: The start of the string |
37 | * @endp: A pointer to the end of the parsed string will be placed here | 50 | * @endp: A pointer to the end of the parsed string will be placed here |
38 | * @base: The number base to use | 51 | * @base: The number base to use |
39 | */ | 52 | */ |
40 | unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base) | 53 | unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) |
41 | { | 54 | { |
42 | unsigned long result = 0,value; | 55 | unsigned long result = 0; |
43 | 56 | ||
44 | if (!base) { | 57 | if (!base) |
45 | base = 10; | 58 | base = simple_guess_base(cp); |
46 | if (*cp == '0') { | 59 | |
47 | base = 8; | 60 | if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x') |
48 | cp++; | 61 | cp += 2; |
49 | if ((TOLOWER(*cp) == 'x') && isxdigit(cp[1])) { | 62 | |
50 | cp++; | 63 | while (isxdigit(*cp)) { |
51 | base = 16; | 64 | unsigned int value; |
52 | } | 65 | |
53 | } | 66 | value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10; |
54 | } else if (base == 16) { | 67 | if (value >= base) |
55 | if (cp[0] == '0' && TOLOWER(cp[1]) == 'x') | 68 | break; |
56 | cp += 2; | 69 | result = result * base + value; |
57 | } | ||
58 | while (isxdigit(*cp) && | ||
59 | (value = isdigit(*cp) ? *cp-'0' : TOLOWER(*cp)-'a'+10) < base) { | ||
60 | result = result*base + value; | ||
61 | cp++; | 70 | cp++; |
62 | } | 71 | } |
72 | |||
63 | if (endp) | 73 | if (endp) |
64 | *endp = (char *)cp; | 74 | *endp = (char *)cp; |
65 | return result; | 75 | return result; |
66 | } | 76 | } |
67 | |||
68 | EXPORT_SYMBOL(simple_strtoul); | 77 | EXPORT_SYMBOL(simple_strtoul); |
69 | 78 | ||
70 | /** | 79 | /** |
@@ -73,13 +82,12 @@ EXPORT_SYMBOL(simple_strtoul); | |||
73 | * @endp: A pointer to the end of the parsed string will be placed here | 82 | * @endp: A pointer to the end of the parsed string will be placed here |
74 | * @base: The number base to use | 83 | * @base: The number base to use |
75 | */ | 84 | */ |
76 | long simple_strtol(const char *cp,char **endp,unsigned int base) | 85 | long simple_strtol(const char *cp, char **endp, unsigned int base) |
77 | { | 86 | { |
78 | if(*cp=='-') | 87 | if(*cp == '-') |
79 | return -simple_strtoul(cp+1,endp,base); | 88 | return -simple_strtoul(cp + 1, endp, base); |
80 | return simple_strtoul(cp,endp,base); | 89 | return simple_strtoul(cp, endp, base); |
81 | } | 90 | } |
82 | |||
83 | EXPORT_SYMBOL(simple_strtol); | 91 | EXPORT_SYMBOL(simple_strtol); |
84 | 92 | ||
85 | /** | 93 | /** |
@@ -88,34 +96,30 @@ EXPORT_SYMBOL(simple_strtol); | |||
88 | * @endp: A pointer to the end of the parsed string will be placed here | 96 | * @endp: A pointer to the end of the parsed string will be placed here |
89 | * @base: The number base to use | 97 | * @base: The number base to use |
90 | */ | 98 | */ |
91 | unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base) | 99 | unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) |
92 | { | 100 | { |
93 | unsigned long long result = 0,value; | 101 | unsigned long long result = 0; |
94 | 102 | ||
95 | if (!base) { | 103 | if (!base) |
96 | base = 10; | 104 | base = simple_guess_base(cp); |
97 | if (*cp == '0') { | 105 | |
98 | base = 8; | 106 | if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x') |
99 | cp++; | 107 | cp += 2; |
100 | if ((TOLOWER(*cp) == 'x') && isxdigit(cp[1])) { | 108 | |
101 | cp++; | 109 | while (isxdigit(*cp)) { |
102 | base = 16; | 110 | unsigned int value; |
103 | } | 111 | |
104 | } | 112 | value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10; |
105 | } else if (base == 16) { | 113 | if (value >= base) |
106 | if (cp[0] == '0' && TOLOWER(cp[1]) == 'x') | 114 | break; |
107 | cp += 2; | 115 | result = result * base + value; |
108 | } | ||
109 | while (isxdigit(*cp) | ||
110 | && (value = isdigit(*cp) ? *cp-'0' : TOLOWER(*cp)-'a'+10) < base) { | ||
111 | result = result*base + value; | ||
112 | cp++; | 116 | cp++; |
113 | } | 117 | } |
118 | |||
114 | if (endp) | 119 | if (endp) |
115 | *endp = (char *)cp; | 120 | *endp = (char *)cp; |
116 | return result; | 121 | return result; |
117 | } | 122 | } |
118 | |||
119 | EXPORT_SYMBOL(simple_strtoull); | 123 | EXPORT_SYMBOL(simple_strtoull); |
120 | 124 | ||
121 | /** | 125 | /** |
@@ -124,14 +128,13 @@ EXPORT_SYMBOL(simple_strtoull); | |||
124 | * @endp: A pointer to the end of the parsed string will be placed here | 128 | * @endp: A pointer to the end of the parsed string will be placed here |
125 | * @base: The number base to use | 129 | * @base: The number base to use |
126 | */ | 130 | */ |
127 | long long simple_strtoll(const char *cp,char **endp,unsigned int base) | 131 | long long simple_strtoll(const char *cp, char **endp, unsigned int base) |
128 | { | 132 | { |
129 | if(*cp=='-') | 133 | if(*cp=='-') |
130 | return -simple_strtoull(cp+1,endp,base); | 134 | return -simple_strtoull(cp + 1, endp, base); |
131 | return simple_strtoull(cp,endp,base); | 135 | return simple_strtoull(cp, endp, base); |
132 | } | 136 | } |
133 | 137 | ||
134 | |||
135 | /** | 138 | /** |
136 | * strict_strtoul - convert a string to an unsigned long strictly | 139 | * strict_strtoul - convert a string to an unsigned long strictly |
137 | * @cp: The string to be converted | 140 | * @cp: The string to be converted |
@@ -154,7 +157,27 @@ long long simple_strtoll(const char *cp,char **endp,unsigned int base) | |||
154 | * simple_strtoul just ignores the successive invalid characters and | 157 | * simple_strtoul just ignores the successive invalid characters and |
155 | * return the converted value of prefix part of the string. | 158 | * return the converted value of prefix part of the string. |
156 | */ | 159 | */ |
157 | int strict_strtoul(const char *cp, unsigned int base, unsigned long *res); | 160 | int strict_strtoul(const char *cp, unsigned int base, unsigned long *res) |
161 | { | ||
162 | char *tail; | ||
163 | unsigned long val; | ||
164 | size_t len; | ||
165 | |||
166 | *res = 0; | ||
167 | len = strlen(cp); | ||
168 | if (len == 0) | ||
169 | return -EINVAL; | ||
170 | |||
171 | val = simple_strtoul(cp, &tail, base); | ||
172 | if ((*tail == '\0') || | ||
173 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { | ||
174 | *res = val; | ||
175 | return 0; | ||
176 | } | ||
177 | |||
178 | return -EINVAL; | ||
179 | } | ||
180 | EXPORT_SYMBOL(strict_strtoul); | ||
158 | 181 | ||
159 | /** | 182 | /** |
160 | * strict_strtol - convert a string to a long strictly | 183 | * strict_strtol - convert a string to a long strictly |
@@ -168,7 +191,20 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res); | |||
168 | * It returns 0 if conversion is successful and *res is set to the converted | 191 | * It returns 0 if conversion is successful and *res is set to the converted |
169 | * value, otherwise it returns -EINVAL and *res is set to 0. | 192 | * value, otherwise it returns -EINVAL and *res is set to 0. |
170 | */ | 193 | */ |
171 | int strict_strtol(const char *cp, unsigned int base, long *res); | 194 | int strict_strtol(const char *cp, unsigned int base, long *res) |
195 | { | ||
196 | int ret; | ||
197 | if (*cp == '-') { | ||
198 | ret = strict_strtoul(cp + 1, base, (unsigned long *)res); | ||
199 | if (!ret) | ||
200 | *res = -(*res); | ||
201 | } else { | ||
202 | ret = strict_strtoul(cp, base, (unsigned long *)res); | ||
203 | } | ||
204 | |||
205 | return ret; | ||
206 | } | ||
207 | EXPORT_SYMBOL(strict_strtol); | ||
172 | 208 | ||
173 | /** | 209 | /** |
174 | * strict_strtoull - convert a string to an unsigned long long strictly | 210 | * strict_strtoull - convert a string to an unsigned long long strictly |
@@ -192,7 +228,27 @@ int strict_strtol(const char *cp, unsigned int base, long *res); | |||
192 | * simple_strtoull just ignores the successive invalid characters and | 228 | * simple_strtoull just ignores the successive invalid characters and |
193 | * return the converted value of prefix part of the string. | 229 | * return the converted value of prefix part of the string. |
194 | */ | 230 | */ |
195 | int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res); | 231 | int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res) |
232 | { | ||
233 | char *tail; | ||
234 | unsigned long long val; | ||
235 | size_t len; | ||
236 | |||
237 | *res = 0; | ||
238 | len = strlen(cp); | ||
239 | if (len == 0) | ||
240 | return -EINVAL; | ||
241 | |||
242 | val = simple_strtoull(cp, &tail, base); | ||
243 | if ((*tail == '\0') || | ||
244 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { | ||
245 | *res = val; | ||
246 | return 0; | ||
247 | } | ||
248 | |||
249 | return -EINVAL; | ||
250 | } | ||
251 | EXPORT_SYMBOL(strict_strtoull); | ||
196 | 252 | ||
197 | /** | 253 | /** |
198 | * strict_strtoll - convert a string to a long long strictly | 254 | * strict_strtoll - convert a string to a long long strictly |
@@ -206,53 +262,20 @@ int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res); | |||
206 | * It returns 0 if conversion is successful and *res is set to the converted | 262 | * It returns 0 if conversion is successful and *res is set to the converted |
207 | * value, otherwise it returns -EINVAL and *res is set to 0. | 263 | * value, otherwise it returns -EINVAL and *res is set to 0. |
208 | */ | 264 | */ |
209 | int strict_strtoll(const char *cp, unsigned int base, long long *res); | 265 | int strict_strtoll(const char *cp, unsigned int base, long long *res) |
210 | 266 | { | |
211 | #define define_strict_strtoux(type, valtype) \ | 267 | int ret; |
212 | int strict_strtou##type(const char *cp, unsigned int base, valtype *res)\ | 268 | if (*cp == '-') { |
213 | { \ | 269 | ret = strict_strtoull(cp + 1, base, (unsigned long long *)res); |
214 | char *tail; \ | 270 | if (!ret) |
215 | valtype val; \ | 271 | *res = -(*res); |
216 | size_t len; \ | 272 | } else { |
217 | \ | 273 | ret = strict_strtoull(cp, base, (unsigned long long *)res); |
218 | *res = 0; \ | 274 | } |
219 | len = strlen(cp); \ | ||
220 | if (len == 0) \ | ||
221 | return -EINVAL; \ | ||
222 | \ | ||
223 | val = simple_strtou##type(cp, &tail, base); \ | ||
224 | if ((*tail == '\0') || \ | ||
225 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {\ | ||
226 | *res = val; \ | ||
227 | return 0; \ | ||
228 | } \ | ||
229 | \ | ||
230 | return -EINVAL; \ | ||
231 | } \ | ||
232 | |||
233 | #define define_strict_strtox(type, valtype) \ | ||
234 | int strict_strto##type(const char *cp, unsigned int base, valtype *res) \ | ||
235 | { \ | ||
236 | int ret; \ | ||
237 | if (*cp == '-') { \ | ||
238 | ret = strict_strtou##type(cp+1, base, res); \ | ||
239 | if (!ret) \ | ||
240 | *res = -(*res); \ | ||
241 | } else \ | ||
242 | ret = strict_strtou##type(cp, base, res); \ | ||
243 | \ | ||
244 | return ret; \ | ||
245 | } \ | ||
246 | |||
247 | define_strict_strtoux(l, unsigned long) | ||
248 | define_strict_strtox(l, long) | ||
249 | define_strict_strtoux(ll, unsigned long long) | ||
250 | define_strict_strtox(ll, long long) | ||
251 | 275 | ||
252 | EXPORT_SYMBOL(strict_strtoul); | 276 | return ret; |
253 | EXPORT_SYMBOL(strict_strtol); | 277 | } |
254 | EXPORT_SYMBOL(strict_strtoll); | 278 | EXPORT_SYMBOL(strict_strtoll); |
255 | EXPORT_SYMBOL(strict_strtoull); | ||
256 | 279 | ||
257 | static int skip_atoi(const char **s) | 280 | static int skip_atoi(const char **s) |
258 | { | 281 | { |
@@ -513,16 +536,6 @@ static char *string(char *buf, char *end, char *s, int field_width, int precisio | |||
513 | return buf; | 536 | return buf; |
514 | } | 537 | } |
515 | 538 | ||
516 | static inline void *dereference_function_descriptor(void *ptr) | ||
517 | { | ||
518 | #if defined(CONFIG_IA64) || defined(CONFIG_PPC64) | ||
519 | void *p; | ||
520 | if (!probe_kernel_address(ptr, p)) | ||
521 | ptr = p; | ||
522 | #endif | ||
523 | return ptr; | ||
524 | } | ||
525 | |||
526 | static char *symbol_string(char *buf, char *end, void *ptr, int field_width, int precision, int flags) | 539 | static char *symbol_string(char *buf, char *end, void *ptr, int field_width, int precision, int flags) |
527 | { | 540 | { |
528 | unsigned long value = (unsigned long) ptr; | 541 | unsigned long value = (unsigned long) ptr; |
@@ -574,6 +587,10 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field | |||
574 | * @fmt: The format string to use | 587 | * @fmt: The format string to use |
575 | * @args: Arguments for the format string | 588 | * @args: Arguments for the format string |
576 | * | 589 | * |
590 | * This function follows C99 vsnprintf, but has some extensions: | ||
591 | * %pS output the name of a text symbol | ||
592 | * %pF output the name of a function pointer | ||
593 | * | ||
577 | * The return value is the number of characters which would | 594 | * The return value is the number of characters which would |
578 | * be generated for the given input, excluding the trailing | 595 | * be generated for the given input, excluding the trailing |
579 | * '\0', as per ISO C99. If you want to have the exact | 596 | * '\0', as per ISO C99. If you want to have the exact |
@@ -799,7 +816,6 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
799 | /* the trailing null byte doesn't count towards the total */ | 816 | /* the trailing null byte doesn't count towards the total */ |
800 | return str-buf; | 817 | return str-buf; |
801 | } | 818 | } |
802 | |||
803 | EXPORT_SYMBOL(vsnprintf); | 819 | EXPORT_SYMBOL(vsnprintf); |
804 | 820 | ||
805 | /** | 821 | /** |
@@ -815,6 +831,8 @@ EXPORT_SYMBOL(vsnprintf); | |||
815 | * | 831 | * |
816 | * Call this function if you are already dealing with a va_list. | 832 | * Call this function if you are already dealing with a va_list. |
817 | * You probably want scnprintf() instead. | 833 | * You probably want scnprintf() instead. |
834 | * | ||
835 | * See the vsnprintf() documentation for format string extensions over C99. | ||
818 | */ | 836 | */ |
819 | int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) | 837 | int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) |
820 | { | 838 | { |
@@ -823,7 +841,6 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
823 | i=vsnprintf(buf,size,fmt,args); | 841 | i=vsnprintf(buf,size,fmt,args); |
824 | return (i >= size) ? (size - 1) : i; | 842 | return (i >= size) ? (size - 1) : i; |
825 | } | 843 | } |
826 | |||
827 | EXPORT_SYMBOL(vscnprintf); | 844 | EXPORT_SYMBOL(vscnprintf); |
828 | 845 | ||
829 | /** | 846 | /** |
@@ -837,6 +854,8 @@ EXPORT_SYMBOL(vscnprintf); | |||
837 | * generated for the given input, excluding the trailing null, | 854 | * generated for the given input, excluding the trailing null, |
838 | * as per ISO C99. If the return is greater than or equal to | 855 | * as per ISO C99. If the return is greater than or equal to |
839 | * @size, the resulting string is truncated. | 856 | * @size, the resulting string is truncated. |
857 | * | ||
858 | * See the vsnprintf() documentation for format string extensions over C99. | ||
840 | */ | 859 | */ |
841 | int snprintf(char * buf, size_t size, const char *fmt, ...) | 860 | int snprintf(char * buf, size_t size, const char *fmt, ...) |
842 | { | 861 | { |
@@ -848,7 +867,6 @@ int snprintf(char * buf, size_t size, const char *fmt, ...) | |||
848 | va_end(args); | 867 | va_end(args); |
849 | return i; | 868 | return i; |
850 | } | 869 | } |
851 | |||
852 | EXPORT_SYMBOL(snprintf); | 870 | EXPORT_SYMBOL(snprintf); |
853 | 871 | ||
854 | /** | 872 | /** |
@@ -886,12 +904,13 @@ EXPORT_SYMBOL(scnprintf); | |||
886 | * | 904 | * |
887 | * Call this function if you are already dealing with a va_list. | 905 | * Call this function if you are already dealing with a va_list. |
888 | * You probably want sprintf() instead. | 906 | * You probably want sprintf() instead. |
907 | * | ||
908 | * See the vsnprintf() documentation for format string extensions over C99. | ||
889 | */ | 909 | */ |
890 | int vsprintf(char *buf, const char *fmt, va_list args) | 910 | int vsprintf(char *buf, const char *fmt, va_list args) |
891 | { | 911 | { |
892 | return vsnprintf(buf, INT_MAX, fmt, args); | 912 | return vsnprintf(buf, INT_MAX, fmt, args); |
893 | } | 913 | } |
894 | |||
895 | EXPORT_SYMBOL(vsprintf); | 914 | EXPORT_SYMBOL(vsprintf); |
896 | 915 | ||
897 | /** | 916 | /** |
@@ -903,6 +922,8 @@ EXPORT_SYMBOL(vsprintf); | |||
903 | * The function returns the number of characters written | 922 | * The function returns the number of characters written |
904 | * into @buf. Use snprintf() or scnprintf() in order to avoid | 923 | * into @buf. Use snprintf() or scnprintf() in order to avoid |
905 | * buffer overflows. | 924 | * buffer overflows. |
925 | * | ||
926 | * See the vsnprintf() documentation for format string extensions over C99. | ||
906 | */ | 927 | */ |
907 | int sprintf(char * buf, const char *fmt, ...) | 928 | int sprintf(char * buf, const char *fmt, ...) |
908 | { | 929 | { |
@@ -914,7 +935,6 @@ int sprintf(char * buf, const char *fmt, ...) | |||
914 | va_end(args); | 935 | va_end(args); |
915 | return i; | 936 | return i; |
916 | } | 937 | } |
917 | |||
918 | EXPORT_SYMBOL(sprintf); | 938 | EXPORT_SYMBOL(sprintf); |
919 | 939 | ||
920 | /** | 940 | /** |
@@ -1143,7 +1163,6 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1143 | 1163 | ||
1144 | return num; | 1164 | return num; |
1145 | } | 1165 | } |
1146 | |||
1147 | EXPORT_SYMBOL(vsscanf); | 1166 | EXPORT_SYMBOL(vsscanf); |
1148 | 1167 | ||
1149 | /** | 1168 | /** |
@@ -1162,5 +1181,4 @@ int sscanf(const char * buf, const char * fmt, ...) | |||
1162 | va_end(args); | 1181 | va_end(args); |
1163 | return i; | 1182 | return i; |
1164 | } | 1183 | } |
1165 | |||
1166 | EXPORT_SYMBOL(sscanf); | 1184 | EXPORT_SYMBOL(sscanf); |