diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 10 | ||||
-rw-r--r-- | lib/Kconfig.debug | 2 | ||||
-rw-r--r-- | lib/Makefile | 8 | ||||
-rw-r--r-- | lib/find_last_bit.c | 4 | ||||
-rw-r--r-- | lib/find_next_bit.c | 18 | ||||
-rw-r--r-- | lib/flex_array.c | 51 | ||||
-rw-r--r-- | lib/locking-selftest.c | 2 |
7 files changed, 49 insertions, 46 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 | |||
19 | config GENERIC_FIND_FIRST_BIT | 19 | config GENERIC_FIND_FIRST_BIT |
20 | bool | 20 | bool |
21 | 21 | ||
22 | config GENERIC_FIND_NEXT_BIT | ||
23 | bool | ||
24 | |||
25 | config GENERIC_FIND_BIT_LE | ||
26 | bool | ||
27 | |||
28 | config GENERIC_FIND_LAST_BIT | ||
29 | bool | ||
30 | default y | ||
31 | |||
32 | config CRC_CCITT | 22 | config 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 28afa4c5333c..dd373c8ee943 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
@@ -697,7 +697,7 @@ config DEBUG_BUGVERBOSE | |||
697 | bool "Verbose BUG() reporting (adds 70K)" if DEBUG_KERNEL && EXPERT | 697 | bool "Verbose BUG() reporting (adds 70K)" if DEBUG_KERNEL && EXPERT |
698 | depends on BUG | 698 | depends on BUG |
699 | depends on ARM || AVR32 || M32R || M68K || SPARC32 || SPARC64 || \ | 699 | depends on ARM || AVR32 || M32R || M68K || SPARC32 || SPARC64 || \ |
700 | FRV || SUPERH || GENERIC_BUG || BLACKFIN || MN10300 | 700 | FRV || SUPERH || GENERIC_BUG || BLACKFIN || MN10300 || TILE |
701 | default y | 701 | default y |
702 | help | 702 | help |
703 | Say Y here to make BUG() panics output the file name and line number | 703 | Say Y here to make BUG() panics output the file name and line number |
diff --git a/lib/Makefile b/lib/Makefile index 4b49a249064b..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 | ||
17 | lib-$(CONFIG_MMU) += ioremap.o | 17 | lib-$(CONFIG_MMU) += ioremap.o |
18 | lib-$(CONFIG_SMP) += cpumask.o | 18 | lib-$(CONFIG_SMP) += cpumask.o |
@@ -22,7 +22,7 @@ lib-y += kobject.o kref.o klist.o | |||
22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | 22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ | 23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ |
24 | string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o \ | 24 | string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o \ |
25 | bsearch.o | 25 | bsearch.o find_last_bit.o |
26 | obj-y += kstrtox.o | 26 | obj-y += kstrtox.o |
27 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o | 27 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o |
28 | 28 | ||
@@ -39,10 +39,6 @@ obj-$(CONFIG_DEBUG_LOCKING_API_SELFTESTS) += locking-selftest.o | |||
39 | obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o | 39 | obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o |
40 | lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o | 40 | lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o |
41 | lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o | 41 | lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o |
42 | lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o | ||
43 | lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o | ||
44 | lib-$(CONFIG_GENERIC_FIND_BIT_LE) += find_next_bit.o | ||
45 | obj-$(CONFIG_GENERIC_FIND_LAST_BIT) += find_last_bit.o | ||
46 | 42 | ||
47 | CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS)) | 43 | CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS)) |
48 | obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o | 44 | obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o |
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 | |||
18 | unsigned long find_last_bit(const unsigned long *addr, unsigned long size) | 20 | unsigned 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 | } |
45 | EXPORT_SYMBOL(find_last_bit); | 47 | EXPORT_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 | } |
61 | EXPORT_SYMBOL(find_next_bit); | 61 | EXPORT_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 | } |
105 | EXPORT_SYMBOL(find_next_zero_bit); | 107 | EXPORT_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 | } |
133 | EXPORT_SYMBOL(find_first_bit); | 135 | EXPORT_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 | } |
159 | EXPORT_SYMBOL(find_first_zero_bit); | 163 | EXPORT_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 */ |
166 | static inline unsigned long ext2_swabp(const unsigned long * x) | 169 | static 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 | ||
189 | unsigned long find_next_zero_bit_le(const void *addr, unsigned | 193 | unsigned 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 | } |
231 | EXPORT_SYMBOL(find_next_zero_bit_le); | 235 | EXPORT_SYMBOL(find_next_zero_bit_le); |
236 | #endif | ||
232 | 237 | ||
238 | #ifndef find_next_bit_le | ||
233 | unsigned long find_next_bit_le(const void *addr, unsigned | 239 | unsigned 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 | } |
276 | EXPORT_SYMBOL(find_next_bit_le); | 282 | EXPORT_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 cab7621f98aa..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 | ||
28 | struct flex_array_part { | 29 | struct 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,11 +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; |
92 | int elems_per_part = 0; | ||
93 | int reciprocal_elems = 0; | ||
91 | int max_size = 0; | 94 | int max_size = 0; |
92 | 95 | ||
93 | if (element_size) | 96 | if (element_size) { |
94 | max_size = FLEX_ARRAY_NR_BASE_PTRS * | 97 | elems_per_part = FLEX_ARRAY_ELEMENTS_PER_PART(element_size); |
95 | 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 | } | ||
96 | 101 | ||
97 | /* max_size will end up 0 if element_size > PAGE_SIZE */ | 102 | /* max_size will end up 0 if element_size > PAGE_SIZE */ |
98 | if (total > max_size) | 103 | if (total > max_size) |
@@ -102,6 +107,8 @@ struct flex_array *flex_array_alloc(int element_size, unsigned int total, | |||
102 | return NULL; | 107 | return NULL; |
103 | ret->element_size = element_size; | 108 | ret->element_size = element_size; |
104 | 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; | ||
105 | if (elements_fit_in_base(ret) && !(flags & __GFP_ZERO)) | 112 | if (elements_fit_in_base(ret) && !(flags & __GFP_ZERO)) |
106 | memset(&ret->parts[0], FLEX_ARRAY_FREE, | 113 | memset(&ret->parts[0], FLEX_ARRAY_FREE, |
107 | FLEX_ARRAY_BASE_BYTES_LEFT); | 114 | FLEX_ARRAY_BASE_BYTES_LEFT); |
@@ -112,7 +119,7 @@ EXPORT_SYMBOL(flex_array_alloc); | |||
112 | static int fa_element_to_part_nr(struct flex_array *fa, | 119 | static int fa_element_to_part_nr(struct flex_array *fa, |
113 | unsigned int element_nr) | 120 | unsigned int element_nr) |
114 | { | 121 | { |
115 | return element_nr / FLEX_ARRAY_ELEMENTS_PER_PART(fa->element_size); | 122 | return reciprocal_divide(element_nr, fa->reciprocal_elems); |
116 | } | 123 | } |
117 | 124 | ||
118 | /** | 125 | /** |
@@ -141,12 +148,12 @@ void flex_array_free(struct flex_array *fa) | |||
141 | EXPORT_SYMBOL(flex_array_free); | 148 | EXPORT_SYMBOL(flex_array_free); |
142 | 149 | ||
143 | static unsigned int index_inside_part(struct flex_array *fa, | 150 | static unsigned int index_inside_part(struct flex_array *fa, |
144 | unsigned int element_nr) | 151 | unsigned int element_nr, |
152 | unsigned int part_nr) | ||
145 | { | 153 | { |
146 | unsigned int part_offset; | 154 | unsigned int part_offset; |
147 | 155 | ||
148 | part_offset = element_nr % | 156 | part_offset = element_nr - part_nr * fa->elems_per_part; |
149 | FLEX_ARRAY_ELEMENTS_PER_PART(fa->element_size); | ||
150 | return part_offset * fa->element_size; | 157 | return part_offset * fa->element_size; |
151 | } | 158 | } |
152 | 159 | ||
@@ -186,7 +193,7 @@ __fa_get_part(struct flex_array *fa, int part_nr, gfp_t flags) | |||
186 | int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src, | 193 | int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src, |
187 | gfp_t flags) | 194 | gfp_t flags) |
188 | { | 195 | { |
189 | int part_nr; | 196 | int part_nr = 0; |
190 | struct flex_array_part *part; | 197 | struct flex_array_part *part; |
191 | void *dst; | 198 | void *dst; |
192 | 199 | ||
@@ -202,7 +209,7 @@ int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src, | |||
202 | if (!part) | 209 | if (!part) |
203 | return -ENOMEM; | 210 | return -ENOMEM; |
204 | } | 211 | } |
205 | dst = &part->elements[index_inside_part(fa, element_nr)]; | 212 | dst = &part->elements[index_inside_part(fa, element_nr, part_nr)]; |
206 | memcpy(dst, src, fa->element_size); | 213 | memcpy(dst, src, fa->element_size); |
207 | return 0; | 214 | return 0; |
208 | } | 215 | } |
@@ -217,7 +224,7 @@ EXPORT_SYMBOL(flex_array_put); | |||
217 | */ | 224 | */ |
218 | int flex_array_clear(struct flex_array *fa, unsigned int element_nr) | 225 | int flex_array_clear(struct flex_array *fa, unsigned int element_nr) |
219 | { | 226 | { |
220 | int part_nr; | 227 | int part_nr = 0; |
221 | struct flex_array_part *part; | 228 | struct flex_array_part *part; |
222 | void *dst; | 229 | void *dst; |
223 | 230 | ||
@@ -233,7 +240,7 @@ int flex_array_clear(struct flex_array *fa, unsigned int element_nr) | |||
233 | if (!part) | 240 | if (!part) |
234 | return -EINVAL; | 241 | return -EINVAL; |
235 | } | 242 | } |
236 | dst = &part->elements[index_inside_part(fa, element_nr)]; | 243 | dst = &part->elements[index_inside_part(fa, element_nr, part_nr)]; |
237 | memset(dst, FLEX_ARRAY_FREE, fa->element_size); | 244 | memset(dst, FLEX_ARRAY_FREE, fa->element_size); |
238 | return 0; | 245 | return 0; |
239 | } | 246 | } |
@@ -302,7 +309,7 @@ EXPORT_SYMBOL(flex_array_prealloc); | |||
302 | */ | 309 | */ |
303 | void *flex_array_get(struct flex_array *fa, unsigned int element_nr) | 310 | void *flex_array_get(struct flex_array *fa, unsigned int element_nr) |
304 | { | 311 | { |
305 | int part_nr; | 312 | int part_nr = 0; |
306 | struct flex_array_part *part; | 313 | struct flex_array_part *part; |
307 | 314 | ||
308 | if (!fa->element_size) | 315 | if (!fa->element_size) |
@@ -317,7 +324,7 @@ void *flex_array_get(struct flex_array *fa, unsigned int element_nr) | |||
317 | if (!part) | 324 | if (!part) |
318 | return NULL; | 325 | return NULL; |
319 | } | 326 | } |
320 | return &part->elements[index_inside_part(fa, element_nr)]; | 327 | return &part->elements[index_inside_part(fa, element_nr, part_nr)]; |
321 | } | 328 | } |
322 | EXPORT_SYMBOL(flex_array_get); | 329 | EXPORT_SYMBOL(flex_array_get); |
323 | 330 | ||
diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c index 619313ed6c46..507a22fab738 100644 --- a/lib/locking-selftest.c +++ b/lib/locking-selftest.c | |||
@@ -144,7 +144,7 @@ static void init_shared_classes(void) | |||
144 | 144 | ||
145 | #define HARDIRQ_ENTER() \ | 145 | #define HARDIRQ_ENTER() \ |
146 | local_irq_disable(); \ | 146 | local_irq_disable(); \ |
147 | irq_enter(); \ | 147 | __irq_enter(); \ |
148 | WARN_ON(!in_irq()); | 148 | WARN_ON(!in_irq()); |
149 | 149 | ||
150 | #define HARDIRQ_EXIT() \ | 150 | #define HARDIRQ_EXIT() \ |