diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 33 | ||||
-rw-r--r-- | lib/Kconfig.debug | 2 | ||||
-rw-r--r-- | lib/Makefile | 2 | ||||
-rw-r--r-- | lib/bitmap.c | 111 | ||||
-rw-r--r-- | lib/cmdline.c | 15 | ||||
-rw-r--r-- | lib/glob.c | 287 | ||||
-rw-r--r-- | lib/klist.c | 6 | ||||
-rw-r--r-- | lib/list_sort.c | 71 | ||||
-rw-r--r-- | lib/string_helpers.c | 15 | ||||
-rw-r--r-- | lib/test-kstrtox.c | 2 | ||||
-rw-r--r-- | lib/zlib_deflate/deflate.c | 143 | ||||
-rw-r--r-- | lib/zlib_inflate/inflate.c | 132 |
12 files changed, 437 insertions, 382 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index a8a775730c09..df872659ddd3 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
@@ -396,6 +396,39 @@ config CPU_RMAP | |||
396 | config DQL | 396 | config DQL |
397 | bool | 397 | bool |
398 | 398 | ||
399 | config GLOB | ||
400 | bool | ||
401 | # This actually supports modular compilation, but the module overhead | ||
402 | # is ridiculous for the amount of code involved. Until an out-of-tree | ||
403 | # driver asks for it, we'll just link it directly it into the kernel | ||
404 | # when required. Since we're ignoring out-of-tree users, there's also | ||
405 | # no need bother prompting for a manual decision: | ||
406 | # prompt "glob_match() function" | ||
407 | help | ||
408 | This option provides a glob_match function for performing | ||
409 | simple text pattern matching. It originated in the ATA code | ||
410 | to blacklist particular drive models, but other device drivers | ||
411 | may need similar functionality. | ||
412 | |||
413 | All drivers in the Linux kernel tree that require this function | ||
414 | should automatically select this option. Say N unless you | ||
415 | are compiling an out-of tree driver which tells you that it | ||
416 | depends on this. | ||
417 | |||
418 | config GLOB_SELFTEST | ||
419 | bool "glob self-test on init" | ||
420 | default n | ||
421 | depends on GLOB | ||
422 | help | ||
423 | This option enables a simple self-test of the glob_match | ||
424 | function on startup. It is primarily useful for people | ||
425 | working on the code to ensure they haven't introduced any | ||
426 | regressions. | ||
427 | |||
428 | It only adds a little bit of code and slows kernel boot (or | ||
429 | module load) by a small amount, so you're welcome to play with | ||
430 | it, but you probably don't need it. | ||
431 | |||
399 | # | 432 | # |
400 | # Netlink attribute parsing support is select'ed if needed | 433 | # Netlink attribute parsing support is select'ed if needed |
401 | # | 434 | # |
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index cfe7df8f62cc..cb45f59685e6 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
@@ -15,7 +15,7 @@ config PRINTK_TIME | |||
15 | The behavior is also controlled by the kernel command line | 15 | The behavior is also controlled by the kernel command line |
16 | parameter printk.time=1. See Documentation/kernel-parameters.txt | 16 | parameter printk.time=1. See Documentation/kernel-parameters.txt |
17 | 17 | ||
18 | config DEFAULT_MESSAGE_LOGLEVEL | 18 | config MESSAGE_LOGLEVEL_DEFAULT |
19 | int "Default message log level (1-7)" | 19 | int "Default message log level (1-7)" |
20 | range 1 7 | 20 | range 1 7 |
21 | default "4" | 21 | default "4" |
diff --git a/lib/Makefile b/lib/Makefile index 8427df95dade..d6b4bc496408 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -137,6 +137,8 @@ obj-$(CONFIG_CORDIC) += cordic.o | |||
137 | 137 | ||
138 | obj-$(CONFIG_DQL) += dynamic_queue_limits.o | 138 | obj-$(CONFIG_DQL) += dynamic_queue_limits.o |
139 | 139 | ||
140 | obj-$(CONFIG_GLOB) += glob.o | ||
141 | |||
140 | obj-$(CONFIG_MPILIB) += mpi/ | 142 | obj-$(CONFIG_MPILIB) += mpi/ |
141 | obj-$(CONFIG_SIGNATURE) += digsig.o | 143 | obj-$(CONFIG_SIGNATURE) += digsig.o |
142 | 144 | ||
diff --git a/lib/bitmap.c b/lib/bitmap.c index 06f7e4fe8d2d..1e031f2c9aba 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c | |||
@@ -40,9 +40,9 @@ | |||
40 | * for the best explanations of this ordering. | 40 | * for the best explanations of this ordering. |
41 | */ | 41 | */ |
42 | 42 | ||
43 | int __bitmap_empty(const unsigned long *bitmap, int bits) | 43 | int __bitmap_empty(const unsigned long *bitmap, unsigned int bits) |
44 | { | 44 | { |
45 | int k, lim = bits/BITS_PER_LONG; | 45 | unsigned int k, lim = bits/BITS_PER_LONG; |
46 | for (k = 0; k < lim; ++k) | 46 | for (k = 0; k < lim; ++k) |
47 | if (bitmap[k]) | 47 | if (bitmap[k]) |
48 | return 0; | 48 | return 0; |
@@ -55,9 +55,9 @@ int __bitmap_empty(const unsigned long *bitmap, int bits) | |||
55 | } | 55 | } |
56 | EXPORT_SYMBOL(__bitmap_empty); | 56 | EXPORT_SYMBOL(__bitmap_empty); |
57 | 57 | ||
58 | int __bitmap_full(const unsigned long *bitmap, int bits) | 58 | int __bitmap_full(const unsigned long *bitmap, unsigned int bits) |
59 | { | 59 | { |
60 | int k, lim = bits/BITS_PER_LONG; | 60 | unsigned int k, lim = bits/BITS_PER_LONG; |
61 | for (k = 0; k < lim; ++k) | 61 | for (k = 0; k < lim; ++k) |
62 | if (~bitmap[k]) | 62 | if (~bitmap[k]) |
63 | return 0; | 63 | return 0; |
@@ -71,9 +71,9 @@ int __bitmap_full(const unsigned long *bitmap, int bits) | |||
71 | EXPORT_SYMBOL(__bitmap_full); | 71 | EXPORT_SYMBOL(__bitmap_full); |
72 | 72 | ||
73 | int __bitmap_equal(const unsigned long *bitmap1, | 73 | int __bitmap_equal(const unsigned long *bitmap1, |
74 | const unsigned long *bitmap2, int bits) | 74 | const unsigned long *bitmap2, unsigned int bits) |
75 | { | 75 | { |
76 | int k, lim = bits/BITS_PER_LONG; | 76 | unsigned int k, lim = bits/BITS_PER_LONG; |
77 | for (k = 0; k < lim; ++k) | 77 | for (k = 0; k < lim; ++k) |
78 | if (bitmap1[k] != bitmap2[k]) | 78 | if (bitmap1[k] != bitmap2[k]) |
79 | return 0; | 79 | return 0; |
@@ -86,14 +86,14 @@ int __bitmap_equal(const unsigned long *bitmap1, | |||
86 | } | 86 | } |
87 | EXPORT_SYMBOL(__bitmap_equal); | 87 | EXPORT_SYMBOL(__bitmap_equal); |
88 | 88 | ||
89 | void __bitmap_complement(unsigned long *dst, const unsigned long *src, int bits) | 89 | void __bitmap_complement(unsigned long *dst, const unsigned long *src, unsigned int bits) |
90 | { | 90 | { |
91 | int k, lim = bits/BITS_PER_LONG; | 91 | unsigned int k, lim = bits/BITS_PER_LONG; |
92 | for (k = 0; k < lim; ++k) | 92 | for (k = 0; k < lim; ++k) |
93 | dst[k] = ~src[k]; | 93 | dst[k] = ~src[k]; |
94 | 94 | ||
95 | if (bits % BITS_PER_LONG) | 95 | if (bits % BITS_PER_LONG) |
96 | dst[k] = ~src[k] & BITMAP_LAST_WORD_MASK(bits); | 96 | dst[k] = ~src[k]; |
97 | } | 97 | } |
98 | EXPORT_SYMBOL(__bitmap_complement); | 98 | EXPORT_SYMBOL(__bitmap_complement); |
99 | 99 | ||
@@ -182,23 +182,26 @@ void __bitmap_shift_left(unsigned long *dst, | |||
182 | EXPORT_SYMBOL(__bitmap_shift_left); | 182 | EXPORT_SYMBOL(__bitmap_shift_left); |
183 | 183 | ||
184 | int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, | 184 | int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, |
185 | const unsigned long *bitmap2, int bits) | 185 | const unsigned long *bitmap2, unsigned int bits) |
186 | { | 186 | { |
187 | int k; | 187 | unsigned int k; |
188 | int nr = BITS_TO_LONGS(bits); | 188 | unsigned int lim = bits/BITS_PER_LONG; |
189 | unsigned long result = 0; | 189 | unsigned long result = 0; |
190 | 190 | ||
191 | for (k = 0; k < nr; k++) | 191 | for (k = 0; k < lim; k++) |
192 | result |= (dst[k] = bitmap1[k] & bitmap2[k]); | 192 | result |= (dst[k] = bitmap1[k] & bitmap2[k]); |
193 | if (bits % BITS_PER_LONG) | ||
194 | result |= (dst[k] = bitmap1[k] & bitmap2[k] & | ||
195 | BITMAP_LAST_WORD_MASK(bits)); | ||
193 | return result != 0; | 196 | return result != 0; |
194 | } | 197 | } |
195 | EXPORT_SYMBOL(__bitmap_and); | 198 | EXPORT_SYMBOL(__bitmap_and); |
196 | 199 | ||
197 | void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, | 200 | void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, |
198 | const unsigned long *bitmap2, int bits) | 201 | const unsigned long *bitmap2, unsigned int bits) |
199 | { | 202 | { |
200 | int k; | 203 | unsigned int k; |
201 | int nr = BITS_TO_LONGS(bits); | 204 | unsigned int nr = BITS_TO_LONGS(bits); |
202 | 205 | ||
203 | for (k = 0; k < nr; k++) | 206 | for (k = 0; k < nr; k++) |
204 | dst[k] = bitmap1[k] | bitmap2[k]; | 207 | dst[k] = bitmap1[k] | bitmap2[k]; |
@@ -206,10 +209,10 @@ void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, | |||
206 | EXPORT_SYMBOL(__bitmap_or); | 209 | EXPORT_SYMBOL(__bitmap_or); |
207 | 210 | ||
208 | void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1, | 211 | void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1, |
209 | const unsigned long *bitmap2, int bits) | 212 | const unsigned long *bitmap2, unsigned int bits) |
210 | { | 213 | { |
211 | int k; | 214 | unsigned int k; |
212 | int nr = BITS_TO_LONGS(bits); | 215 | unsigned int nr = BITS_TO_LONGS(bits); |
213 | 216 | ||
214 | for (k = 0; k < nr; k++) | 217 | for (k = 0; k < nr; k++) |
215 | dst[k] = bitmap1[k] ^ bitmap2[k]; | 218 | dst[k] = bitmap1[k] ^ bitmap2[k]; |
@@ -217,22 +220,25 @@ void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1, | |||
217 | EXPORT_SYMBOL(__bitmap_xor); | 220 | EXPORT_SYMBOL(__bitmap_xor); |
218 | 221 | ||
219 | int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1, | 222 | int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1, |
220 | const unsigned long *bitmap2, int bits) | 223 | const unsigned long *bitmap2, unsigned int bits) |
221 | { | 224 | { |
222 | int k; | 225 | unsigned int k; |
223 | int nr = BITS_TO_LONGS(bits); | 226 | unsigned int lim = bits/BITS_PER_LONG; |
224 | unsigned long result = 0; | 227 | unsigned long result = 0; |
225 | 228 | ||
226 | for (k = 0; k < nr; k++) | 229 | for (k = 0; k < lim; k++) |
227 | result |= (dst[k] = bitmap1[k] & ~bitmap2[k]); | 230 | result |= (dst[k] = bitmap1[k] & ~bitmap2[k]); |
231 | if (bits % BITS_PER_LONG) | ||
232 | result |= (dst[k] = bitmap1[k] & ~bitmap2[k] & | ||
233 | BITMAP_LAST_WORD_MASK(bits)); | ||
228 | return result != 0; | 234 | return result != 0; |
229 | } | 235 | } |
230 | EXPORT_SYMBOL(__bitmap_andnot); | 236 | EXPORT_SYMBOL(__bitmap_andnot); |
231 | 237 | ||
232 | int __bitmap_intersects(const unsigned long *bitmap1, | 238 | int __bitmap_intersects(const unsigned long *bitmap1, |
233 | const unsigned long *bitmap2, int bits) | 239 | const unsigned long *bitmap2, unsigned int bits) |
234 | { | 240 | { |
235 | int k, lim = bits/BITS_PER_LONG; | 241 | unsigned int k, lim = bits/BITS_PER_LONG; |
236 | for (k = 0; k < lim; ++k) | 242 | for (k = 0; k < lim; ++k) |
237 | if (bitmap1[k] & bitmap2[k]) | 243 | if (bitmap1[k] & bitmap2[k]) |
238 | return 1; | 244 | return 1; |
@@ -245,9 +251,9 @@ int __bitmap_intersects(const unsigned long *bitmap1, | |||
245 | EXPORT_SYMBOL(__bitmap_intersects); | 251 | EXPORT_SYMBOL(__bitmap_intersects); |
246 | 252 | ||
247 | int __bitmap_subset(const unsigned long *bitmap1, | 253 | int __bitmap_subset(const unsigned long *bitmap1, |
248 | const unsigned long *bitmap2, int bits) | 254 | const unsigned long *bitmap2, unsigned int bits) |
249 | { | 255 | { |
250 | int k, lim = bits/BITS_PER_LONG; | 256 | unsigned int k, lim = bits/BITS_PER_LONG; |
251 | for (k = 0; k < lim; ++k) | 257 | for (k = 0; k < lim; ++k) |
252 | if (bitmap1[k] & ~bitmap2[k]) | 258 | if (bitmap1[k] & ~bitmap2[k]) |
253 | return 0; | 259 | return 0; |
@@ -259,9 +265,10 @@ int __bitmap_subset(const unsigned long *bitmap1, | |||
259 | } | 265 | } |
260 | EXPORT_SYMBOL(__bitmap_subset); | 266 | EXPORT_SYMBOL(__bitmap_subset); |
261 | 267 | ||
262 | int __bitmap_weight(const unsigned long *bitmap, int bits) | 268 | int __bitmap_weight(const unsigned long *bitmap, unsigned int bits) |
263 | { | 269 | { |
264 | int k, w = 0, lim = bits/BITS_PER_LONG; | 270 | unsigned int k, lim = bits/BITS_PER_LONG; |
271 | int w = 0; | ||
265 | 272 | ||
266 | for (k = 0; k < lim; k++) | 273 | for (k = 0; k < lim; k++) |
267 | w += hweight_long(bitmap[k]); | 274 | w += hweight_long(bitmap[k]); |
@@ -273,42 +280,42 @@ int __bitmap_weight(const unsigned long *bitmap, int bits) | |||
273 | } | 280 | } |
274 | EXPORT_SYMBOL(__bitmap_weight); | 281 | EXPORT_SYMBOL(__bitmap_weight); |
275 | 282 | ||
276 | void bitmap_set(unsigned long *map, int start, int nr) | 283 | void bitmap_set(unsigned long *map, unsigned int start, int len) |
277 | { | 284 | { |
278 | unsigned long *p = map + BIT_WORD(start); | 285 | unsigned long *p = map + BIT_WORD(start); |
279 | const int size = start + nr; | 286 | const unsigned int size = start + len; |
280 | int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG); | 287 | int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG); |
281 | unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start); | 288 | unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start); |
282 | 289 | ||
283 | while (nr - bits_to_set >= 0) { | 290 | while (len - bits_to_set >= 0) { |
284 | *p |= mask_to_set; | 291 | *p |= mask_to_set; |
285 | nr -= bits_to_set; | 292 | len -= bits_to_set; |
286 | bits_to_set = BITS_PER_LONG; | 293 | bits_to_set = BITS_PER_LONG; |
287 | mask_to_set = ~0UL; | 294 | mask_to_set = ~0UL; |
288 | p++; | 295 | p++; |
289 | } | 296 | } |
290 | if (nr) { | 297 | if (len) { |
291 | mask_to_set &= BITMAP_LAST_WORD_MASK(size); | 298 | mask_to_set &= BITMAP_LAST_WORD_MASK(size); |
292 | *p |= mask_to_set; | 299 | *p |= mask_to_set; |
293 | } | 300 | } |
294 | } | 301 | } |
295 | EXPORT_SYMBOL(bitmap_set); | 302 | EXPORT_SYMBOL(bitmap_set); |
296 | 303 | ||
297 | void bitmap_clear(unsigned long *map, int start, int nr) | 304 | void bitmap_clear(unsigned long *map, unsigned int start, int len) |
298 | { | 305 | { |
299 | unsigned long *p = map + BIT_WORD(start); | 306 | unsigned long *p = map + BIT_WORD(start); |
300 | const int size = start + nr; | 307 | const unsigned int size = start + len; |
301 | int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG); | 308 | int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG); |
302 | unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start); | 309 | unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start); |
303 | 310 | ||
304 | while (nr - bits_to_clear >= 0) { | 311 | while (len - bits_to_clear >= 0) { |
305 | *p &= ~mask_to_clear; | 312 | *p &= ~mask_to_clear; |
306 | nr -= bits_to_clear; | 313 | len -= bits_to_clear; |
307 | bits_to_clear = BITS_PER_LONG; | 314 | bits_to_clear = BITS_PER_LONG; |
308 | mask_to_clear = ~0UL; | 315 | mask_to_clear = ~0UL; |
309 | p++; | 316 | p++; |
310 | } | 317 | } |
311 | if (nr) { | 318 | if (len) { |
312 | mask_to_clear &= BITMAP_LAST_WORD_MASK(size); | 319 | mask_to_clear &= BITMAP_LAST_WORD_MASK(size); |
313 | *p &= ~mask_to_clear; | 320 | *p &= ~mask_to_clear; |
314 | } | 321 | } |
@@ -664,13 +671,8 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, | |||
664 | 671 | ||
665 | int bitmap_parselist(const char *bp, unsigned long *maskp, int nmaskbits) | 672 | int bitmap_parselist(const char *bp, unsigned long *maskp, int nmaskbits) |
666 | { | 673 | { |
667 | char *nl = strchr(bp, '\n'); | 674 | char *nl = strchrnul(bp, '\n'); |
668 | int len; | 675 | int len = nl - bp; |
669 | |||
670 | if (nl) | ||
671 | len = nl - bp; | ||
672 | else | ||
673 | len = strlen(bp); | ||
674 | 676 | ||
675 | return __bitmap_parselist(bp, len, 0, maskp, nmaskbits); | 677 | return __bitmap_parselist(bp, len, 0, maskp, nmaskbits); |
676 | } | 678 | } |
@@ -716,7 +718,7 @@ EXPORT_SYMBOL(bitmap_parselist_user); | |||
716 | * | 718 | * |
717 | * If for example, just bits 4 through 7 are set in @buf, then @pos | 719 | * If for example, just bits 4 through 7 are set in @buf, then @pos |
718 | * values 4 through 7 will get mapped to 0 through 3, respectively, | 720 | * values 4 through 7 will get mapped to 0 through 3, respectively, |
719 | * and other @pos values will get mapped to 0. When @pos value 7 | 721 | * and other @pos values will get mapped to -1. When @pos value 7 |
720 | * gets mapped to (returns) @ord value 3 in this example, that means | 722 | * gets mapped to (returns) @ord value 3 in this example, that means |
721 | * that bit 7 is the 3rd (starting with 0th) set bit in @buf. | 723 | * that bit 7 is the 3rd (starting with 0th) set bit in @buf. |
722 | * | 724 | * |
@@ -1046,7 +1048,7 @@ enum { | |||
1046 | REG_OP_RELEASE, /* clear all bits in region */ | 1048 | REG_OP_RELEASE, /* clear all bits in region */ |
1047 | }; | 1049 | }; |
1048 | 1050 | ||
1049 | static int __reg_op(unsigned long *bitmap, int pos, int order, int reg_op) | 1051 | static int __reg_op(unsigned long *bitmap, unsigned int pos, int order, int reg_op) |
1050 | { | 1052 | { |
1051 | int nbits_reg; /* number of bits in region */ | 1053 | int nbits_reg; /* number of bits in region */ |
1052 | int index; /* index first long of region in bitmap */ | 1054 | int index; /* index first long of region in bitmap */ |
@@ -1112,11 +1114,11 @@ done: | |||
1112 | * Return the bit offset in bitmap of the allocated region, | 1114 | * Return the bit offset in bitmap of the allocated region, |
1113 | * or -errno on failure. | 1115 | * or -errno on failure. |
1114 | */ | 1116 | */ |
1115 | int bitmap_find_free_region(unsigned long *bitmap, int bits, int order) | 1117 | int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order) |
1116 | { | 1118 | { |
1117 | int pos, end; /* scans bitmap by regions of size order */ | 1119 | unsigned int pos, end; /* scans bitmap by regions of size order */ |
1118 | 1120 | ||
1119 | for (pos = 0 ; (end = pos + (1 << order)) <= bits; pos = end) { | 1121 | for (pos = 0 ; (end = pos + (1U << order)) <= bits; pos = end) { |
1120 | if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE)) | 1122 | if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE)) |
1121 | continue; | 1123 | continue; |
1122 | __reg_op(bitmap, pos, order, REG_OP_ALLOC); | 1124 | __reg_op(bitmap, pos, order, REG_OP_ALLOC); |
@@ -1137,7 +1139,7 @@ EXPORT_SYMBOL(bitmap_find_free_region); | |||
1137 | * | 1139 | * |
1138 | * No return value. | 1140 | * No return value. |
1139 | */ | 1141 | */ |
1140 | void bitmap_release_region(unsigned long *bitmap, int pos, int order) | 1142 | void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order) |
1141 | { | 1143 | { |
1142 | __reg_op(bitmap, pos, order, REG_OP_RELEASE); | 1144 | __reg_op(bitmap, pos, order, REG_OP_RELEASE); |
1143 | } | 1145 | } |
@@ -1154,12 +1156,11 @@ EXPORT_SYMBOL(bitmap_release_region); | |||
1154 | * Return 0 on success, or %-EBUSY if specified region wasn't | 1156 | * Return 0 on success, or %-EBUSY if specified region wasn't |
1155 | * free (not all bits were zero). | 1157 | * free (not all bits were zero). |
1156 | */ | 1158 | */ |
1157 | int bitmap_allocate_region(unsigned long *bitmap, int pos, int order) | 1159 | int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order) |
1158 | { | 1160 | { |
1159 | if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE)) | 1161 | if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE)) |
1160 | return -EBUSY; | 1162 | return -EBUSY; |
1161 | __reg_op(bitmap, pos, order, REG_OP_ALLOC); | 1163 | return __reg_op(bitmap, pos, order, REG_OP_ALLOC); |
1162 | return 0; | ||
1163 | } | 1164 | } |
1164 | EXPORT_SYMBOL(bitmap_allocate_region); | 1165 | EXPORT_SYMBOL(bitmap_allocate_region); |
1165 | 1166 | ||
diff --git a/lib/cmdline.c b/lib/cmdline.c index d4932f745e92..76a712e6e20e 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c | |||
@@ -121,11 +121,7 @@ EXPORT_SYMBOL(get_options); | |||
121 | * @retptr: (output) Optional pointer to next char after parse completes | 121 | * @retptr: (output) Optional pointer to next char after parse completes |
122 | * | 122 | * |
123 | * Parses a string into a number. The number stored at @ptr is | 123 | * Parses a string into a number. The number stored at @ptr is |
124 | * potentially suffixed with %K (for kilobytes, or 1024 bytes), | 124 | * potentially suffixed with K, M, G, T, P, E. |
125 | * %M (for megabytes, or 1048576 bytes), or %G (for gigabytes, or | ||
126 | * 1073741824). If the number is suffixed with K, M, or G, then | ||
127 | * the return value is the number multiplied by one kilobyte, one | ||
128 | * megabyte, or one gigabyte, respectively. | ||
129 | */ | 125 | */ |
130 | 126 | ||
131 | unsigned long long memparse(const char *ptr, char **retptr) | 127 | unsigned long long memparse(const char *ptr, char **retptr) |
@@ -135,6 +131,15 @@ unsigned long long memparse(const char *ptr, char **retptr) | |||
135 | unsigned long long ret = simple_strtoull(ptr, &endptr, 0); | 131 | unsigned long long ret = simple_strtoull(ptr, &endptr, 0); |
136 | 132 | ||
137 | switch (*endptr) { | 133 | switch (*endptr) { |
134 | case 'E': | ||
135 | case 'e': | ||
136 | ret <<= 10; | ||
137 | case 'P': | ||
138 | case 'p': | ||
139 | ret <<= 10; | ||
140 | case 'T': | ||
141 | case 't': | ||
142 | ret <<= 10; | ||
138 | case 'G': | 143 | case 'G': |
139 | case 'g': | 144 | case 'g': |
140 | ret <<= 10; | 145 | ret <<= 10; |
diff --git a/lib/glob.c b/lib/glob.c new file mode 100644 index 000000000000..500fc80d23e1 --- /dev/null +++ b/lib/glob.c | |||
@@ -0,0 +1,287 @@ | |||
1 | #include <linux/module.h> | ||
2 | #include <linux/glob.h> | ||
3 | |||
4 | /* | ||
5 | * The only reason this code can be compiled as a module is because the | ||
6 | * ATA code that depends on it can be as well. In practice, they're | ||
7 | * both usually compiled in and the module overhead goes away. | ||
8 | */ | ||
9 | MODULE_DESCRIPTION("glob(7) matching"); | ||
10 | MODULE_LICENSE("Dual MIT/GPL"); | ||
11 | |||
12 | /** | ||
13 | * glob_match - Shell-style pattern matching, like !fnmatch(pat, str, 0) | ||
14 | * @pat: Shell-style pattern to match, e.g. "*.[ch]". | ||
15 | * @str: String to match. The pattern must match the entire string. | ||
16 | * | ||
17 | * Perform shell-style glob matching, returning true (1) if the match | ||
18 | * succeeds, or false (0) if it fails. Equivalent to !fnmatch(@pat, @str, 0). | ||
19 | * | ||
20 | * Pattern metacharacters are ?, *, [ and \. | ||
21 | * (And, inside character classes, !, - and ].) | ||
22 | * | ||
23 | * This is small and simple implementation intended for device blacklists | ||
24 | * where a string is matched against a number of patterns. Thus, it | ||
25 | * does not preprocess the patterns. It is non-recursive, and run-time | ||
26 | * is at most quadratic: strlen(@str)*strlen(@pat). | ||
27 | * | ||
28 | * An example of the worst case is glob_match("*aaaaa", "aaaaaaaaaa"); | ||
29 | * it takes 6 passes over the pattern before matching the string. | ||
30 | * | ||
31 | * Like !fnmatch(@pat, @str, 0) and unlike the shell, this does NOT | ||
32 | * treat / or leading . specially; it isn't actually used for pathnames. | ||
33 | * | ||
34 | * Note that according to glob(7) (and unlike bash), character classes | ||
35 | * are complemented by a leading !; this does not support the regex-style | ||
36 | * [^a-z] syntax. | ||
37 | * | ||
38 | * An opening bracket without a matching close is matched literally. | ||
39 | */ | ||
40 | bool __pure glob_match(char const *pat, char const *str) | ||
41 | { | ||
42 | /* | ||
43 | * Backtrack to previous * on mismatch and retry starting one | ||
44 | * character later in the string. Because * matches all characters | ||
45 | * (no exception for /), it can be easily proved that there's | ||
46 | * never a need to backtrack multiple levels. | ||
47 | */ | ||
48 | char const *back_pat = NULL, *back_str = back_str; | ||
49 | |||
50 | /* | ||
51 | * Loop over each token (character or class) in pat, matching | ||
52 | * it against the remaining unmatched tail of str. Return false | ||
53 | * on mismatch, or true after matching the trailing nul bytes. | ||
54 | */ | ||
55 | for (;;) { | ||
56 | unsigned char c = *str++; | ||
57 | unsigned char d = *pat++; | ||
58 | |||
59 | switch (d) { | ||
60 | case '?': /* Wildcard: anything but nul */ | ||
61 | if (c == '\0') | ||
62 | return false; | ||
63 | break; | ||
64 | case '*': /* Any-length wildcard */ | ||
65 | if (*pat == '\0') /* Optimize trailing * case */ | ||
66 | return true; | ||
67 | back_pat = pat; | ||
68 | back_str = --str; /* Allow zero-length match */ | ||
69 | break; | ||
70 | case '[': { /* Character class */ | ||
71 | bool match = false, inverted = (*pat == '!'); | ||
72 | char const *class = pat + inverted; | ||
73 | unsigned char a = *class++; | ||
74 | |||
75 | /* | ||
76 | * Iterate over each span in the character class. | ||
77 | * A span is either a single character a, or a | ||
78 | * range a-b. The first span may begin with ']'. | ||
79 | */ | ||
80 | do { | ||
81 | unsigned char b = a; | ||
82 | |||
83 | if (a == '\0') /* Malformed */ | ||
84 | goto literal; | ||
85 | |||
86 | if (class[0] == '-' && class[1] != ']') { | ||
87 | b = class[1]; | ||
88 | |||
89 | if (b == '\0') | ||
90 | goto literal; | ||
91 | |||
92 | class += 2; | ||
93 | /* Any special action if a > b? */ | ||
94 | } | ||
95 | match |= (a <= c && c <= b); | ||
96 | } while ((a = *class++) != ']'); | ||
97 | |||
98 | if (match == inverted) | ||
99 | goto backtrack; | ||
100 | pat = class; | ||
101 | } | ||
102 | break; | ||
103 | case '\\': | ||
104 | d = *pat++; | ||
105 | /*FALLTHROUGH*/ | ||
106 | default: /* Literal character */ | ||
107 | literal: | ||
108 | if (c == d) { | ||
109 | if (d == '\0') | ||
110 | return true; | ||
111 | break; | ||
112 | } | ||
113 | backtrack: | ||
114 | if (c == '\0' || !back_pat) | ||
115 | return false; /* No point continuing */ | ||
116 | /* Try again from last *, one character later in str. */ | ||
117 | pat = back_pat; | ||
118 | str = ++back_str; | ||
119 | break; | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | EXPORT_SYMBOL(glob_match); | ||
124 | |||
125 | |||
126 | #ifdef CONFIG_GLOB_SELFTEST | ||
127 | |||
128 | #include <linux/printk.h> | ||
129 | #include <linux/moduleparam.h> | ||
130 | |||
131 | /* Boot with "glob.verbose=1" to show successful tests, too */ | ||
132 | static bool verbose = false; | ||
133 | module_param(verbose, bool, 0); | ||
134 | |||
135 | struct glob_test { | ||
136 | char const *pat, *str; | ||
137 | bool expected; | ||
138 | }; | ||
139 | |||
140 | static bool __pure __init test(char const *pat, char const *str, bool expected) | ||
141 | { | ||
142 | bool match = glob_match(pat, str); | ||
143 | bool success = match == expected; | ||
144 | |||
145 | /* Can't get string literals into a particular section, so... */ | ||
146 | static char const msg_error[] __initconst = | ||
147 | KERN_ERR "glob: \"%s\" vs. \"%s\": %s *** ERROR ***\n"; | ||
148 | static char const msg_ok[] __initconst = | ||
149 | KERN_DEBUG "glob: \"%s\" vs. \"%s\": %s OK\n"; | ||
150 | static char const mismatch[] __initconst = "mismatch"; | ||
151 | char const *message; | ||
152 | |||
153 | if (!success) | ||
154 | message = msg_error; | ||
155 | else if (verbose) | ||
156 | message = msg_ok; | ||
157 | else | ||
158 | return success; | ||
159 | |||
160 | printk(message, pat, str, mismatch + 3*match); | ||
161 | return success; | ||
162 | } | ||
163 | |||
164 | /* | ||
165 | * The tests are all jammed together in one array to make it simpler | ||
166 | * to place that array in the .init.rodata section. The obvious | ||
167 | * "array of structures containing char *" has no way to force the | ||
168 | * pointed-to strings to be in a particular section. | ||
169 | * | ||
170 | * Anyway, a test consists of: | ||
171 | * 1. Expected glob_match result: '1' or '0'. | ||
172 | * 2. Pattern to match: null-terminated string | ||
173 | * 3. String to match against: null-terminated string | ||
174 | * | ||
175 | * The list of tests is terminated with a final '\0' instead of | ||
176 | * a glob_match result character. | ||
177 | */ | ||
178 | static char const glob_tests[] __initconst = | ||
179 | /* Some basic tests */ | ||
180 | "1" "a\0" "a\0" | ||
181 | "0" "a\0" "b\0" | ||
182 | "0" "a\0" "aa\0" | ||
183 | "0" "a\0" "\0" | ||
184 | "1" "\0" "\0" | ||
185 | "0" "\0" "a\0" | ||
186 | /* Simple character class tests */ | ||
187 | "1" "[a]\0" "a\0" | ||
188 | "0" "[a]\0" "b\0" | ||
189 | "0" "[!a]\0" "a\0" | ||
190 | "1" "[!a]\0" "b\0" | ||
191 | "1" "[ab]\0" "a\0" | ||
192 | "1" "[ab]\0" "b\0" | ||
193 | "0" "[ab]\0" "c\0" | ||
194 | "1" "[!ab]\0" "c\0" | ||
195 | "1" "[a-c]\0" "b\0" | ||
196 | "0" "[a-c]\0" "d\0" | ||
197 | /* Corner cases in character class parsing */ | ||
198 | "1" "[a-c-e-g]\0" "-\0" | ||
199 | "0" "[a-c-e-g]\0" "d\0" | ||
200 | "1" "[a-c-e-g]\0" "f\0" | ||
201 | "1" "[]a-ceg-ik[]\0" "a\0" | ||
202 | "1" "[]a-ceg-ik[]\0" "]\0" | ||
203 | "1" "[]a-ceg-ik[]\0" "[\0" | ||
204 | "1" "[]a-ceg-ik[]\0" "h\0" | ||
205 | "0" "[]a-ceg-ik[]\0" "f\0" | ||
206 | "0" "[!]a-ceg-ik[]\0" "h\0" | ||
207 | "0" "[!]a-ceg-ik[]\0" "]\0" | ||
208 | "1" "[!]a-ceg-ik[]\0" "f\0" | ||
209 | /* Simple wild cards */ | ||
210 | "1" "?\0" "a\0" | ||
211 | "0" "?\0" "aa\0" | ||
212 | "0" "??\0" "a\0" | ||
213 | "1" "?x?\0" "axb\0" | ||
214 | "0" "?x?\0" "abx\0" | ||
215 | "0" "?x?\0" "xab\0" | ||
216 | /* Asterisk wild cards (backtracking) */ | ||
217 | "0" "*??\0" "a\0" | ||
218 | "1" "*??\0" "ab\0" | ||
219 | "1" "*??\0" "abc\0" | ||
220 | "1" "*??\0" "abcd\0" | ||
221 | "0" "??*\0" "a\0" | ||
222 | "1" "??*\0" "ab\0" | ||
223 | "1" "??*\0" "abc\0" | ||
224 | "1" "??*\0" "abcd\0" | ||
225 | "0" "?*?\0" "a\0" | ||
226 | "1" "?*?\0" "ab\0" | ||
227 | "1" "?*?\0" "abc\0" | ||
228 | "1" "?*?\0" "abcd\0" | ||
229 | "1" "*b\0" "b\0" | ||
230 | "1" "*b\0" "ab\0" | ||
231 | "0" "*b\0" "ba\0" | ||
232 | "1" "*b\0" "bb\0" | ||
233 | "1" "*b\0" "abb\0" | ||
234 | "1" "*b\0" "bab\0" | ||
235 | "1" "*bc\0" "abbc\0" | ||
236 | "1" "*bc\0" "bc\0" | ||
237 | "1" "*bc\0" "bbc\0" | ||
238 | "1" "*bc\0" "bcbc\0" | ||
239 | /* Multiple asterisks (complex backtracking) */ | ||
240 | "1" "*ac*\0" "abacadaeafag\0" | ||
241 | "1" "*ac*ae*ag*\0" "abacadaeafag\0" | ||
242 | "1" "*a*b*[bc]*[ef]*g*\0" "abacadaeafag\0" | ||
243 | "0" "*a*b*[ef]*[cd]*g*\0" "abacadaeafag\0" | ||
244 | "1" "*abcd*\0" "abcabcabcabcdefg\0" | ||
245 | "1" "*ab*cd*\0" "abcabcabcabcdefg\0" | ||
246 | "1" "*abcd*abcdef*\0" "abcabcdabcdeabcdefg\0" | ||
247 | "0" "*abcd*\0" "abcabcabcabcefg\0" | ||
248 | "0" "*ab*cd*\0" "abcabcabcabcefg\0"; | ||
249 | |||
250 | static int __init glob_init(void) | ||
251 | { | ||
252 | unsigned successes = 0; | ||
253 | unsigned n = 0; | ||
254 | char const *p = glob_tests; | ||
255 | static char const message[] __initconst = | ||
256 | KERN_INFO "glob: %u self-tests passed, %u failed\n"; | ||
257 | |||
258 | /* | ||
259 | * Tests are jammed together in a string. The first byte is '1' | ||
260 | * or '0' to indicate the expected outcome, or '\0' to indicate the | ||
261 | * end of the tests. Then come two null-terminated strings: the | ||
262 | * pattern and the string to match it against. | ||
263 | */ | ||
264 | while (*p) { | ||
265 | bool expected = *p++ & 1; | ||
266 | char const *pat = p; | ||
267 | |||
268 | p += strlen(p) + 1; | ||
269 | successes += test(pat, p, expected); | ||
270 | p += strlen(p) + 1; | ||
271 | n++; | ||
272 | } | ||
273 | |||
274 | n -= successes; | ||
275 | printk(message, successes, n); | ||
276 | |||
277 | /* What's the errno for "kernel bug detected"? Guess... */ | ||
278 | return n ? -ECANCELED : 0; | ||
279 | } | ||
280 | |||
281 | /* We need a dummy exit function to allow unload */ | ||
282 | static void __exit glob_fini(void) { } | ||
283 | |||
284 | module_init(glob_init); | ||
285 | module_exit(glob_fini); | ||
286 | |||
287 | #endif /* CONFIG_GLOB_SELFTEST */ | ||
diff --git a/lib/klist.c b/lib/klist.c index 358a368a2947..89b485a2a58d 100644 --- a/lib/klist.c +++ b/lib/klist.c | |||
@@ -140,11 +140,11 @@ void klist_add_tail(struct klist_node *n, struct klist *k) | |||
140 | EXPORT_SYMBOL_GPL(klist_add_tail); | 140 | EXPORT_SYMBOL_GPL(klist_add_tail); |
141 | 141 | ||
142 | /** | 142 | /** |
143 | * klist_add_after - Init a klist_node and add it after an existing node | 143 | * klist_add_behind - Init a klist_node and add it after an existing node |
144 | * @n: node we're adding. | 144 | * @n: node we're adding. |
145 | * @pos: node to put @n after | 145 | * @pos: node to put @n after |
146 | */ | 146 | */ |
147 | void klist_add_after(struct klist_node *n, struct klist_node *pos) | 147 | void klist_add_behind(struct klist_node *n, struct klist_node *pos) |
148 | { | 148 | { |
149 | struct klist *k = knode_klist(pos); | 149 | struct klist *k = knode_klist(pos); |
150 | 150 | ||
@@ -153,7 +153,7 @@ void klist_add_after(struct klist_node *n, struct klist_node *pos) | |||
153 | list_add(&n->n_node, &pos->n_node); | 153 | list_add(&n->n_node, &pos->n_node); |
154 | spin_unlock(&k->k_lock); | 154 | spin_unlock(&k->k_lock); |
155 | } | 155 | } |
156 | EXPORT_SYMBOL_GPL(klist_add_after); | 156 | EXPORT_SYMBOL_GPL(klist_add_behind); |
157 | 157 | ||
158 | /** | 158 | /** |
159 | * klist_add_before - Init a klist_node and add it before an existing node | 159 | * klist_add_before - Init a klist_node and add it before an existing node |
diff --git a/lib/list_sort.c b/lib/list_sort.c index 1183fa70a44d..12bcba1c8612 100644 --- a/lib/list_sort.c +++ b/lib/list_sort.c | |||
@@ -1,3 +1,6 @@ | |||
1 | |||
2 | #define pr_fmt(fmt) "list_sort_test: " fmt | ||
3 | |||
1 | #include <linux/kernel.h> | 4 | #include <linux/kernel.h> |
2 | #include <linux/module.h> | 5 | #include <linux/module.h> |
3 | #include <linux/list_sort.h> | 6 | #include <linux/list_sort.h> |
@@ -47,6 +50,7 @@ static void merge_and_restore_back_links(void *priv, | |||
47 | struct list_head *a, struct list_head *b) | 50 | struct list_head *a, struct list_head *b) |
48 | { | 51 | { |
49 | struct list_head *tail = head; | 52 | struct list_head *tail = head; |
53 | u8 count = 0; | ||
50 | 54 | ||
51 | while (a && b) { | 55 | while (a && b) { |
52 | /* if equal, take 'a' -- important for sort stability */ | 56 | /* if equal, take 'a' -- important for sort stability */ |
@@ -70,7 +74,8 @@ static void merge_and_restore_back_links(void *priv, | |||
70 | * element comparison is needed, so the client's cmp() | 74 | * element comparison is needed, so the client's cmp() |
71 | * routine can invoke cond_resched() periodically. | 75 | * routine can invoke cond_resched() periodically. |
72 | */ | 76 | */ |
73 | (*cmp)(priv, tail->next, tail->next); | 77 | if (unlikely(!(++count))) |
78 | (*cmp)(priv, tail->next, tail->next); | ||
74 | 79 | ||
75 | tail->next->prev = tail; | 80 | tail->next->prev = tail; |
76 | tail = tail->next; | 81 | tail = tail->next; |
@@ -123,9 +128,7 @@ void list_sort(void *priv, struct list_head *head, | |||
123 | } | 128 | } |
124 | if (lev > max_lev) { | 129 | if (lev > max_lev) { |
125 | if (unlikely(lev >= ARRAY_SIZE(part)-1)) { | 130 | if (unlikely(lev >= ARRAY_SIZE(part)-1)) { |
126 | printk_once(KERN_DEBUG "list passed to" | 131 | printk_once(KERN_DEBUG "list too long for efficiency\n"); |
127 | " list_sort() too long for" | ||
128 | " efficiency\n"); | ||
129 | lev--; | 132 | lev--; |
130 | } | 133 | } |
131 | max_lev = lev; | 134 | max_lev = lev; |
@@ -168,27 +171,25 @@ static struct debug_el **elts __initdata; | |||
168 | static int __init check(struct debug_el *ela, struct debug_el *elb) | 171 | static int __init check(struct debug_el *ela, struct debug_el *elb) |
169 | { | 172 | { |
170 | if (ela->serial >= TEST_LIST_LEN) { | 173 | if (ela->serial >= TEST_LIST_LEN) { |
171 | printk(KERN_ERR "list_sort_test: error: incorrect serial %d\n", | 174 | pr_err("error: incorrect serial %d\n", ela->serial); |
172 | ela->serial); | ||
173 | return -EINVAL; | 175 | return -EINVAL; |
174 | } | 176 | } |
175 | if (elb->serial >= TEST_LIST_LEN) { | 177 | if (elb->serial >= TEST_LIST_LEN) { |
176 | printk(KERN_ERR "list_sort_test: error: incorrect serial %d\n", | 178 | pr_err("error: incorrect serial %d\n", elb->serial); |
177 | elb->serial); | ||
178 | return -EINVAL; | 179 | return -EINVAL; |
179 | } | 180 | } |
180 | if (elts[ela->serial] != ela || elts[elb->serial] != elb) { | 181 | if (elts[ela->serial] != ela || elts[elb->serial] != elb) { |
181 | printk(KERN_ERR "list_sort_test: error: phantom element\n"); | 182 | pr_err("error: phantom element\n"); |
182 | return -EINVAL; | 183 | return -EINVAL; |
183 | } | 184 | } |
184 | if (ela->poison1 != TEST_POISON1 || ela->poison2 != TEST_POISON2) { | 185 | if (ela->poison1 != TEST_POISON1 || ela->poison2 != TEST_POISON2) { |
185 | printk(KERN_ERR "list_sort_test: error: bad poison: %#x/%#x\n", | 186 | pr_err("error: bad poison: %#x/%#x\n", |
186 | ela->poison1, ela->poison2); | 187 | ela->poison1, ela->poison2); |
187 | return -EINVAL; | 188 | return -EINVAL; |
188 | } | 189 | } |
189 | if (elb->poison1 != TEST_POISON1 || elb->poison2 != TEST_POISON2) { | 190 | if (elb->poison1 != TEST_POISON1 || elb->poison2 != TEST_POISON2) { |
190 | printk(KERN_ERR "list_sort_test: error: bad poison: %#x/%#x\n", | 191 | pr_err("error: bad poison: %#x/%#x\n", |
191 | elb->poison1, elb->poison2); | 192 | elb->poison1, elb->poison2); |
192 | return -EINVAL; | 193 | return -EINVAL; |
193 | } | 194 | } |
194 | return 0; | 195 | return 0; |
@@ -207,25 +208,23 @@ static int __init cmp(void *priv, struct list_head *a, struct list_head *b) | |||
207 | 208 | ||
208 | static int __init list_sort_test(void) | 209 | static int __init list_sort_test(void) |
209 | { | 210 | { |
210 | int i, count = 1, err = -EINVAL; | 211 | int i, count = 1, err = -ENOMEM; |
211 | struct debug_el *el; | 212 | struct debug_el *el; |
212 | struct list_head *cur, *tmp; | 213 | struct list_head *cur; |
213 | LIST_HEAD(head); | 214 | LIST_HEAD(head); |
214 | 215 | ||
215 | printk(KERN_DEBUG "list_sort_test: start testing list_sort()\n"); | 216 | pr_debug("start testing list_sort()\n"); |
216 | 217 | ||
217 | elts = kmalloc(sizeof(void *) * TEST_LIST_LEN, GFP_KERNEL); | 218 | elts = kcalloc(TEST_LIST_LEN, sizeof(*elts), GFP_KERNEL); |
218 | if (!elts) { | 219 | if (!elts) { |
219 | printk(KERN_ERR "list_sort_test: error: cannot allocate " | 220 | pr_err("error: cannot allocate memory\n"); |
220 | "memory\n"); | 221 | return err; |
221 | goto exit; | ||
222 | } | 222 | } |
223 | 223 | ||
224 | for (i = 0; i < TEST_LIST_LEN; i++) { | 224 | for (i = 0; i < TEST_LIST_LEN; i++) { |
225 | el = kmalloc(sizeof(*el), GFP_KERNEL); | 225 | el = kmalloc(sizeof(*el), GFP_KERNEL); |
226 | if (!el) { | 226 | if (!el) { |
227 | printk(KERN_ERR "list_sort_test: error: cannot " | 227 | pr_err("error: cannot allocate memory\n"); |
228 | "allocate memory\n"); | ||
229 | goto exit; | 228 | goto exit; |
230 | } | 229 | } |
231 | /* force some equivalencies */ | 230 | /* force some equivalencies */ |
@@ -239,52 +238,52 @@ static int __init list_sort_test(void) | |||
239 | 238 | ||
240 | list_sort(NULL, &head, cmp); | 239 | list_sort(NULL, &head, cmp); |
241 | 240 | ||
241 | err = -EINVAL; | ||
242 | for (cur = head.next; cur->next != &head; cur = cur->next) { | 242 | for (cur = head.next; cur->next != &head; cur = cur->next) { |
243 | struct debug_el *el1; | 243 | struct debug_el *el1; |
244 | int cmp_result; | 244 | int cmp_result; |
245 | 245 | ||
246 | if (cur->next->prev != cur) { | 246 | if (cur->next->prev != cur) { |
247 | printk(KERN_ERR "list_sort_test: error: list is " | 247 | pr_err("error: list is corrupted\n"); |
248 | "corrupted\n"); | ||
249 | goto exit; | 248 | goto exit; |
250 | } | 249 | } |
251 | 250 | ||
252 | cmp_result = cmp(NULL, cur, cur->next); | 251 | cmp_result = cmp(NULL, cur, cur->next); |
253 | if (cmp_result > 0) { | 252 | if (cmp_result > 0) { |
254 | printk(KERN_ERR "list_sort_test: error: list is not " | 253 | pr_err("error: list is not sorted\n"); |
255 | "sorted\n"); | ||
256 | goto exit; | 254 | goto exit; |
257 | } | 255 | } |
258 | 256 | ||
259 | el = container_of(cur, struct debug_el, list); | 257 | el = container_of(cur, struct debug_el, list); |
260 | el1 = container_of(cur->next, struct debug_el, list); | 258 | el1 = container_of(cur->next, struct debug_el, list); |
261 | if (cmp_result == 0 && el->serial >= el1->serial) { | 259 | if (cmp_result == 0 && el->serial >= el1->serial) { |
262 | printk(KERN_ERR "list_sort_test: error: order of " | 260 | pr_err("error: order of equivalent elements not " |
263 | "equivalent elements not preserved\n"); | 261 | "preserved\n"); |
264 | goto exit; | 262 | goto exit; |
265 | } | 263 | } |
266 | 264 | ||
267 | if (check(el, el1)) { | 265 | if (check(el, el1)) { |
268 | printk(KERN_ERR "list_sort_test: error: element check " | 266 | pr_err("error: element check failed\n"); |
269 | "failed\n"); | ||
270 | goto exit; | 267 | goto exit; |
271 | } | 268 | } |
272 | count++; | 269 | count++; |
273 | } | 270 | } |
271 | if (head.prev != cur) { | ||
272 | pr_err("error: list is corrupted\n"); | ||
273 | goto exit; | ||
274 | } | ||
275 | |||
274 | 276 | ||
275 | if (count != TEST_LIST_LEN) { | 277 | if (count != TEST_LIST_LEN) { |
276 | printk(KERN_ERR "list_sort_test: error: bad list length %d", | 278 | pr_err("error: bad list length %d", count); |
277 | count); | ||
278 | goto exit; | 279 | goto exit; |
279 | } | 280 | } |
280 | 281 | ||
281 | err = 0; | 282 | err = 0; |
282 | exit: | 283 | exit: |
284 | for (i = 0; i < TEST_LIST_LEN; i++) | ||
285 | kfree(elts[i]); | ||
283 | kfree(elts); | 286 | kfree(elts); |
284 | list_for_each_safe(cur, tmp, &head) { | ||
285 | list_del(cur); | ||
286 | kfree(container_of(cur, struct debug_el, list)); | ||
287 | } | ||
288 | return err; | 287 | return err; |
289 | } | 288 | } |
290 | module_init(list_sort_test); | 289 | module_init(list_sort_test); |
diff --git a/lib/string_helpers.c b/lib/string_helpers.c index ed5c1454dd62..29033f319aea 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c | |||
@@ -25,12 +25,15 @@ | |||
25 | int string_get_size(u64 size, const enum string_size_units units, | 25 | int string_get_size(u64 size, const enum string_size_units units, |
26 | char *buf, int len) | 26 | char *buf, int len) |
27 | { | 27 | { |
28 | static const char *units_10[] = { "B", "kB", "MB", "GB", "TB", "PB", | 28 | static const char *const units_10[] = { |
29 | "EB", "ZB", "YB", NULL}; | 29 | "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", NULL |
30 | static const char *units_2[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", | 30 | }; |
31 | "EiB", "ZiB", "YiB", NULL }; | 31 | static const char *const units_2[] = { |
32 | static const char **units_str[] = { | 32 | "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", |
33 | [STRING_UNITS_10] = units_10, | 33 | NULL |
34 | }; | ||
35 | static const char *const *const units_str[] = { | ||
36 | [STRING_UNITS_10] = units_10, | ||
34 | [STRING_UNITS_2] = units_2, | 37 | [STRING_UNITS_2] = units_2, |
35 | }; | 38 | }; |
36 | static const unsigned int divisor[] = { | 39 | static const unsigned int divisor[] = { |
diff --git a/lib/test-kstrtox.c b/lib/test-kstrtox.c index bea3f3fa3f02..4137bca5f8e8 100644 --- a/lib/test-kstrtox.c +++ b/lib/test-kstrtox.c | |||
@@ -3,7 +3,7 @@ | |||
3 | #include <linux/module.h> | 3 | #include <linux/module.h> |
4 | 4 | ||
5 | #define for_each_test(i, test) \ | 5 | #define for_each_test(i, test) \ |
6 | for (i = 0; i < sizeof(test) / sizeof(test[0]); i++) | 6 | for (i = 0; i < ARRAY_SIZE(test); i++) |
7 | 7 | ||
8 | struct test_fail { | 8 | struct test_fail { |
9 | const char *str; | 9 | const char *str; |
diff --git a/lib/zlib_deflate/deflate.c b/lib/zlib_deflate/deflate.c index d63381e8e333..d20ef458f137 100644 --- a/lib/zlib_deflate/deflate.c +++ b/lib/zlib_deflate/deflate.c | |||
@@ -250,52 +250,6 @@ int zlib_deflateInit2( | |||
250 | } | 250 | } |
251 | 251 | ||
252 | /* ========================================================================= */ | 252 | /* ========================================================================= */ |
253 | #if 0 | ||
254 | int zlib_deflateSetDictionary( | ||
255 | z_streamp strm, | ||
256 | const Byte *dictionary, | ||
257 | uInt dictLength | ||
258 | ) | ||
259 | { | ||
260 | deflate_state *s; | ||
261 | uInt length = dictLength; | ||
262 | uInt n; | ||
263 | IPos hash_head = 0; | ||
264 | |||
265 | if (strm == NULL || strm->state == NULL || dictionary == NULL) | ||
266 | return Z_STREAM_ERROR; | ||
267 | |||
268 | s = (deflate_state *) strm->state; | ||
269 | if (s->status != INIT_STATE) return Z_STREAM_ERROR; | ||
270 | |||
271 | strm->adler = zlib_adler32(strm->adler, dictionary, dictLength); | ||
272 | |||
273 | if (length < MIN_MATCH) return Z_OK; | ||
274 | if (length > MAX_DIST(s)) { | ||
275 | length = MAX_DIST(s); | ||
276 | #ifndef USE_DICT_HEAD | ||
277 | dictionary += dictLength - length; /* use the tail of the dictionary */ | ||
278 | #endif | ||
279 | } | ||
280 | memcpy((char *)s->window, dictionary, length); | ||
281 | s->strstart = length; | ||
282 | s->block_start = (long)length; | ||
283 | |||
284 | /* Insert all strings in the hash table (except for the last two bytes). | ||
285 | * s->lookahead stays null, so s->ins_h will be recomputed at the next | ||
286 | * call of fill_window. | ||
287 | */ | ||
288 | s->ins_h = s->window[0]; | ||
289 | UPDATE_HASH(s, s->ins_h, s->window[1]); | ||
290 | for (n = 0; n <= length - MIN_MATCH; n++) { | ||
291 | INSERT_STRING(s, n, hash_head); | ||
292 | } | ||
293 | if (hash_head) hash_head = 0; /* to make compiler happy */ | ||
294 | return Z_OK; | ||
295 | } | ||
296 | #endif /* 0 */ | ||
297 | |||
298 | /* ========================================================================= */ | ||
299 | int zlib_deflateReset( | 253 | int zlib_deflateReset( |
300 | z_streamp strm | 254 | z_streamp strm |
301 | ) | 255 | ) |
@@ -326,45 +280,6 @@ int zlib_deflateReset( | |||
326 | return Z_OK; | 280 | return Z_OK; |
327 | } | 281 | } |
328 | 282 | ||
329 | /* ========================================================================= */ | ||
330 | #if 0 | ||
331 | int zlib_deflateParams( | ||
332 | z_streamp strm, | ||
333 | int level, | ||
334 | int strategy | ||
335 | ) | ||
336 | { | ||
337 | deflate_state *s; | ||
338 | compress_func func; | ||
339 | int err = Z_OK; | ||
340 | |||
341 | if (strm == NULL || strm->state == NULL) return Z_STREAM_ERROR; | ||
342 | s = (deflate_state *) strm->state; | ||
343 | |||
344 | if (level == Z_DEFAULT_COMPRESSION) { | ||
345 | level = 6; | ||
346 | } | ||
347 | if (level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY) { | ||
348 | return Z_STREAM_ERROR; | ||
349 | } | ||
350 | func = configuration_table[s->level].func; | ||
351 | |||
352 | if (func != configuration_table[level].func && strm->total_in != 0) { | ||
353 | /* Flush the last buffer: */ | ||
354 | err = zlib_deflate(strm, Z_PARTIAL_FLUSH); | ||
355 | } | ||
356 | if (s->level != level) { | ||
357 | s->level = level; | ||
358 | s->max_lazy_match = configuration_table[level].max_lazy; | ||
359 | s->good_match = configuration_table[level].good_length; | ||
360 | s->nice_match = configuration_table[level].nice_length; | ||
361 | s->max_chain_length = configuration_table[level].max_chain; | ||
362 | } | ||
363 | s->strategy = strategy; | ||
364 | return err; | ||
365 | } | ||
366 | #endif /* 0 */ | ||
367 | |||
368 | /* ========================================================================= | 283 | /* ========================================================================= |
369 | * Put a short in the pending buffer. The 16-bit value is put in MSB order. | 284 | * Put a short in the pending buffer. The 16-bit value is put in MSB order. |
370 | * IN assertion: the stream state is correct and there is enough room in | 285 | * IN assertion: the stream state is correct and there is enough room in |
@@ -568,64 +483,6 @@ int zlib_deflateEnd( | |||
568 | return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; | 483 | return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; |
569 | } | 484 | } |
570 | 485 | ||
571 | /* ========================================================================= | ||
572 | * Copy the source state to the destination state. | ||
573 | */ | ||
574 | #if 0 | ||
575 | int zlib_deflateCopy ( | ||
576 | z_streamp dest, | ||
577 | z_streamp source | ||
578 | ) | ||
579 | { | ||
580 | #ifdef MAXSEG_64K | ||
581 | return Z_STREAM_ERROR; | ||
582 | #else | ||
583 | deflate_state *ds; | ||
584 | deflate_state *ss; | ||
585 | ush *overlay; | ||
586 | deflate_workspace *mem; | ||
587 | |||
588 | |||
589 | if (source == NULL || dest == NULL || source->state == NULL) { | ||
590 | return Z_STREAM_ERROR; | ||
591 | } | ||
592 | |||
593 | ss = (deflate_state *) source->state; | ||
594 | |||
595 | *dest = *source; | ||
596 | |||
597 | mem = (deflate_workspace *) dest->workspace; | ||
598 | |||
599 | ds = &(mem->deflate_memory); | ||
600 | |||
601 | dest->state = (struct internal_state *) ds; | ||
602 | *ds = *ss; | ||
603 | ds->strm = dest; | ||
604 | |||
605 | ds->window = (Byte *) mem->window_memory; | ||
606 | ds->prev = (Pos *) mem->prev_memory; | ||
607 | ds->head = (Pos *) mem->head_memory; | ||
608 | overlay = (ush *) mem->overlay_memory; | ||
609 | ds->pending_buf = (uch *) overlay; | ||
610 | |||
611 | memcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); | ||
612 | memcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos)); | ||
613 | memcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos)); | ||
614 | memcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); | ||
615 | |||
616 | ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); | ||
617 | ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); | ||
618 | ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; | ||
619 | |||
620 | ds->l_desc.dyn_tree = ds->dyn_ltree; | ||
621 | ds->d_desc.dyn_tree = ds->dyn_dtree; | ||
622 | ds->bl_desc.dyn_tree = ds->bl_tree; | ||
623 | |||
624 | return Z_OK; | ||
625 | #endif | ||
626 | } | ||
627 | #endif /* 0 */ | ||
628 | |||
629 | /* =========================================================================== | 486 | /* =========================================================================== |
630 | * Read a new buffer from the current input stream, update the adler32 | 487 | * Read a new buffer from the current input stream, update the adler32 |
631 | * and total number of bytes read. All deflate() input goes through | 488 | * and total number of bytes read. All deflate() input goes through |
diff --git a/lib/zlib_inflate/inflate.c b/lib/zlib_inflate/inflate.c index f5ce87b0800e..58a733b10387 100644 --- a/lib/zlib_inflate/inflate.c +++ b/lib/zlib_inflate/inflate.c | |||
@@ -45,21 +45,6 @@ int zlib_inflateReset(z_streamp strm) | |||
45 | return Z_OK; | 45 | return Z_OK; |
46 | } | 46 | } |
47 | 47 | ||
48 | #if 0 | ||
49 | int zlib_inflatePrime(z_streamp strm, int bits, int value) | ||
50 | { | ||
51 | struct inflate_state *state; | ||
52 | |||
53 | if (strm == NULL || strm->state == NULL) return Z_STREAM_ERROR; | ||
54 | state = (struct inflate_state *)strm->state; | ||
55 | if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; | ||
56 | value &= (1L << bits) - 1; | ||
57 | state->hold += value << state->bits; | ||
58 | state->bits += bits; | ||
59 | return Z_OK; | ||
60 | } | ||
61 | #endif | ||
62 | |||
63 | int zlib_inflateInit2(z_streamp strm, int windowBits) | 48 | int zlib_inflateInit2(z_streamp strm, int windowBits) |
64 | { | 49 | { |
65 | struct inflate_state *state; | 50 | struct inflate_state *state; |
@@ -761,123 +746,6 @@ int zlib_inflateEnd(z_streamp strm) | |||
761 | return Z_OK; | 746 | return Z_OK; |
762 | } | 747 | } |
763 | 748 | ||
764 | #if 0 | ||
765 | int zlib_inflateSetDictionary(z_streamp strm, const Byte *dictionary, | ||
766 | uInt dictLength) | ||
767 | { | ||
768 | struct inflate_state *state; | ||
769 | unsigned long id; | ||
770 | |||
771 | /* check state */ | ||
772 | if (strm == NULL || strm->state == NULL) return Z_STREAM_ERROR; | ||
773 | state = (struct inflate_state *)strm->state; | ||
774 | if (state->wrap != 0 && state->mode != DICT) | ||
775 | return Z_STREAM_ERROR; | ||
776 | |||
777 | /* check for correct dictionary id */ | ||
778 | if (state->mode == DICT) { | ||
779 | id = zlib_adler32(0L, NULL, 0); | ||
780 | id = zlib_adler32(id, dictionary, dictLength); | ||
781 | if (id != state->check) | ||
782 | return Z_DATA_ERROR; | ||
783 | } | ||
784 | |||
785 | /* copy dictionary to window */ | ||
786 | zlib_updatewindow(strm, strm->avail_out); | ||
787 | |||
788 | if (dictLength > state->wsize) { | ||
789 | memcpy(state->window, dictionary + dictLength - state->wsize, | ||
790 | state->wsize); | ||
791 | state->whave = state->wsize; | ||
792 | } | ||
793 | else { | ||
794 | memcpy(state->window + state->wsize - dictLength, dictionary, | ||
795 | dictLength); | ||
796 | state->whave = dictLength; | ||
797 | } | ||
798 | state->havedict = 1; | ||
799 | return Z_OK; | ||
800 | } | ||
801 | #endif | ||
802 | |||
803 | #if 0 | ||
804 | /* | ||
805 | Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found | ||
806 | or when out of input. When called, *have is the number of pattern bytes | ||
807 | found in order so far, in 0..3. On return *have is updated to the new | ||
808 | state. If on return *have equals four, then the pattern was found and the | ||
809 | return value is how many bytes were read including the last byte of the | ||
810 | pattern. If *have is less than four, then the pattern has not been found | ||
811 | yet and the return value is len. In the latter case, zlib_syncsearch() can be | ||
812 | called again with more data and the *have state. *have is initialized to | ||
813 | zero for the first call. | ||
814 | */ | ||
815 | static unsigned zlib_syncsearch(unsigned *have, unsigned char *buf, | ||
816 | unsigned len) | ||
817 | { | ||
818 | unsigned got; | ||
819 | unsigned next; | ||
820 | |||
821 | got = *have; | ||
822 | next = 0; | ||
823 | while (next < len && got < 4) { | ||
824 | if ((int)(buf[next]) == (got < 2 ? 0 : 0xff)) | ||
825 | got++; | ||
826 | else if (buf[next]) | ||
827 | got = 0; | ||
828 | else | ||
829 | got = 4 - got; | ||
830 | next++; | ||
831 | } | ||
832 | *have = got; | ||
833 | return next; | ||
834 | } | ||
835 | #endif | ||
836 | |||
837 | #if 0 | ||
838 | int zlib_inflateSync(z_streamp strm) | ||
839 | { | ||
840 | unsigned len; /* number of bytes to look at or looked at */ | ||
841 | unsigned long in, out; /* temporary to save total_in and total_out */ | ||
842 | unsigned char buf[4]; /* to restore bit buffer to byte string */ | ||
843 | struct inflate_state *state; | ||
844 | |||
845 | /* check parameters */ | ||
846 | if (strm == NULL || strm->state == NULL) return Z_STREAM_ERROR; | ||
847 | state = (struct inflate_state *)strm->state; | ||
848 | if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; | ||
849 | |||
850 | /* if first time, start search in bit buffer */ | ||
851 | if (state->mode != SYNC) { | ||
852 | state->mode = SYNC; | ||
853 | state->hold <<= state->bits & 7; | ||
854 | state->bits -= state->bits & 7; | ||
855 | len = 0; | ||
856 | while (state->bits >= 8) { | ||
857 | buf[len++] = (unsigned char)(state->hold); | ||
858 | state->hold >>= 8; | ||
859 | state->bits -= 8; | ||
860 | } | ||
861 | state->have = 0; | ||
862 | zlib_syncsearch(&(state->have), buf, len); | ||
863 | } | ||
864 | |||
865 | /* search available input */ | ||
866 | len = zlib_syncsearch(&(state->have), strm->next_in, strm->avail_in); | ||
867 | strm->avail_in -= len; | ||
868 | strm->next_in += len; | ||
869 | strm->total_in += len; | ||
870 | |||
871 | /* return no joy or set up to restart inflate() on a new block */ | ||
872 | if (state->have != 4) return Z_DATA_ERROR; | ||
873 | in = strm->total_in; out = strm->total_out; | ||
874 | zlib_inflateReset(strm); | ||
875 | strm->total_in = in; strm->total_out = out; | ||
876 | state->mode = TYPE; | ||
877 | return Z_OK; | ||
878 | } | ||
879 | #endif | ||
880 | |||
881 | /* | 749 | /* |
882 | * This subroutine adds the data at next_in/avail_in to the output history | 750 | * This subroutine adds the data at next_in/avail_in to the output history |
883 | * without performing any output. The output buffer must be "caught up"; | 751 | * without performing any output. The output buffer must be "caught up"; |