diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Kconfig | 40 | ||||
| -rw-r--r-- | lib/Kconfig.debug | 26 | ||||
| -rw-r--r-- | lib/Makefile | 2 | ||||
| -rw-r--r-- | lib/bitmap.c | 111 | ||||
| -rw-r--r-- | lib/cmdline.c | 15 | ||||
| -rw-r--r-- | lib/decompress.c | 2 | ||||
| -rw-r--r-- | lib/decompress_bunzip2.c | 26 | ||||
| -rw-r--r-- | lib/decompress_inflate.c | 12 | ||||
| -rw-r--r-- | lib/decompress_unlz4.c | 83 | ||||
| -rw-r--r-- | lib/decompress_unlzma.c | 28 | ||||
| -rw-r--r-- | lib/decompress_unlzo.c | 12 | ||||
| -rw-r--r-- | lib/decompress_unxz.c | 10 | ||||
| -rw-r--r-- | lib/glob.c | 287 | ||||
| -rw-r--r-- | lib/idr.c | 25 | ||||
| -rw-r--r-- | lib/kfifo.c | 6 | ||||
| -rw-r--r-- | lib/klist.c | 6 | ||||
| -rw-r--r-- | lib/list_sort.c | 71 | ||||
| -rw-r--r-- | lib/lru_cache.c | 23 | ||||
| -rw-r--r-- | lib/rbtree.c | 2 | ||||
| -rw-r--r-- | lib/rhashtable.c | 10 | ||||
| -rw-r--r-- | lib/scatterlist.c | 4 | ||||
| -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 |
25 files changed, 599 insertions, 494 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index a8a775730c09..a5ce0c7f6c30 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 | # |
| @@ -475,4 +508,11 @@ config UCS2_STRING | |||
| 475 | 508 | ||
| 476 | source "lib/fonts/Kconfig" | 509 | source "lib/fonts/Kconfig" |
| 477 | 510 | ||
| 511 | # | ||
| 512 | # sg chaining option | ||
| 513 | # | ||
| 514 | |||
| 515 | config ARCH_HAS_SG_CHAIN | ||
| 516 | def_bool n | ||
| 517 | |||
| 478 | endmenu | 518 | endmenu |
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index cfe7df8f62cc..07c28323f88f 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" |
| @@ -143,6 +143,30 @@ config DEBUG_INFO_REDUCED | |||
| 143 | DEBUG_INFO build and compile times are reduced too. | 143 | DEBUG_INFO build and compile times are reduced too. |
| 144 | Only works with newer gcc versions. | 144 | Only works with newer gcc versions. |
| 145 | 145 | ||
| 146 | config DEBUG_INFO_SPLIT | ||
| 147 | bool "Produce split debuginfo in .dwo files" | ||
| 148 | depends on DEBUG_INFO | ||
| 149 | help | ||
| 150 | Generate debug info into separate .dwo files. This significantly | ||
| 151 | reduces the build directory size for builds with DEBUG_INFO, | ||
| 152 | because it stores the information only once on disk in .dwo | ||
| 153 | files instead of multiple times in object files and executables. | ||
| 154 | In addition the debug information is also compressed. | ||
| 155 | |||
| 156 | Requires recent gcc (4.7+) and recent gdb/binutils. | ||
| 157 | Any tool that packages or reads debug information would need | ||
| 158 | to know about the .dwo files and include them. | ||
| 159 | Incompatible with older versions of ccache. | ||
| 160 | |||
| 161 | config DEBUG_INFO_DWARF4 | ||
| 162 | bool "Generate dwarf4 debuginfo" | ||
| 163 | depends on DEBUG_INFO | ||
| 164 | help | ||
| 165 | Generate dwarf4 debug info. This requires recent versions | ||
| 166 | of gcc and gdb. It makes the debug information larger. | ||
| 167 | But it significantly improves the success of resolving | ||
| 168 | variables in gdb on optimized code. | ||
| 169 | |||
| 146 | config ENABLE_WARN_DEPRECATED | 170 | config ENABLE_WARN_DEPRECATED |
| 147 | bool "Enable __deprecated logic" | 171 | bool "Enable __deprecated logic" |
| 148 | default y | 172 | default y |
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/decompress.c b/lib/decompress.c index 86069d74c062..37f3c786348f 100644 --- a/lib/decompress.c +++ b/lib/decompress.c | |||
| @@ -54,7 +54,7 @@ static const struct compress_format compressed_formats[] __initconst = { | |||
| 54 | { {0, 0}, NULL, NULL } | 54 | { {0, 0}, NULL, NULL } |
| 55 | }; | 55 | }; |
| 56 | 56 | ||
| 57 | decompress_fn __init decompress_method(const unsigned char *inbuf, int len, | 57 | decompress_fn __init decompress_method(const unsigned char *inbuf, long len, |
| 58 | const char **name) | 58 | const char **name) |
| 59 | { | 59 | { |
| 60 | const struct compress_format *cf; | 60 | const struct compress_format *cf; |
diff --git a/lib/decompress_bunzip2.c b/lib/decompress_bunzip2.c index 31c5f7675fbf..8290e0bef7ea 100644 --- a/lib/decompress_bunzip2.c +++ b/lib/decompress_bunzip2.c | |||
| @@ -92,8 +92,8 @@ struct bunzip_data { | |||
| 92 | /* State for interrupting output loop */ | 92 | /* State for interrupting output loop */ |
| 93 | int writeCopies, writePos, writeRunCountdown, writeCount, writeCurrent; | 93 | int writeCopies, writePos, writeRunCountdown, writeCount, writeCurrent; |
| 94 | /* I/O tracking data (file handles, buffers, positions, etc.) */ | 94 | /* I/O tracking data (file handles, buffers, positions, etc.) */ |
| 95 | int (*fill)(void*, unsigned int); | 95 | long (*fill)(void*, unsigned long); |
| 96 | int inbufCount, inbufPos /*, outbufPos*/; | 96 | long inbufCount, inbufPos /*, outbufPos*/; |
| 97 | unsigned char *inbuf /*,*outbuf*/; | 97 | unsigned char *inbuf /*,*outbuf*/; |
| 98 | unsigned int inbufBitCount, inbufBits; | 98 | unsigned int inbufBitCount, inbufBits; |
| 99 | /* The CRC values stored in the block header and calculated from the | 99 | /* The CRC values stored in the block header and calculated from the |
| @@ -617,7 +617,7 @@ decode_next_byte: | |||
| 617 | goto decode_next_byte; | 617 | goto decode_next_byte; |
| 618 | } | 618 | } |
| 619 | 619 | ||
| 620 | static int INIT nofill(void *buf, unsigned int len) | 620 | static long INIT nofill(void *buf, unsigned long len) |
| 621 | { | 621 | { |
| 622 | return -1; | 622 | return -1; |
| 623 | } | 623 | } |
| @@ -625,8 +625,8 @@ static int INIT nofill(void *buf, unsigned int len) | |||
| 625 | /* Allocate the structure, read file header. If in_fd ==-1, inbuf must contain | 625 | /* Allocate the structure, read file header. If in_fd ==-1, inbuf must contain |
| 626 | a complete bunzip file (len bytes long). If in_fd!=-1, inbuf and len are | 626 | a complete bunzip file (len bytes long). If in_fd!=-1, inbuf and len are |
| 627 | ignored, and data is read from file handle into temporary buffer. */ | 627 | ignored, and data is read from file handle into temporary buffer. */ |
| 628 | static int INIT start_bunzip(struct bunzip_data **bdp, void *inbuf, int len, | 628 | static int INIT start_bunzip(struct bunzip_data **bdp, void *inbuf, long len, |
| 629 | int (*fill)(void*, unsigned int)) | 629 | long (*fill)(void*, unsigned long)) |
| 630 | { | 630 | { |
| 631 | struct bunzip_data *bd; | 631 | struct bunzip_data *bd; |
| 632 | unsigned int i, j, c; | 632 | unsigned int i, j, c; |
| @@ -675,11 +675,11 @@ static int INIT start_bunzip(struct bunzip_data **bdp, void *inbuf, int len, | |||
| 675 | 675 | ||
| 676 | /* Example usage: decompress src_fd to dst_fd. (Stops at end of bzip2 data, | 676 | /* Example usage: decompress src_fd to dst_fd. (Stops at end of bzip2 data, |
| 677 | not end of file.) */ | 677 | not end of file.) */ |
| 678 | STATIC int INIT bunzip2(unsigned char *buf, int len, | 678 | STATIC int INIT bunzip2(unsigned char *buf, long len, |
| 679 | int(*fill)(void*, unsigned int), | 679 | long (*fill)(void*, unsigned long), |
| 680 | int(*flush)(void*, unsigned int), | 680 | long (*flush)(void*, unsigned long), |
| 681 | unsigned char *outbuf, | 681 | unsigned char *outbuf, |
| 682 | int *pos, | 682 | long *pos, |
| 683 | void(*error)(char *x)) | 683 | void(*error)(char *x)) |
| 684 | { | 684 | { |
| 685 | struct bunzip_data *bd; | 685 | struct bunzip_data *bd; |
| @@ -743,11 +743,11 @@ exit_0: | |||
| 743 | } | 743 | } |
| 744 | 744 | ||
| 745 | #ifdef PREBOOT | 745 | #ifdef PREBOOT |
| 746 | STATIC int INIT decompress(unsigned char *buf, int len, | 746 | STATIC int INIT decompress(unsigned char *buf, long len, |
| 747 | int(*fill)(void*, unsigned int), | 747 | long (*fill)(void*, unsigned long), |
| 748 | int(*flush)(void*, unsigned int), | 748 | long (*flush)(void*, unsigned long), |
| 749 | unsigned char *outbuf, | 749 | unsigned char *outbuf, |
| 750 | int *pos, | 750 | long *pos, |
| 751 | void(*error)(char *x)) | 751 | void(*error)(char *x)) |
| 752 | { | 752 | { |
| 753 | return bunzip2(buf, len - 4, fill, flush, outbuf, pos, error); | 753 | return bunzip2(buf, len - 4, fill, flush, outbuf, pos, error); |
diff --git a/lib/decompress_inflate.c b/lib/decompress_inflate.c index 0edfd742a154..d4c7891635ec 100644 --- a/lib/decompress_inflate.c +++ b/lib/decompress_inflate.c | |||
| @@ -27,17 +27,17 @@ | |||
| 27 | 27 | ||
| 28 | #define GZIP_IOBUF_SIZE (16*1024) | 28 | #define GZIP_IOBUF_SIZE (16*1024) |
| 29 | 29 | ||
| 30 | static int INIT nofill(void *buffer, unsigned int len) | 30 | static long INIT nofill(void *buffer, unsigned long len) |
| 31 | { | 31 | { |
| 32 | return -1; | 32 | return -1; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | /* Included from initramfs et al code */ | 35 | /* Included from initramfs et al code */ |
| 36 | STATIC int INIT gunzip(unsigned char *buf, int len, | 36 | STATIC int INIT gunzip(unsigned char *buf, long len, |
| 37 | int(*fill)(void*, unsigned int), | 37 | long (*fill)(void*, unsigned long), |
| 38 | int(*flush)(void*, unsigned int), | 38 | long (*flush)(void*, unsigned long), |
| 39 | unsigned char *out_buf, | 39 | unsigned char *out_buf, |
| 40 | int *pos, | 40 | long *pos, |
| 41 | void(*error)(char *x)) { | 41 | void(*error)(char *x)) { |
| 42 | u8 *zbuf; | 42 | u8 *zbuf; |
| 43 | struct z_stream_s *strm; | 43 | struct z_stream_s *strm; |
| @@ -142,7 +142,7 @@ STATIC int INIT gunzip(unsigned char *buf, int len, | |||
| 142 | 142 | ||
| 143 | /* Write any data generated */ | 143 | /* Write any data generated */ |
| 144 | if (flush && strm->next_out > out_buf) { | 144 | if (flush && strm->next_out > out_buf) { |
| 145 | int l = strm->next_out - out_buf; | 145 | long l = strm->next_out - out_buf; |
| 146 | if (l != flush(out_buf, l)) { | 146 | if (l != flush(out_buf, l)) { |
| 147 | rc = -1; | 147 | rc = -1; |
| 148 | error("write error"); | 148 | error("write error"); |
diff --git a/lib/decompress_unlz4.c b/lib/decompress_unlz4.c index 7d1e83caf8ad..40f66ebe57b7 100644 --- a/lib/decompress_unlz4.c +++ b/lib/decompress_unlz4.c | |||
| @@ -31,10 +31,10 @@ | |||
| 31 | #define LZ4_DEFAULT_UNCOMPRESSED_CHUNK_SIZE (8 << 20) | 31 | #define LZ4_DEFAULT_UNCOMPRESSED_CHUNK_SIZE (8 << 20) |
| 32 | #define ARCHIVE_MAGICNUMBER 0x184C2102 | 32 | #define ARCHIVE_MAGICNUMBER 0x184C2102 |
| 33 | 33 | ||
| 34 | STATIC inline int INIT unlz4(u8 *input, int in_len, | 34 | STATIC inline int INIT unlz4(u8 *input, long in_len, |
| 35 | int (*fill) (void *, unsigned int), | 35 | long (*fill)(void *, unsigned long), |
| 36 | int (*flush) (void *, unsigned int), | 36 | long (*flush)(void *, unsigned long), |
| 37 | u8 *output, int *posp, | 37 | u8 *output, long *posp, |
| 38 | void (*error) (char *x)) | 38 | void (*error) (char *x)) |
| 39 | { | 39 | { |
| 40 | int ret = -1; | 40 | int ret = -1; |
| @@ -43,7 +43,7 @@ STATIC inline int INIT unlz4(u8 *input, int in_len, | |||
| 43 | u8 *inp; | 43 | u8 *inp; |
| 44 | u8 *inp_start; | 44 | u8 *inp_start; |
| 45 | u8 *outp; | 45 | u8 *outp; |
| 46 | int size = in_len; | 46 | long size = in_len; |
| 47 | #ifdef PREBOOT | 47 | #ifdef PREBOOT |
| 48 | size_t out_len = get_unaligned_le32(input + in_len); | 48 | size_t out_len = get_unaligned_le32(input + in_len); |
| 49 | #endif | 49 | #endif |
| @@ -83,13 +83,20 @@ STATIC inline int INIT unlz4(u8 *input, int in_len, | |||
| 83 | if (posp) | 83 | if (posp) |
| 84 | *posp = 0; | 84 | *posp = 0; |
| 85 | 85 | ||
| 86 | if (fill) | 86 | if (fill) { |
| 87 | fill(inp, 4); | 87 | size = fill(inp, 4); |
| 88 | if (size < 4) { | ||
| 89 | error("data corrupted"); | ||
| 90 | goto exit_2; | ||
| 91 | } | ||
| 92 | } | ||
| 88 | 93 | ||
| 89 | chunksize = get_unaligned_le32(inp); | 94 | chunksize = get_unaligned_le32(inp); |
| 90 | if (chunksize == ARCHIVE_MAGICNUMBER) { | 95 | if (chunksize == ARCHIVE_MAGICNUMBER) { |
| 91 | inp += 4; | 96 | if (!fill) { |
| 92 | size -= 4; | 97 | inp += 4; |
| 98 | size -= 4; | ||
| 99 | } | ||
| 93 | } else { | 100 | } else { |
| 94 | error("invalid header"); | 101 | error("invalid header"); |
| 95 | goto exit_2; | 102 | goto exit_2; |
| @@ -100,29 +107,44 @@ STATIC inline int INIT unlz4(u8 *input, int in_len, | |||
| 100 | 107 | ||
| 101 | for (;;) { | 108 | for (;;) { |
| 102 | 109 | ||
| 103 | if (fill) | 110 | if (fill) { |
| 104 | fill(inp, 4); | 111 | size = fill(inp, 4); |
| 112 | if (size == 0) | ||
| 113 | break; | ||
| 114 | if (size < 4) { | ||
| 115 | error("data corrupted"); | ||
| 116 | goto exit_2; | ||
| 117 | } | ||
| 118 | } | ||
| 105 | 119 | ||
| 106 | chunksize = get_unaligned_le32(inp); | 120 | chunksize = get_unaligned_le32(inp); |
| 107 | if (chunksize == ARCHIVE_MAGICNUMBER) { | 121 | if (chunksize == ARCHIVE_MAGICNUMBER) { |
| 108 | inp += 4; | 122 | if (!fill) { |
| 109 | size -= 4; | 123 | inp += 4; |
| 124 | size -= 4; | ||
| 125 | } | ||
| 110 | if (posp) | 126 | if (posp) |
| 111 | *posp += 4; | 127 | *posp += 4; |
| 112 | continue; | 128 | continue; |
| 113 | } | 129 | } |
| 114 | inp += 4; | 130 | |
| 115 | size -= 4; | ||
| 116 | 131 | ||
| 117 | if (posp) | 132 | if (posp) |
| 118 | *posp += 4; | 133 | *posp += 4; |
| 119 | 134 | ||
| 120 | if (fill) { | 135 | if (!fill) { |
| 136 | inp += 4; | ||
| 137 | size -= 4; | ||
| 138 | } else { | ||
| 121 | if (chunksize > lz4_compressbound(uncomp_chunksize)) { | 139 | if (chunksize > lz4_compressbound(uncomp_chunksize)) { |
| 122 | error("chunk length is longer than allocated"); | 140 | error("chunk length is longer than allocated"); |
| 123 | goto exit_2; | 141 | goto exit_2; |
| 124 | } | 142 | } |
| 125 | fill(inp, chunksize); | 143 | size = fill(inp, chunksize); |
| 144 | if (size < chunksize) { | ||
| 145 | error("data corrupted"); | ||
| 146 | goto exit_2; | ||
| 147 | } | ||
| 126 | } | 148 | } |
| 127 | #ifdef PREBOOT | 149 | #ifdef PREBOOT |
| 128 | if (out_len >= uncomp_chunksize) { | 150 | if (out_len >= uncomp_chunksize) { |
| @@ -149,18 +171,17 @@ STATIC inline int INIT unlz4(u8 *input, int in_len, | |||
| 149 | if (posp) | 171 | if (posp) |
| 150 | *posp += chunksize; | 172 | *posp += chunksize; |
| 151 | 173 | ||
| 152 | size -= chunksize; | 174 | if (!fill) { |
| 175 | size -= chunksize; | ||
| 153 | 176 | ||
| 154 | if (size == 0) | 177 | if (size == 0) |
| 155 | break; | 178 | break; |
| 156 | else if (size < 0) { | 179 | else if (size < 0) { |
| 157 | error("data corrupted"); | 180 | error("data corrupted"); |
| 158 | goto exit_2; | 181 | goto exit_2; |
| 182 | } | ||
| 183 | inp += chunksize; | ||
| 159 | } | 184 | } |
| 160 | |||
| 161 | inp += chunksize; | ||
| 162 | if (fill) | ||
| 163 | inp = inp_start; | ||
| 164 | } | 185 | } |
| 165 | 186 | ||
| 166 | ret = 0; | 187 | ret = 0; |
| @@ -175,11 +196,11 @@ exit_0: | |||
| 175 | } | 196 | } |
| 176 | 197 | ||
| 177 | #ifdef PREBOOT | 198 | #ifdef PREBOOT |
| 178 | STATIC int INIT decompress(unsigned char *buf, int in_len, | 199 | STATIC int INIT decompress(unsigned char *buf, long in_len, |
| 179 | int(*fill)(void*, unsigned int), | 200 | long (*fill)(void*, unsigned long), |
| 180 | int(*flush)(void*, unsigned int), | 201 | long (*flush)(void*, unsigned long), |
| 181 | unsigned char *output, | 202 | unsigned char *output, |
| 182 | int *posp, | 203 | long *posp, |
| 183 | void(*error)(char *x) | 204 | void(*error)(char *x) |
| 184 | ) | 205 | ) |
| 185 | { | 206 | { |
diff --git a/lib/decompress_unlzma.c b/lib/decompress_unlzma.c index 32adb73a9038..0be83af62b88 100644 --- a/lib/decompress_unlzma.c +++ b/lib/decompress_unlzma.c | |||
| @@ -65,11 +65,11 @@ static long long INIT read_int(unsigned char *ptr, int size) | |||
| 65 | #define LZMA_IOBUF_SIZE 0x10000 | 65 | #define LZMA_IOBUF_SIZE 0x10000 |
| 66 | 66 | ||
| 67 | struct rc { | 67 | struct rc { |
| 68 | int (*fill)(void*, unsigned int); | 68 | long (*fill)(void*, unsigned long); |
| 69 | uint8_t *ptr; | 69 | uint8_t *ptr; |
| 70 | uint8_t *buffer; | 70 | uint8_t *buffer; |
| 71 | uint8_t *buffer_end; | 71 | uint8_t *buffer_end; |
| 72 | int buffer_size; | 72 | long buffer_size; |
| 73 | uint32_t code; | 73 | uint32_t code; |
| 74 | uint32_t range; | 74 | uint32_t range; |
| 75 | uint32_t bound; | 75 | uint32_t bound; |
| @@ -82,7 +82,7 @@ struct rc { | |||
| 82 | #define RC_MODEL_TOTAL_BITS 11 | 82 | #define RC_MODEL_TOTAL_BITS 11 |
| 83 | 83 | ||
| 84 | 84 | ||
| 85 | static int INIT nofill(void *buffer, unsigned int len) | 85 | static long INIT nofill(void *buffer, unsigned long len) |
| 86 | { | 86 | { |
| 87 | return -1; | 87 | return -1; |
| 88 | } | 88 | } |
| @@ -99,8 +99,8 @@ static void INIT rc_read(struct rc *rc) | |||
| 99 | 99 | ||
| 100 | /* Called once */ | 100 | /* Called once */ |
| 101 | static inline void INIT rc_init(struct rc *rc, | 101 | static inline void INIT rc_init(struct rc *rc, |
| 102 | int (*fill)(void*, unsigned int), | 102 | long (*fill)(void*, unsigned long), |
| 103 | char *buffer, int buffer_size) | 103 | char *buffer, long buffer_size) |
| 104 | { | 104 | { |
| 105 | if (fill) | 105 | if (fill) |
| 106 | rc->fill = fill; | 106 | rc->fill = fill; |
| @@ -280,7 +280,7 @@ struct writer { | |||
| 280 | size_t buffer_pos; | 280 | size_t buffer_pos; |
| 281 | int bufsize; | 281 | int bufsize; |
| 282 | size_t global_pos; | 282 | size_t global_pos; |
| 283 | int(*flush)(void*, unsigned int); | 283 | long (*flush)(void*, unsigned long); |
| 284 | struct lzma_header *header; | 284 | struct lzma_header *header; |
| 285 | }; | 285 | }; |
| 286 | 286 | ||
| @@ -534,11 +534,11 @@ static inline int INIT process_bit1(struct writer *wr, struct rc *rc, | |||
| 534 | 534 | ||
| 535 | 535 | ||
| 536 | 536 | ||
| 537 | STATIC inline int INIT unlzma(unsigned char *buf, int in_len, | 537 | STATIC inline int INIT unlzma(unsigned char *buf, long in_len, |
| 538 | int(*fill)(void*, unsigned int), | 538 | long (*fill)(void*, unsigned long), |
| 539 | int(*flush)(void*, unsigned int), | 539 | long (*flush)(void*, unsigned long), |
| 540 | unsigned char *output, | 540 | unsigned char *output, |
| 541 | int *posp, | 541 | long *posp, |
| 542 | void(*error)(char *x) | 542 | void(*error)(char *x) |
| 543 | ) | 543 | ) |
| 544 | { | 544 | { |
| @@ -667,11 +667,11 @@ exit_0: | |||
| 667 | } | 667 | } |
| 668 | 668 | ||
| 669 | #ifdef PREBOOT | 669 | #ifdef PREBOOT |
| 670 | STATIC int INIT decompress(unsigned char *buf, int in_len, | 670 | STATIC int INIT decompress(unsigned char *buf, long in_len, |
| 671 | int(*fill)(void*, unsigned int), | 671 | long (*fill)(void*, unsigned long), |
| 672 | int(*flush)(void*, unsigned int), | 672 | long (*flush)(void*, unsigned long), |
| 673 | unsigned char *output, | 673 | unsigned char *output, |
| 674 | int *posp, | 674 | long *posp, |
| 675 | void(*error)(char *x) | 675 | void(*error)(char *x) |
| 676 | ) | 676 | ) |
| 677 | { | 677 | { |
diff --git a/lib/decompress_unlzo.c b/lib/decompress_unlzo.c index 960183d4258f..b94a31bdd87d 100644 --- a/lib/decompress_unlzo.c +++ b/lib/decompress_unlzo.c | |||
| @@ -51,7 +51,7 @@ static const unsigned char lzop_magic[] = { | |||
| 51 | #define HEADER_SIZE_MIN (9 + 7 + 4 + 8 + 1 + 4) | 51 | #define HEADER_SIZE_MIN (9 + 7 + 4 + 8 + 1 + 4) |
| 52 | #define HEADER_SIZE_MAX (9 + 7 + 1 + 8 + 8 + 4 + 1 + 255 + 4) | 52 | #define HEADER_SIZE_MAX (9 + 7 + 1 + 8 + 8 + 4 + 1 + 255 + 4) |
| 53 | 53 | ||
| 54 | STATIC inline int INIT parse_header(u8 *input, int *skip, int in_len) | 54 | STATIC inline long INIT parse_header(u8 *input, long *skip, long in_len) |
| 55 | { | 55 | { |
| 56 | int l; | 56 | int l; |
| 57 | u8 *parse = input; | 57 | u8 *parse = input; |
| @@ -108,14 +108,14 @@ STATIC inline int INIT parse_header(u8 *input, int *skip, int in_len) | |||
| 108 | return 1; | 108 | return 1; |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | STATIC inline int INIT unlzo(u8 *input, int in_len, | 111 | STATIC int INIT unlzo(u8 *input, long in_len, |
| 112 | int (*fill) (void *, unsigned int), | 112 | long (*fill)(void *, unsigned long), |
| 113 | int (*flush) (void *, unsigned int), | 113 | long (*flush)(void *, unsigned long), |
| 114 | u8 *output, int *posp, | 114 | u8 *output, long *posp, |
| 115 | void (*error) (char *x)) | 115 | void (*error) (char *x)) |
| 116 | { | 116 | { |
| 117 | u8 r = 0; | 117 | u8 r = 0; |
| 118 | int skip = 0; | 118 | long skip = 0; |
| 119 | u32 src_len, dst_len; | 119 | u32 src_len, dst_len; |
| 120 | size_t tmp; | 120 | size_t tmp; |
| 121 | u8 *in_buf, *in_buf_save, *out_buf; | 121 | u8 *in_buf, *in_buf_save, *out_buf; |
diff --git a/lib/decompress_unxz.c b/lib/decompress_unxz.c index 9f34eb56854d..b07a78340e9d 100644 --- a/lib/decompress_unxz.c +++ b/lib/decompress_unxz.c | |||
| @@ -248,10 +248,10 @@ void *memmove(void *dest, const void *src, size_t size) | |||
| 248 | * both input and output buffers are available as a single chunk, i.e. when | 248 | * both input and output buffers are available as a single chunk, i.e. when |
| 249 | * fill() and flush() won't be used. | 249 | * fill() and flush() won't be used. |
| 250 | */ | 250 | */ |
| 251 | STATIC int INIT unxz(unsigned char *in, int in_size, | 251 | STATIC int INIT unxz(unsigned char *in, long in_size, |
| 252 | int (*fill)(void *dest, unsigned int size), | 252 | long (*fill)(void *dest, unsigned long size), |
| 253 | int (*flush)(void *src, unsigned int size), | 253 | long (*flush)(void *src, unsigned long size), |
| 254 | unsigned char *out, int *in_used, | 254 | unsigned char *out, long *in_used, |
| 255 | void (*error)(char *x)) | 255 | void (*error)(char *x)) |
| 256 | { | 256 | { |
| 257 | struct xz_buf b; | 257 | struct xz_buf b; |
| @@ -329,7 +329,7 @@ STATIC int INIT unxz(unsigned char *in, int in_size, | |||
| 329 | * returned by xz_dec_run(), but probably | 329 | * returned by xz_dec_run(), but probably |
| 330 | * it's not too bad. | 330 | * it's not too bad. |
| 331 | */ | 331 | */ |
| 332 | if (flush(b.out, b.out_pos) != (int)b.out_pos) | 332 | if (flush(b.out, b.out_pos) != (long)b.out_pos) |
| 333 | ret = XZ_BUF_ERROR; | 333 | ret = XZ_BUF_ERROR; |
| 334 | 334 | ||
| 335 | b.out_pos = 0; | 335 | b.out_pos = 0; |
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 */ | ||
| @@ -590,26 +590,27 @@ static void __idr_remove_all(struct idr *idp) | |||
| 590 | struct idr_layer **paa = &pa[0]; | 590 | struct idr_layer **paa = &pa[0]; |
| 591 | 591 | ||
| 592 | n = idp->layers * IDR_BITS; | 592 | n = idp->layers * IDR_BITS; |
| 593 | p = idp->top; | 593 | *paa = idp->top; |
| 594 | RCU_INIT_POINTER(idp->top, NULL); | 594 | RCU_INIT_POINTER(idp->top, NULL); |
| 595 | max = idr_max(idp->layers); | 595 | max = idr_max(idp->layers); |
| 596 | 596 | ||
| 597 | id = 0; | 597 | id = 0; |
| 598 | while (id >= 0 && id <= max) { | 598 | while (id >= 0 && id <= max) { |
| 599 | p = *paa; | ||
| 599 | while (n > IDR_BITS && p) { | 600 | while (n > IDR_BITS && p) { |
| 600 | n -= IDR_BITS; | 601 | n -= IDR_BITS; |
| 601 | *paa++ = p; | ||
| 602 | p = p->ary[(id >> n) & IDR_MASK]; | 602 | p = p->ary[(id >> n) & IDR_MASK]; |
| 603 | *++paa = p; | ||
| 603 | } | 604 | } |
| 604 | 605 | ||
| 605 | bt_mask = id; | 606 | bt_mask = id; |
| 606 | id += 1 << n; | 607 | id += 1 << n; |
| 607 | /* Get the highest bit that the above add changed from 0->1. */ | 608 | /* Get the highest bit that the above add changed from 0->1. */ |
| 608 | while (n < fls(id ^ bt_mask)) { | 609 | while (n < fls(id ^ bt_mask)) { |
| 609 | if (p) | 610 | if (*paa) |
| 610 | free_layer(idp, p); | 611 | free_layer(idp, *paa); |
| 611 | n += IDR_BITS; | 612 | n += IDR_BITS; |
| 612 | p = *--paa; | 613 | --paa; |
| 613 | } | 614 | } |
| 614 | } | 615 | } |
| 615 | idp->layers = 0; | 616 | idp->layers = 0; |
| @@ -692,15 +693,16 @@ int idr_for_each(struct idr *idp, | |||
| 692 | struct idr_layer **paa = &pa[0]; | 693 | struct idr_layer **paa = &pa[0]; |
| 693 | 694 | ||
| 694 | n = idp->layers * IDR_BITS; | 695 | n = idp->layers * IDR_BITS; |
| 695 | p = rcu_dereference_raw(idp->top); | 696 | *paa = rcu_dereference_raw(idp->top); |
| 696 | max = idr_max(idp->layers); | 697 | max = idr_max(idp->layers); |
| 697 | 698 | ||
| 698 | id = 0; | 699 | id = 0; |
| 699 | while (id >= 0 && id <= max) { | 700 | while (id >= 0 && id <= max) { |
| 701 | p = *paa; | ||
| 700 | while (n > 0 && p) { | 702 | while (n > 0 && p) { |
| 701 | n -= IDR_BITS; | 703 | n -= IDR_BITS; |
| 702 | *paa++ = p; | ||
| 703 | p = rcu_dereference_raw(p->ary[(id >> n) & IDR_MASK]); | 704 | p = rcu_dereference_raw(p->ary[(id >> n) & IDR_MASK]); |
| 705 | *++paa = p; | ||
| 704 | } | 706 | } |
| 705 | 707 | ||
| 706 | if (p) { | 708 | if (p) { |
| @@ -712,7 +714,7 @@ int idr_for_each(struct idr *idp, | |||
| 712 | id += 1 << n; | 714 | id += 1 << n; |
| 713 | while (n < fls(id)) { | 715 | while (n < fls(id)) { |
| 714 | n += IDR_BITS; | 716 | n += IDR_BITS; |
| 715 | p = *--paa; | 717 | --paa; |
| 716 | } | 718 | } |
| 717 | } | 719 | } |
| 718 | 720 | ||
| @@ -740,17 +742,18 @@ void *idr_get_next(struct idr *idp, int *nextidp) | |||
| 740 | int n, max; | 742 | int n, max; |
| 741 | 743 | ||
| 742 | /* find first ent */ | 744 | /* find first ent */ |
| 743 | p = rcu_dereference_raw(idp->top); | 745 | p = *paa = rcu_dereference_raw(idp->top); |
| 744 | if (!p) | 746 | if (!p) |
| 745 | return NULL; | 747 | return NULL; |
| 746 | n = (p->layer + 1) * IDR_BITS; | 748 | n = (p->layer + 1) * IDR_BITS; |
| 747 | max = idr_max(p->layer + 1); | 749 | max = idr_max(p->layer + 1); |
| 748 | 750 | ||
| 749 | while (id >= 0 && id <= max) { | 751 | while (id >= 0 && id <= max) { |
| 752 | p = *paa; | ||
| 750 | while (n > 0 && p) { | 753 | while (n > 0 && p) { |
| 751 | n -= IDR_BITS; | 754 | n -= IDR_BITS; |
| 752 | *paa++ = p; | ||
| 753 | p = rcu_dereference_raw(p->ary[(id >> n) & IDR_MASK]); | 755 | p = rcu_dereference_raw(p->ary[(id >> n) & IDR_MASK]); |
| 756 | *++paa = p; | ||
| 754 | } | 757 | } |
| 755 | 758 | ||
| 756 | if (p) { | 759 | if (p) { |
| @@ -768,7 +771,7 @@ void *idr_get_next(struct idr *idp, int *nextidp) | |||
| 768 | id = round_up(id + 1, 1 << n); | 771 | id = round_up(id + 1, 1 << n); |
| 769 | while (n < fls(id)) { | 772 | while (n < fls(id)) { |
| 770 | n += IDR_BITS; | 773 | n += IDR_BITS; |
| 771 | p = *--paa; | 774 | --paa; |
| 772 | } | 775 | } |
| 773 | } | 776 | } |
| 774 | return NULL; | 777 | return NULL; |
diff --git a/lib/kfifo.c b/lib/kfifo.c index d79b9d222065..90ba1eb1df06 100644 --- a/lib/kfifo.c +++ b/lib/kfifo.c | |||
| @@ -561,8 +561,7 @@ EXPORT_SYMBOL(__kfifo_to_user_r); | |||
| 561 | unsigned int __kfifo_dma_in_prepare_r(struct __kfifo *fifo, | 561 | unsigned int __kfifo_dma_in_prepare_r(struct __kfifo *fifo, |
| 562 | struct scatterlist *sgl, int nents, unsigned int len, size_t recsize) | 562 | struct scatterlist *sgl, int nents, unsigned int len, size_t recsize) |
| 563 | { | 563 | { |
| 564 | if (!nents) | 564 | BUG_ON(!nents); |
| 565 | BUG(); | ||
| 566 | 565 | ||
| 567 | len = __kfifo_max_r(len, recsize); | 566 | len = __kfifo_max_r(len, recsize); |
| 568 | 567 | ||
| @@ -585,8 +584,7 @@ EXPORT_SYMBOL(__kfifo_dma_in_finish_r); | |||
| 585 | unsigned int __kfifo_dma_out_prepare_r(struct __kfifo *fifo, | 584 | unsigned int __kfifo_dma_out_prepare_r(struct __kfifo *fifo, |
| 586 | struct scatterlist *sgl, int nents, unsigned int len, size_t recsize) | 585 | struct scatterlist *sgl, int nents, unsigned int len, size_t recsize) |
| 587 | { | 586 | { |
| 588 | if (!nents) | 587 | BUG_ON(!nents); |
| 589 | BUG(); | ||
| 590 | 588 | ||
| 591 | len = __kfifo_max_r(len, recsize); | 589 | len = __kfifo_max_r(len, recsize); |
| 592 | 590 | ||
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/lru_cache.c b/lib/lru_cache.c index 4a83ecd03650..852c81e3ba9a 100644 --- a/lib/lru_cache.c +++ b/lib/lru_cache.c | |||
| @@ -169,7 +169,7 @@ out_fail: | |||
| 169 | return NULL; | 169 | return NULL; |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | void lc_free_by_index(struct lru_cache *lc, unsigned i) | 172 | static void lc_free_by_index(struct lru_cache *lc, unsigned i) |
| 173 | { | 173 | { |
| 174 | void *p = lc->lc_element[i]; | 174 | void *p = lc->lc_element[i]; |
| 175 | WARN_ON(!p); | 175 | WARN_ON(!p); |
| @@ -643,9 +643,10 @@ void lc_set(struct lru_cache *lc, unsigned int enr, int index) | |||
| 643 | * lc_dump - Dump a complete LRU cache to seq in textual form. | 643 | * lc_dump - Dump a complete LRU cache to seq in textual form. |
| 644 | * @lc: the lru cache to operate on | 644 | * @lc: the lru cache to operate on |
| 645 | * @seq: the &struct seq_file pointer to seq_printf into | 645 | * @seq: the &struct seq_file pointer to seq_printf into |
| 646 | * @utext: user supplied "heading" or other info | 646 | * @utext: user supplied additional "heading" or other info |
| 647 | * @detail: function pointer the user may provide to dump further details | 647 | * @detail: function pointer the user may provide to dump further details |
| 648 | * of the object the lc_element is embedded in. | 648 | * of the object the lc_element is embedded in. May be NULL. |
| 649 | * Note: a leading space ' ' and trailing newline '\n' is implied. | ||
| 649 | */ | 650 | */ |
| 650 | void lc_seq_dump_details(struct seq_file *seq, struct lru_cache *lc, char *utext, | 651 | void lc_seq_dump_details(struct seq_file *seq, struct lru_cache *lc, char *utext, |
| 651 | void (*detail) (struct seq_file *, struct lc_element *)) | 652 | void (*detail) (struct seq_file *, struct lc_element *)) |
| @@ -654,16 +655,18 @@ void lc_seq_dump_details(struct seq_file *seq, struct lru_cache *lc, char *utext | |||
| 654 | struct lc_element *e; | 655 | struct lc_element *e; |
| 655 | int i; | 656 | int i; |
| 656 | 657 | ||
| 657 | seq_printf(seq, "\tnn: lc_number refcnt %s\n ", utext); | 658 | seq_printf(seq, "\tnn: lc_number (new nr) refcnt %s\n ", utext); |
| 658 | for (i = 0; i < nr_elements; i++) { | 659 | for (i = 0; i < nr_elements; i++) { |
| 659 | e = lc_element_by_index(lc, i); | 660 | e = lc_element_by_index(lc, i); |
| 660 | if (e->lc_number == LC_FREE) { | 661 | if (e->lc_number != e->lc_new_number) |
| 661 | seq_printf(seq, "\t%2d: FREE\n", i); | 662 | seq_printf(seq, "\t%5d: %6d %8d %6d ", |
| 662 | } else { | 663 | i, e->lc_number, e->lc_new_number, e->refcnt); |
| 663 | seq_printf(seq, "\t%2d: %4u %4u ", i, | 664 | else |
| 664 | e->lc_number, e->refcnt); | 665 | seq_printf(seq, "\t%5d: %6d %-8s %6d ", |
| 666 | i, e->lc_number, "-\"-", e->refcnt); | ||
| 667 | if (detail) | ||
| 665 | detail(seq, e); | 668 | detail(seq, e); |
| 666 | } | 669 | seq_putc(seq, '\n'); |
| 667 | } | 670 | } |
| 668 | } | 671 | } |
| 669 | 672 | ||
diff --git a/lib/rbtree.c b/lib/rbtree.c index 65f4effd117f..c16c81a3d430 100644 --- a/lib/rbtree.c +++ b/lib/rbtree.c | |||
| @@ -101,7 +101,7 @@ __rb_insert(struct rb_node *node, struct rb_root *root, | |||
| 101 | * / \ / \ | 101 | * / \ / \ |
| 102 | * p u --> P U | 102 | * p u --> P U |
| 103 | * / / | 103 | * / / |
| 104 | * n N | 104 | * n n |
| 105 | * | 105 | * |
| 106 | * However, since g's parent might be red, and | 106 | * However, since g's parent might be red, and |
| 107 | * 4) does not allow this, we need to recurse | 107 | * 4) does not allow this, we need to recurse |
diff --git a/lib/rhashtable.c b/lib/rhashtable.c index e6940cf16628..a2c78810ebc1 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c | |||
| @@ -38,16 +38,10 @@ int lockdep_rht_mutex_is_held(const struct rhashtable *ht) | |||
| 38 | EXPORT_SYMBOL_GPL(lockdep_rht_mutex_is_held); | 38 | EXPORT_SYMBOL_GPL(lockdep_rht_mutex_is_held); |
| 39 | #endif | 39 | #endif |
| 40 | 40 | ||
| 41 | /** | 41 | static void *rht_obj(const struct rhashtable *ht, const struct rhash_head *he) |
| 42 | * rht_obj - cast hash head to outer object | ||
| 43 | * @ht: hash table | ||
| 44 | * @he: hashed node | ||
| 45 | */ | ||
| 46 | void *rht_obj(const struct rhashtable *ht, const struct rhash_head *he) | ||
| 47 | { | 42 | { |
| 48 | return (void *) he - ht->p.head_offset; | 43 | return (void *) he - ht->p.head_offset; |
| 49 | } | 44 | } |
| 50 | EXPORT_SYMBOL_GPL(rht_obj); | ||
| 51 | 45 | ||
| 52 | static u32 __hashfn(const struct rhashtable *ht, const void *key, | 46 | static u32 __hashfn(const struct rhashtable *ht, const void *key, |
| 53 | u32 len, u32 hsize) | 47 | u32 len, u32 hsize) |
| @@ -386,7 +380,7 @@ EXPORT_SYMBOL_GPL(rhashtable_insert); | |||
| 386 | * deletion when combined with walking or lookup. | 380 | * deletion when combined with walking or lookup. |
| 387 | */ | 381 | */ |
| 388 | void rhashtable_remove_pprev(struct rhashtable *ht, struct rhash_head *obj, | 382 | void rhashtable_remove_pprev(struct rhashtable *ht, struct rhash_head *obj, |
| 389 | struct rhash_head **pprev, gfp_t flags) | 383 | struct rhash_head __rcu **pprev, gfp_t flags) |
| 390 | { | 384 | { |
| 391 | struct bucket_table *tbl = rht_dereference(ht->tbl, ht); | 385 | struct bucket_table *tbl = rht_dereference(ht->tbl, ht); |
| 392 | 386 | ||
diff --git a/lib/scatterlist.c b/lib/scatterlist.c index b4415fceb7e7..9cdf62f8accd 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c | |||
| @@ -73,7 +73,7 @@ EXPORT_SYMBOL(sg_nents); | |||
| 73 | **/ | 73 | **/ |
| 74 | struct scatterlist *sg_last(struct scatterlist *sgl, unsigned int nents) | 74 | struct scatterlist *sg_last(struct scatterlist *sgl, unsigned int nents) |
| 75 | { | 75 | { |
| 76 | #ifndef ARCH_HAS_SG_CHAIN | 76 | #ifndef CONFIG_ARCH_HAS_SG_CHAIN |
| 77 | struct scatterlist *ret = &sgl[nents - 1]; | 77 | struct scatterlist *ret = &sgl[nents - 1]; |
| 78 | #else | 78 | #else |
| 79 | struct scatterlist *sg, *ret = NULL; | 79 | struct scatterlist *sg, *ret = NULL; |
| @@ -255,7 +255,7 @@ int __sg_alloc_table(struct sg_table *table, unsigned int nents, | |||
| 255 | 255 | ||
| 256 | if (nents == 0) | 256 | if (nents == 0) |
| 257 | return -EINVAL; | 257 | return -EINVAL; |
| 258 | #ifndef ARCH_HAS_SG_CHAIN | 258 | #ifndef CONFIG_ARCH_HAS_SG_CHAIN |
| 259 | if (WARN_ON_ONCE(nents > max_ents)) | 259 | if (WARN_ON_ONCE(nents > max_ents)) |
| 260 | return -EINVAL; | 260 | return -EINVAL; |
| 261 | #endif | 261 | #endif |
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"; |
