diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 4 | ||||
-rw-r--r-- | lib/Kconfig.debug | 3 | ||||
-rw-r--r-- | lib/Makefile | 3 | ||||
-rw-r--r-- | lib/argv_split.c | 13 | ||||
-rw-r--r-- | lib/bitmap.c | 81 | ||||
-rw-r--r-- | lib/crc32.c | 121 | ||||
-rw-r--r-- | lib/ctype.c | 50 | ||||
-rw-r--r-- | lib/debugobjects.c | 74 | ||||
-rw-r--r-- | lib/decompress.c | 5 | ||||
-rw-r--r-- | lib/decompress_bunzip2.c | 10 | ||||
-rw-r--r-- | lib/decompress_unlzo.c | 209 | ||||
-rw-r--r-- | lib/dma-debug.c | 15 | ||||
-rw-r--r-- | lib/dynamic_debug.c | 4 | ||||
-rw-r--r-- | lib/genalloc.c | 33 | ||||
-rw-r--r-- | lib/iommu-helper.c | 59 | ||||
-rw-r--r-- | lib/kernel_lock.c | 22 | ||||
-rw-r--r-- | lib/list_sort.c | 102 | ||||
-rw-r--r-- | lib/lmb.c | 7 | ||||
-rw-r--r-- | lib/lzo/lzo1x_decompress.c | 9 | ||||
-rw-r--r-- | lib/parser.c | 11 | ||||
-rw-r--r-- | lib/plist.c | 8 | ||||
-rw-r--r-- | lib/rational.c | 1 | ||||
-rw-r--r-- | lib/rwsem-spinlock.c | 23 | ||||
-rw-r--r-- | lib/spinlock_debug.c | 64 | ||||
-rw-r--r-- | lib/string.c | 52 | ||||
-rw-r--r-- | lib/swiotlb.c | 4 | ||||
-rw-r--r-- | lib/vsprintf.c | 410 | ||||
-rw-r--r-- | lib/zlib_inflate/inffast.c | 75 |
28 files changed, 982 insertions, 490 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index 1cfe51628e1b..97b136ff117e 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
@@ -117,6 +117,10 @@ config DECOMPRESS_BZIP2 | |||
117 | config DECOMPRESS_LZMA | 117 | config DECOMPRESS_LZMA |
118 | tristate | 118 | tristate |
119 | 119 | ||
120 | config DECOMPRESS_LZO | ||
121 | select LZO_DECOMPRESS | ||
122 | tristate | ||
123 | |||
120 | # | 124 | # |
121 | # Generic allocator support is selected if needed | 125 | # Generic allocator support is selected if needed |
122 | # | 126 | # |
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 2f22cf4576db..25c3ed594c54 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
@@ -360,6 +360,7 @@ config DEBUG_KMEMLEAK | |||
360 | select DEBUG_FS if SYSFS | 360 | select DEBUG_FS if SYSFS |
361 | select STACKTRACE if STACKTRACE_SUPPORT | 361 | select STACKTRACE if STACKTRACE_SUPPORT |
362 | select KALLSYMS | 362 | select KALLSYMS |
363 | select CRC32 | ||
363 | help | 364 | help |
364 | Say Y here if you want to enable the memory leak | 365 | Say Y here if you want to enable the memory leak |
365 | detector. The memory allocation/freeing is traced in a way | 366 | detector. The memory allocation/freeing is traced in a way |
@@ -575,7 +576,7 @@ config DEBUG_BUGVERBOSE | |||
575 | depends on BUG | 576 | depends on BUG |
576 | depends on ARM || AVR32 || M32R || M68K || SPARC32 || SPARC64 || \ | 577 | depends on ARM || AVR32 || M32R || M68K || SPARC32 || SPARC64 || \ |
577 | FRV || SUPERH || GENERIC_BUG || BLACKFIN || MN10300 | 578 | FRV || SUPERH || GENERIC_BUG || BLACKFIN || MN10300 |
578 | default !EMBEDDED | 579 | default y |
579 | help | 580 | help |
580 | Say Y here to make BUG() panics output the file name and line number | 581 | Say Y here to make BUG() panics output the file name and line number |
581 | of the BUG call as well as the EIP and oops trace. This aids | 582 | of the BUG call as well as the EIP and oops trace. This aids |
diff --git a/lib/Makefile b/lib/Makefile index 347ad8db29d3..3b0b4a696db9 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -21,7 +21,7 @@ lib-y += kobject.o kref.o klist.o | |||
21 | 21 | ||
22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | 22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ | 23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ |
24 | string_helpers.o gcd.o | 24 | string_helpers.o gcd.o list_sort.o |
25 | 25 | ||
26 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) | 26 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) |
27 | CFLAGS_kobject.o += -DDEBUG | 27 | CFLAGS_kobject.o += -DDEBUG |
@@ -69,6 +69,7 @@ obj-$(CONFIG_LZO_DECOMPRESS) += lzo/ | |||
69 | lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o | 69 | lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o |
70 | lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o | 70 | lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o |
71 | lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o | 71 | lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o |
72 | lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o | ||
72 | 73 | ||
73 | obj-$(CONFIG_TEXTSEARCH) += textsearch.o | 74 | obj-$(CONFIG_TEXTSEARCH) += textsearch.o |
74 | obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o | 75 | obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o |
diff --git a/lib/argv_split.c b/lib/argv_split.c index 5205a8dae5bc..4b1b083f219c 100644 --- a/lib/argv_split.c +++ b/lib/argv_split.c | |||
@@ -4,17 +4,10 @@ | |||
4 | 4 | ||
5 | #include <linux/kernel.h> | 5 | #include <linux/kernel.h> |
6 | #include <linux/ctype.h> | 6 | #include <linux/ctype.h> |
7 | #include <linux/string.h> | ||
7 | #include <linux/slab.h> | 8 | #include <linux/slab.h> |
8 | #include <linux/module.h> | 9 | #include <linux/module.h> |
9 | 10 | ||
10 | static const char *skip_sep(const char *cp) | ||
11 | { | ||
12 | while (*cp && isspace(*cp)) | ||
13 | cp++; | ||
14 | |||
15 | return cp; | ||
16 | } | ||
17 | |||
18 | static const char *skip_arg(const char *cp) | 11 | static const char *skip_arg(const char *cp) |
19 | { | 12 | { |
20 | while (*cp && !isspace(*cp)) | 13 | while (*cp && !isspace(*cp)) |
@@ -28,7 +21,7 @@ static int count_argc(const char *str) | |||
28 | int count = 0; | 21 | int count = 0; |
29 | 22 | ||
30 | while (*str) { | 23 | while (*str) { |
31 | str = skip_sep(str); | 24 | str = skip_spaces(str); |
32 | if (*str) { | 25 | if (*str) { |
33 | count++; | 26 | count++; |
34 | str = skip_arg(str); | 27 | str = skip_arg(str); |
@@ -82,7 +75,7 @@ char **argv_split(gfp_t gfp, const char *str, int *argcp) | |||
82 | argvp = argv; | 75 | argvp = argv; |
83 | 76 | ||
84 | while (*str) { | 77 | while (*str) { |
85 | str = skip_sep(str); | 78 | str = skip_spaces(str); |
86 | 79 | ||
87 | if (*str) { | 80 | if (*str) { |
88 | const char *p = str; | 81 | const char *p = str; |
diff --git a/lib/bitmap.c b/lib/bitmap.c index 702565821c99..11bf49750583 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c | |||
@@ -271,6 +271,87 @@ int __bitmap_weight(const unsigned long *bitmap, int bits) | |||
271 | } | 271 | } |
272 | EXPORT_SYMBOL(__bitmap_weight); | 272 | EXPORT_SYMBOL(__bitmap_weight); |
273 | 273 | ||
274 | #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG)) | ||
275 | |||
276 | void bitmap_set(unsigned long *map, int start, int nr) | ||
277 | { | ||
278 | unsigned long *p = map + BIT_WORD(start); | ||
279 | const int size = start + nr; | ||
280 | int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG); | ||
281 | unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start); | ||
282 | |||
283 | while (nr - bits_to_set >= 0) { | ||
284 | *p |= mask_to_set; | ||
285 | nr -= bits_to_set; | ||
286 | bits_to_set = BITS_PER_LONG; | ||
287 | mask_to_set = ~0UL; | ||
288 | p++; | ||
289 | } | ||
290 | if (nr) { | ||
291 | mask_to_set &= BITMAP_LAST_WORD_MASK(size); | ||
292 | *p |= mask_to_set; | ||
293 | } | ||
294 | } | ||
295 | EXPORT_SYMBOL(bitmap_set); | ||
296 | |||
297 | void bitmap_clear(unsigned long *map, int start, int nr) | ||
298 | { | ||
299 | unsigned long *p = map + BIT_WORD(start); | ||
300 | const int size = start + nr; | ||
301 | int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG); | ||
302 | unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start); | ||
303 | |||
304 | while (nr - bits_to_clear >= 0) { | ||
305 | *p &= ~mask_to_clear; | ||
306 | nr -= bits_to_clear; | ||
307 | bits_to_clear = BITS_PER_LONG; | ||
308 | mask_to_clear = ~0UL; | ||
309 | p++; | ||
310 | } | ||
311 | if (nr) { | ||
312 | mask_to_clear &= BITMAP_LAST_WORD_MASK(size); | ||
313 | *p &= ~mask_to_clear; | ||
314 | } | ||
315 | } | ||
316 | EXPORT_SYMBOL(bitmap_clear); | ||
317 | |||
318 | /* | ||
319 | * bitmap_find_next_zero_area - find a contiguous aligned zero area | ||
320 | * @map: The address to base the search on | ||
321 | * @size: The bitmap size in bits | ||
322 | * @start: The bitnumber to start searching at | ||
323 | * @nr: The number of zeroed bits we're looking for | ||
324 | * @align_mask: Alignment mask for zero area | ||
325 | * | ||
326 | * The @align_mask should be one less than a power of 2; the effect is that | ||
327 | * the bit offset of all zero areas this function finds is multiples of that | ||
328 | * power of 2. A @align_mask of 0 means no alignment is required. | ||
329 | */ | ||
330 | unsigned long bitmap_find_next_zero_area(unsigned long *map, | ||
331 | unsigned long size, | ||
332 | unsigned long start, | ||
333 | unsigned int nr, | ||
334 | unsigned long align_mask) | ||
335 | { | ||
336 | unsigned long index, end, i; | ||
337 | again: | ||
338 | index = find_next_zero_bit(map, size, start); | ||
339 | |||
340 | /* Align allocation */ | ||
341 | index = __ALIGN_MASK(index, align_mask); | ||
342 | |||
343 | end = index + nr; | ||
344 | if (end > size) | ||
345 | return end; | ||
346 | i = find_next_bit(map, end, index); | ||
347 | if (i < end) { | ||
348 | start = i + 1; | ||
349 | goto again; | ||
350 | } | ||
351 | return index; | ||
352 | } | ||
353 | EXPORT_SYMBOL(bitmap_find_next_zero_area); | ||
354 | |||
274 | /* | 355 | /* |
275 | * Bitmap printing & parsing functions: first version by Bill Irwin, | 356 | * Bitmap printing & parsing functions: first version by Bill Irwin, |
276 | * second version by Paul Jackson, third by Joe Korty. | 357 | * second version by Paul Jackson, third by Joe Korty. |
diff --git a/lib/crc32.c b/lib/crc32.c index 49d1c9e3ce38..02e3b31b3a79 100644 --- a/lib/crc32.c +++ b/lib/crc32.c | |||
@@ -42,6 +42,48 @@ MODULE_AUTHOR("Matt Domsch <Matt_Domsch@dell.com>"); | |||
42 | MODULE_DESCRIPTION("Ethernet CRC32 calculations"); | 42 | MODULE_DESCRIPTION("Ethernet CRC32 calculations"); |
43 | MODULE_LICENSE("GPL"); | 43 | MODULE_LICENSE("GPL"); |
44 | 44 | ||
45 | #if CRC_LE_BITS == 8 || CRC_BE_BITS == 8 | ||
46 | |||
47 | static inline u32 | ||
48 | crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 *tab) | ||
49 | { | ||
50 | # ifdef __LITTLE_ENDIAN | ||
51 | # define DO_CRC(x) crc = tab[(crc ^ (x)) & 255 ] ^ (crc >> 8) | ||
52 | # else | ||
53 | # define DO_CRC(x) crc = tab[((crc >> 24) ^ (x)) & 255] ^ (crc << 8) | ||
54 | # endif | ||
55 | const u32 *b = (const u32 *)buf; | ||
56 | size_t rem_len; | ||
57 | |||
58 | /* Align it */ | ||
59 | if (unlikely((long)b & 3 && len)) { | ||
60 | u8 *p = (u8 *)b; | ||
61 | do { | ||
62 | DO_CRC(*p++); | ||
63 | } while ((--len) && ((long)p)&3); | ||
64 | b = (u32 *)p; | ||
65 | } | ||
66 | rem_len = len & 3; | ||
67 | /* load data 32 bits wide, xor data 32 bits wide. */ | ||
68 | len = len >> 2; | ||
69 | for (--b; len; --len) { | ||
70 | crc ^= *++b; /* use pre increment for speed */ | ||
71 | DO_CRC(0); | ||
72 | DO_CRC(0); | ||
73 | DO_CRC(0); | ||
74 | DO_CRC(0); | ||
75 | } | ||
76 | len = rem_len; | ||
77 | /* And the last few bytes */ | ||
78 | if (len) { | ||
79 | u8 *p = (u8 *)(b + 1) - 1; | ||
80 | do { | ||
81 | DO_CRC(*++p); /* use pre increment for speed */ | ||
82 | } while (--len); | ||
83 | } | ||
84 | return crc; | ||
85 | } | ||
86 | #endif | ||
45 | /** | 87 | /** |
46 | * crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32 | 88 | * crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32 |
47 | * @crc: seed value for computation. ~0 for Ethernet, sometimes 0 for | 89 | * @crc: seed value for computation. ~0 for Ethernet, sometimes 0 for |
@@ -72,48 +114,10 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) | |||
72 | u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) | 114 | u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) |
73 | { | 115 | { |
74 | # if CRC_LE_BITS == 8 | 116 | # if CRC_LE_BITS == 8 |
75 | const u32 *b =(u32 *)p; | ||
76 | const u32 *tab = crc32table_le; | 117 | const u32 *tab = crc32table_le; |
77 | 118 | ||
78 | # ifdef __LITTLE_ENDIAN | ||
79 | # define DO_CRC(x) crc = tab[ (crc ^ (x)) & 255 ] ^ (crc>>8) | ||
80 | # else | ||
81 | # define DO_CRC(x) crc = tab[ ((crc >> 24) ^ (x)) & 255] ^ (crc<<8) | ||
82 | # endif | ||
83 | |||
84 | crc = __cpu_to_le32(crc); | 119 | crc = __cpu_to_le32(crc); |
85 | /* Align it */ | 120 | crc = crc32_body(crc, p, len, tab); |
86 | if(unlikely(((long)b)&3 && len)){ | ||
87 | do { | ||
88 | u8 *p = (u8 *)b; | ||
89 | DO_CRC(*p++); | ||
90 | b = (void *)p; | ||
91 | } while ((--len) && ((long)b)&3 ); | ||
92 | } | ||
93 | if(likely(len >= 4)){ | ||
94 | /* load data 32 bits wide, xor data 32 bits wide. */ | ||
95 | size_t save_len = len & 3; | ||
96 | len = len >> 2; | ||
97 | --b; /* use pre increment below(*++b) for speed */ | ||
98 | do { | ||
99 | crc ^= *++b; | ||
100 | DO_CRC(0); | ||
101 | DO_CRC(0); | ||
102 | DO_CRC(0); | ||
103 | DO_CRC(0); | ||
104 | } while (--len); | ||
105 | b++; /* point to next byte(s) */ | ||
106 | len = save_len; | ||
107 | } | ||
108 | /* And the last few bytes */ | ||
109 | if(len){ | ||
110 | do { | ||
111 | u8 *p = (u8 *)b; | ||
112 | DO_CRC(*p++); | ||
113 | b = (void *)p; | ||
114 | } while (--len); | ||
115 | } | ||
116 | |||
117 | return __le32_to_cpu(crc); | 121 | return __le32_to_cpu(crc); |
118 | #undef ENDIAN_SHIFT | 122 | #undef ENDIAN_SHIFT |
119 | #undef DO_CRC | 123 | #undef DO_CRC |
@@ -170,47 +174,10 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) | |||
170 | u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) | 174 | u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) |
171 | { | 175 | { |
172 | # if CRC_BE_BITS == 8 | 176 | # if CRC_BE_BITS == 8 |
173 | const u32 *b =(u32 *)p; | ||
174 | const u32 *tab = crc32table_be; | 177 | const u32 *tab = crc32table_be; |
175 | 178 | ||
176 | # ifdef __LITTLE_ENDIAN | ||
177 | # define DO_CRC(x) crc = tab[ (crc ^ (x)) & 255 ] ^ (crc>>8) | ||
178 | # else | ||
179 | # define DO_CRC(x) crc = tab[ ((crc >> 24) ^ (x)) & 255] ^ (crc<<8) | ||
180 | # endif | ||
181 | |||
182 | crc = __cpu_to_be32(crc); | 179 | crc = __cpu_to_be32(crc); |
183 | /* Align it */ | 180 | crc = crc32_body(crc, p, len, tab); |
184 | if(unlikely(((long)b)&3 && len)){ | ||
185 | do { | ||
186 | u8 *p = (u8 *)b; | ||
187 | DO_CRC(*p++); | ||
188 | b = (u32 *)p; | ||
189 | } while ((--len) && ((long)b)&3 ); | ||
190 | } | ||
191 | if(likely(len >= 4)){ | ||
192 | /* load data 32 bits wide, xor data 32 bits wide. */ | ||
193 | size_t save_len = len & 3; | ||
194 | len = len >> 2; | ||
195 | --b; /* use pre increment below(*++b) for speed */ | ||
196 | do { | ||
197 | crc ^= *++b; | ||
198 | DO_CRC(0); | ||
199 | DO_CRC(0); | ||
200 | DO_CRC(0); | ||
201 | DO_CRC(0); | ||
202 | } while (--len); | ||
203 | b++; /* point to next byte(s) */ | ||
204 | len = save_len; | ||
205 | } | ||
206 | /* And the last few bytes */ | ||
207 | if(len){ | ||
208 | do { | ||
209 | u8 *p = (u8 *)b; | ||
210 | DO_CRC(*p++); | ||
211 | b = (void *)p; | ||
212 | } while (--len); | ||
213 | } | ||
214 | return __be32_to_cpu(crc); | 181 | return __be32_to_cpu(crc); |
215 | #undef ENDIAN_SHIFT | 182 | #undef ENDIAN_SHIFT |
216 | #undef DO_CRC | 183 | #undef DO_CRC |
diff --git a/lib/ctype.c b/lib/ctype.c index d02ace14a322..26baa620e95b 100644 --- a/lib/ctype.c +++ b/lib/ctype.c | |||
@@ -7,30 +7,30 @@ | |||
7 | #include <linux/ctype.h> | 7 | #include <linux/ctype.h> |
8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
9 | 9 | ||
10 | unsigned char _ctype[] = { | 10 | const unsigned char _ctype[] = { |
11 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ | 11 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ |
12 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ | 12 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ |
13 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ | 13 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ |
14 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ | 14 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ |
15 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ | 15 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ |
16 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ | 16 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ |
17 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ | 17 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ |
18 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ | 18 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ |
19 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ | 19 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ |
20 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ | 20 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ |
21 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ | 21 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ |
22 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ | 22 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ |
23 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ | 23 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ |
24 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ | 24 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ |
25 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ | 25 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ |
26 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ | 26 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ |
27 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ | 27 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ |
28 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ | 28 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ |
29 | _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */ | 29 | _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */ |
30 | _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */ | 30 | _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */ |
31 | _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */ | 31 | _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */ |
32 | _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */ | 32 | _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */ |
33 | _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */ | 33 | _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */ |
34 | _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */ | 34 | _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */ |
35 | 35 | ||
36 | EXPORT_SYMBOL(_ctype); | 36 | EXPORT_SYMBOL(_ctype); |
diff --git a/lib/debugobjects.c b/lib/debugobjects.c index eae56fddfa3b..a9a8996d286a 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c | |||
@@ -26,14 +26,14 @@ | |||
26 | 26 | ||
27 | struct debug_bucket { | 27 | struct debug_bucket { |
28 | struct hlist_head list; | 28 | struct hlist_head list; |
29 | spinlock_t lock; | 29 | raw_spinlock_t lock; |
30 | }; | 30 | }; |
31 | 31 | ||
32 | static struct debug_bucket obj_hash[ODEBUG_HASH_SIZE]; | 32 | static struct debug_bucket obj_hash[ODEBUG_HASH_SIZE]; |
33 | 33 | ||
34 | static struct debug_obj obj_static_pool[ODEBUG_POOL_SIZE] __initdata; | 34 | static struct debug_obj obj_static_pool[ODEBUG_POOL_SIZE] __initdata; |
35 | 35 | ||
36 | static DEFINE_SPINLOCK(pool_lock); | 36 | static DEFINE_RAW_SPINLOCK(pool_lock); |
37 | 37 | ||
38 | static HLIST_HEAD(obj_pool); | 38 | static HLIST_HEAD(obj_pool); |
39 | 39 | ||
@@ -96,10 +96,10 @@ static int fill_pool(void) | |||
96 | if (!new) | 96 | if (!new) |
97 | return obj_pool_free; | 97 | return obj_pool_free; |
98 | 98 | ||
99 | spin_lock_irqsave(&pool_lock, flags); | 99 | raw_spin_lock_irqsave(&pool_lock, flags); |
100 | hlist_add_head(&new->node, &obj_pool); | 100 | hlist_add_head(&new->node, &obj_pool); |
101 | obj_pool_free++; | 101 | obj_pool_free++; |
102 | spin_unlock_irqrestore(&pool_lock, flags); | 102 | raw_spin_unlock_irqrestore(&pool_lock, flags); |
103 | } | 103 | } |
104 | return obj_pool_free; | 104 | return obj_pool_free; |
105 | } | 105 | } |
@@ -133,7 +133,7 @@ alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr) | |||
133 | { | 133 | { |
134 | struct debug_obj *obj = NULL; | 134 | struct debug_obj *obj = NULL; |
135 | 135 | ||
136 | spin_lock(&pool_lock); | 136 | raw_spin_lock(&pool_lock); |
137 | if (obj_pool.first) { | 137 | if (obj_pool.first) { |
138 | obj = hlist_entry(obj_pool.first, typeof(*obj), node); | 138 | obj = hlist_entry(obj_pool.first, typeof(*obj), node); |
139 | 139 | ||
@@ -152,7 +152,7 @@ alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr) | |||
152 | if (obj_pool_free < obj_pool_min_free) | 152 | if (obj_pool_free < obj_pool_min_free) |
153 | obj_pool_min_free = obj_pool_free; | 153 | obj_pool_min_free = obj_pool_free; |
154 | } | 154 | } |
155 | spin_unlock(&pool_lock); | 155 | raw_spin_unlock(&pool_lock); |
156 | 156 | ||
157 | return obj; | 157 | return obj; |
158 | } | 158 | } |
@@ -165,7 +165,7 @@ static void free_obj_work(struct work_struct *work) | |||
165 | struct debug_obj *obj; | 165 | struct debug_obj *obj; |
166 | unsigned long flags; | 166 | unsigned long flags; |
167 | 167 | ||
168 | spin_lock_irqsave(&pool_lock, flags); | 168 | raw_spin_lock_irqsave(&pool_lock, flags); |
169 | while (obj_pool_free > ODEBUG_POOL_SIZE) { | 169 | while (obj_pool_free > ODEBUG_POOL_SIZE) { |
170 | obj = hlist_entry(obj_pool.first, typeof(*obj), node); | 170 | obj = hlist_entry(obj_pool.first, typeof(*obj), node); |
171 | hlist_del(&obj->node); | 171 | hlist_del(&obj->node); |
@@ -174,11 +174,11 @@ static void free_obj_work(struct work_struct *work) | |||
174 | * We release pool_lock across kmem_cache_free() to | 174 | * We release pool_lock across kmem_cache_free() to |
175 | * avoid contention on pool_lock. | 175 | * avoid contention on pool_lock. |
176 | */ | 176 | */ |
177 | spin_unlock_irqrestore(&pool_lock, flags); | 177 | raw_spin_unlock_irqrestore(&pool_lock, flags); |
178 | kmem_cache_free(obj_cache, obj); | 178 | kmem_cache_free(obj_cache, obj); |
179 | spin_lock_irqsave(&pool_lock, flags); | 179 | raw_spin_lock_irqsave(&pool_lock, flags); |
180 | } | 180 | } |
181 | spin_unlock_irqrestore(&pool_lock, flags); | 181 | raw_spin_unlock_irqrestore(&pool_lock, flags); |
182 | } | 182 | } |
183 | 183 | ||
184 | /* | 184 | /* |
@@ -190,7 +190,7 @@ static void free_object(struct debug_obj *obj) | |||
190 | unsigned long flags; | 190 | unsigned long flags; |
191 | int sched = 0; | 191 | int sched = 0; |
192 | 192 | ||
193 | spin_lock_irqsave(&pool_lock, flags); | 193 | raw_spin_lock_irqsave(&pool_lock, flags); |
194 | /* | 194 | /* |
195 | * schedule work when the pool is filled and the cache is | 195 | * schedule work when the pool is filled and the cache is |
196 | * initialized: | 196 | * initialized: |
@@ -200,7 +200,7 @@ static void free_object(struct debug_obj *obj) | |||
200 | hlist_add_head(&obj->node, &obj_pool); | 200 | hlist_add_head(&obj->node, &obj_pool); |
201 | obj_pool_free++; | 201 | obj_pool_free++; |
202 | obj_pool_used--; | 202 | obj_pool_used--; |
203 | spin_unlock_irqrestore(&pool_lock, flags); | 203 | raw_spin_unlock_irqrestore(&pool_lock, flags); |
204 | if (sched) | 204 | if (sched) |
205 | schedule_work(&debug_obj_work); | 205 | schedule_work(&debug_obj_work); |
206 | } | 206 | } |
@@ -221,9 +221,9 @@ static void debug_objects_oom(void) | |||
221 | printk(KERN_WARNING "ODEBUG: Out of memory. ODEBUG disabled\n"); | 221 | printk(KERN_WARNING "ODEBUG: Out of memory. ODEBUG disabled\n"); |
222 | 222 | ||
223 | for (i = 0; i < ODEBUG_HASH_SIZE; i++, db++) { | 223 | for (i = 0; i < ODEBUG_HASH_SIZE; i++, db++) { |
224 | spin_lock_irqsave(&db->lock, flags); | 224 | raw_spin_lock_irqsave(&db->lock, flags); |
225 | hlist_move_list(&db->list, &freelist); | 225 | hlist_move_list(&db->list, &freelist); |
226 | spin_unlock_irqrestore(&db->lock, flags); | 226 | raw_spin_unlock_irqrestore(&db->lock, flags); |
227 | 227 | ||
228 | /* Now free them */ | 228 | /* Now free them */ |
229 | hlist_for_each_entry_safe(obj, node, tmp, &freelist, node) { | 229 | hlist_for_each_entry_safe(obj, node, tmp, &freelist, node) { |
@@ -303,14 +303,14 @@ __debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack) | |||
303 | 303 | ||
304 | db = get_bucket((unsigned long) addr); | 304 | db = get_bucket((unsigned long) addr); |
305 | 305 | ||
306 | spin_lock_irqsave(&db->lock, flags); | 306 | raw_spin_lock_irqsave(&db->lock, flags); |
307 | 307 | ||
308 | obj = lookup_object(addr, db); | 308 | obj = lookup_object(addr, db); |
309 | if (!obj) { | 309 | if (!obj) { |
310 | obj = alloc_object(addr, db, descr); | 310 | obj = alloc_object(addr, db, descr); |
311 | if (!obj) { | 311 | if (!obj) { |
312 | debug_objects_enabled = 0; | 312 | debug_objects_enabled = 0; |
313 | spin_unlock_irqrestore(&db->lock, flags); | 313 | raw_spin_unlock_irqrestore(&db->lock, flags); |
314 | debug_objects_oom(); | 314 | debug_objects_oom(); |
315 | return; | 315 | return; |
316 | } | 316 | } |
@@ -327,7 +327,7 @@ __debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack) | |||
327 | case ODEBUG_STATE_ACTIVE: | 327 | case ODEBUG_STATE_ACTIVE: |
328 | debug_print_object(obj, "init"); | 328 | debug_print_object(obj, "init"); |
329 | state = obj->state; | 329 | state = obj->state; |
330 | spin_unlock_irqrestore(&db->lock, flags); | 330 | raw_spin_unlock_irqrestore(&db->lock, flags); |
331 | debug_object_fixup(descr->fixup_init, addr, state); | 331 | debug_object_fixup(descr->fixup_init, addr, state); |
332 | return; | 332 | return; |
333 | 333 | ||
@@ -338,7 +338,7 @@ __debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack) | |||
338 | break; | 338 | break; |
339 | } | 339 | } |
340 | 340 | ||
341 | spin_unlock_irqrestore(&db->lock, flags); | 341 | raw_spin_unlock_irqrestore(&db->lock, flags); |
342 | } | 342 | } |
343 | 343 | ||
344 | /** | 344 | /** |
@@ -385,7 +385,7 @@ void debug_object_activate(void *addr, struct debug_obj_descr *descr) | |||
385 | 385 | ||
386 | db = get_bucket((unsigned long) addr); | 386 | db = get_bucket((unsigned long) addr); |
387 | 387 | ||
388 | spin_lock_irqsave(&db->lock, flags); | 388 | raw_spin_lock_irqsave(&db->lock, flags); |
389 | 389 | ||
390 | obj = lookup_object(addr, db); | 390 | obj = lookup_object(addr, db); |
391 | if (obj) { | 391 | if (obj) { |
@@ -398,7 +398,7 @@ void debug_object_activate(void *addr, struct debug_obj_descr *descr) | |||
398 | case ODEBUG_STATE_ACTIVE: | 398 | case ODEBUG_STATE_ACTIVE: |
399 | debug_print_object(obj, "activate"); | 399 | debug_print_object(obj, "activate"); |
400 | state = obj->state; | 400 | state = obj->state; |
401 | spin_unlock_irqrestore(&db->lock, flags); | 401 | raw_spin_unlock_irqrestore(&db->lock, flags); |
402 | debug_object_fixup(descr->fixup_activate, addr, state); | 402 | debug_object_fixup(descr->fixup_activate, addr, state); |
403 | return; | 403 | return; |
404 | 404 | ||
@@ -408,11 +408,11 @@ void debug_object_activate(void *addr, struct debug_obj_descr *descr) | |||
408 | default: | 408 | default: |
409 | break; | 409 | break; |
410 | } | 410 | } |
411 | spin_unlock_irqrestore(&db->lock, flags); | 411 | raw_spin_unlock_irqrestore(&db->lock, flags); |
412 | return; | 412 | return; |
413 | } | 413 | } |
414 | 414 | ||
415 | spin_unlock_irqrestore(&db->lock, flags); | 415 | raw_spin_unlock_irqrestore(&db->lock, flags); |
416 | /* | 416 | /* |
417 | * This happens when a static object is activated. We | 417 | * This happens when a static object is activated. We |
418 | * let the type specific code decide whether this is | 418 | * let the type specific code decide whether this is |
@@ -438,7 +438,7 @@ void debug_object_deactivate(void *addr, struct debug_obj_descr *descr) | |||
438 | 438 | ||
439 | db = get_bucket((unsigned long) addr); | 439 | db = get_bucket((unsigned long) addr); |
440 | 440 | ||
441 | spin_lock_irqsave(&db->lock, flags); | 441 | raw_spin_lock_irqsave(&db->lock, flags); |
442 | 442 | ||
443 | obj = lookup_object(addr, db); | 443 | obj = lookup_object(addr, db); |
444 | if (obj) { | 444 | if (obj) { |
@@ -463,7 +463,7 @@ void debug_object_deactivate(void *addr, struct debug_obj_descr *descr) | |||
463 | debug_print_object(&o, "deactivate"); | 463 | debug_print_object(&o, "deactivate"); |
464 | } | 464 | } |
465 | 465 | ||
466 | spin_unlock_irqrestore(&db->lock, flags); | 466 | raw_spin_unlock_irqrestore(&db->lock, flags); |
467 | } | 467 | } |
468 | 468 | ||
469 | /** | 469 | /** |
@@ -483,7 +483,7 @@ void debug_object_destroy(void *addr, struct debug_obj_descr *descr) | |||
483 | 483 | ||
484 | db = get_bucket((unsigned long) addr); | 484 | db = get_bucket((unsigned long) addr); |
485 | 485 | ||
486 | spin_lock_irqsave(&db->lock, flags); | 486 | raw_spin_lock_irqsave(&db->lock, flags); |
487 | 487 | ||
488 | obj = lookup_object(addr, db); | 488 | obj = lookup_object(addr, db); |
489 | if (!obj) | 489 | if (!obj) |
@@ -498,7 +498,7 @@ void debug_object_destroy(void *addr, struct debug_obj_descr *descr) | |||
498 | case ODEBUG_STATE_ACTIVE: | 498 | case ODEBUG_STATE_ACTIVE: |
499 | debug_print_object(obj, "destroy"); | 499 | debug_print_object(obj, "destroy"); |
500 | state = obj->state; | 500 | state = obj->state; |
501 | spin_unlock_irqrestore(&db->lock, flags); | 501 | raw_spin_unlock_irqrestore(&db->lock, flags); |
502 | debug_object_fixup(descr->fixup_destroy, addr, state); | 502 | debug_object_fixup(descr->fixup_destroy, addr, state); |
503 | return; | 503 | return; |
504 | 504 | ||
@@ -509,7 +509,7 @@ void debug_object_destroy(void *addr, struct debug_obj_descr *descr) | |||
509 | break; | 509 | break; |
510 | } | 510 | } |
511 | out_unlock: | 511 | out_unlock: |
512 | spin_unlock_irqrestore(&db->lock, flags); | 512 | raw_spin_unlock_irqrestore(&db->lock, flags); |
513 | } | 513 | } |
514 | 514 | ||
515 | /** | 515 | /** |
@@ -529,7 +529,7 @@ void debug_object_free(void *addr, struct debug_obj_descr *descr) | |||
529 | 529 | ||
530 | db = get_bucket((unsigned long) addr); | 530 | db = get_bucket((unsigned long) addr); |
531 | 531 | ||
532 | spin_lock_irqsave(&db->lock, flags); | 532 | raw_spin_lock_irqsave(&db->lock, flags); |
533 | 533 | ||
534 | obj = lookup_object(addr, db); | 534 | obj = lookup_object(addr, db); |
535 | if (!obj) | 535 | if (!obj) |
@@ -539,17 +539,17 @@ void debug_object_free(void *addr, struct debug_obj_descr *descr) | |||
539 | case ODEBUG_STATE_ACTIVE: | 539 | case ODEBUG_STATE_ACTIVE: |
540 | debug_print_object(obj, "free"); | 540 | debug_print_object(obj, "free"); |
541 | state = obj->state; | 541 | state = obj->state; |
542 | spin_unlock_irqrestore(&db->lock, flags); | 542 | raw_spin_unlock_irqrestore(&db->lock, flags); |
543 | debug_object_fixup(descr->fixup_free, addr, state); | 543 | debug_object_fixup(descr->fixup_free, addr, state); |
544 | return; | 544 | return; |
545 | default: | 545 | default: |
546 | hlist_del(&obj->node); | 546 | hlist_del(&obj->node); |
547 | spin_unlock_irqrestore(&db->lock, flags); | 547 | raw_spin_unlock_irqrestore(&db->lock, flags); |
548 | free_object(obj); | 548 | free_object(obj); |
549 | return; | 549 | return; |
550 | } | 550 | } |
551 | out_unlock: | 551 | out_unlock: |
552 | spin_unlock_irqrestore(&db->lock, flags); | 552 | raw_spin_unlock_irqrestore(&db->lock, flags); |
553 | } | 553 | } |
554 | 554 | ||
555 | #ifdef CONFIG_DEBUG_OBJECTS_FREE | 555 | #ifdef CONFIG_DEBUG_OBJECTS_FREE |
@@ -575,7 +575,7 @@ static void __debug_check_no_obj_freed(const void *address, unsigned long size) | |||
575 | 575 | ||
576 | repeat: | 576 | repeat: |
577 | cnt = 0; | 577 | cnt = 0; |
578 | spin_lock_irqsave(&db->lock, flags); | 578 | raw_spin_lock_irqsave(&db->lock, flags); |
579 | hlist_for_each_entry_safe(obj, node, tmp, &db->list, node) { | 579 | hlist_for_each_entry_safe(obj, node, tmp, &db->list, node) { |
580 | cnt++; | 580 | cnt++; |
581 | oaddr = (unsigned long) obj->object; | 581 | oaddr = (unsigned long) obj->object; |
@@ -587,7 +587,7 @@ repeat: | |||
587 | debug_print_object(obj, "free"); | 587 | debug_print_object(obj, "free"); |
588 | descr = obj->descr; | 588 | descr = obj->descr; |
589 | state = obj->state; | 589 | state = obj->state; |
590 | spin_unlock_irqrestore(&db->lock, flags); | 590 | raw_spin_unlock_irqrestore(&db->lock, flags); |
591 | debug_object_fixup(descr->fixup_free, | 591 | debug_object_fixup(descr->fixup_free, |
592 | (void *) oaddr, state); | 592 | (void *) oaddr, state); |
593 | goto repeat; | 593 | goto repeat; |
@@ -597,7 +597,7 @@ repeat: | |||
597 | break; | 597 | break; |
598 | } | 598 | } |
599 | } | 599 | } |
600 | spin_unlock_irqrestore(&db->lock, flags); | 600 | raw_spin_unlock_irqrestore(&db->lock, flags); |
601 | 601 | ||
602 | /* Now free them */ | 602 | /* Now free them */ |
603 | hlist_for_each_entry_safe(obj, node, tmp, &freelist, node) { | 603 | hlist_for_each_entry_safe(obj, node, tmp, &freelist, node) { |
@@ -783,7 +783,7 @@ check_results(void *addr, enum debug_obj_state state, int fixups, int warnings) | |||
783 | 783 | ||
784 | db = get_bucket((unsigned long) addr); | 784 | db = get_bucket((unsigned long) addr); |
785 | 785 | ||
786 | spin_lock_irqsave(&db->lock, flags); | 786 | raw_spin_lock_irqsave(&db->lock, flags); |
787 | 787 | ||
788 | obj = lookup_object(addr, db); | 788 | obj = lookup_object(addr, db); |
789 | if (!obj && state != ODEBUG_STATE_NONE) { | 789 | if (!obj && state != ODEBUG_STATE_NONE) { |
@@ -807,7 +807,7 @@ check_results(void *addr, enum debug_obj_state state, int fixups, int warnings) | |||
807 | } | 807 | } |
808 | res = 0; | 808 | res = 0; |
809 | out: | 809 | out: |
810 | spin_unlock_irqrestore(&db->lock, flags); | 810 | raw_spin_unlock_irqrestore(&db->lock, flags); |
811 | if (res) | 811 | if (res) |
812 | debug_objects_enabled = 0; | 812 | debug_objects_enabled = 0; |
813 | return res; | 813 | return res; |
@@ -907,7 +907,7 @@ void __init debug_objects_early_init(void) | |||
907 | int i; | 907 | int i; |
908 | 908 | ||
909 | for (i = 0; i < ODEBUG_HASH_SIZE; i++) | 909 | for (i = 0; i < ODEBUG_HASH_SIZE; i++) |
910 | spin_lock_init(&obj_hash[i].lock); | 910 | raw_spin_lock_init(&obj_hash[i].lock); |
911 | 911 | ||
912 | for (i = 0; i < ODEBUG_POOL_SIZE; i++) | 912 | for (i = 0; i < ODEBUG_POOL_SIZE; i++) |
913 | hlist_add_head(&obj_static_pool[i].node, &obj_pool); | 913 | hlist_add_head(&obj_static_pool[i].node, &obj_pool); |
diff --git a/lib/decompress.c b/lib/decompress.c index d2842f571674..a7606815541f 100644 --- a/lib/decompress.c +++ b/lib/decompress.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/decompress/bunzip2.h> | 9 | #include <linux/decompress/bunzip2.h> |
10 | #include <linux/decompress/unlzma.h> | 10 | #include <linux/decompress/unlzma.h> |
11 | #include <linux/decompress/inflate.h> | 11 | #include <linux/decompress/inflate.h> |
12 | #include <linux/decompress/unlzo.h> | ||
12 | 13 | ||
13 | #include <linux/types.h> | 14 | #include <linux/types.h> |
14 | #include <linux/string.h> | 15 | #include <linux/string.h> |
@@ -22,6 +23,9 @@ | |||
22 | #ifndef CONFIG_DECOMPRESS_LZMA | 23 | #ifndef CONFIG_DECOMPRESS_LZMA |
23 | # define unlzma NULL | 24 | # define unlzma NULL |
24 | #endif | 25 | #endif |
26 | #ifndef CONFIG_DECOMPRESS_LZO | ||
27 | # define unlzo NULL | ||
28 | #endif | ||
25 | 29 | ||
26 | static const struct compress_format { | 30 | static const struct compress_format { |
27 | unsigned char magic[2]; | 31 | unsigned char magic[2]; |
@@ -32,6 +36,7 @@ static const struct compress_format { | |||
32 | { {037, 0236}, "gzip", gunzip }, | 36 | { {037, 0236}, "gzip", gunzip }, |
33 | { {0x42, 0x5a}, "bzip2", bunzip2 }, | 37 | { {0x42, 0x5a}, "bzip2", bunzip2 }, |
34 | { {0x5d, 0x00}, "lzma", unlzma }, | 38 | { {0x5d, 0x00}, "lzma", unlzma }, |
39 | { {0x89, 0x4c}, "lzo", unlzo }, | ||
35 | { {0, 0}, NULL, NULL } | 40 | { {0, 0}, NULL, NULL } |
36 | }; | 41 | }; |
37 | 42 | ||
diff --git a/lib/decompress_bunzip2.c b/lib/decompress_bunzip2.c index 76074209f9a2..a4e971dee102 100644 --- a/lib/decompress_bunzip2.c +++ b/lib/decompress_bunzip2.c | |||
@@ -637,6 +637,8 @@ static int INIT start_bunzip(struct bunzip_data **bdp, void *inbuf, int len, | |||
637 | 637 | ||
638 | /* Allocate bunzip_data. Most fields initialize to zero. */ | 638 | /* Allocate bunzip_data. Most fields initialize to zero. */ |
639 | bd = *bdp = malloc(i); | 639 | bd = *bdp = malloc(i); |
640 | if (!bd) | ||
641 | return RETVAL_OUT_OF_MEMORY; | ||
640 | memset(bd, 0, sizeof(struct bunzip_data)); | 642 | memset(bd, 0, sizeof(struct bunzip_data)); |
641 | /* Setup input buffer */ | 643 | /* Setup input buffer */ |
642 | bd->inbuf = inbuf; | 644 | bd->inbuf = inbuf; |
@@ -664,6 +666,8 @@ static int INIT start_bunzip(struct bunzip_data **bdp, void *inbuf, int len, | |||
664 | bd->dbufSize = 100000*(i-BZh0); | 666 | bd->dbufSize = 100000*(i-BZh0); |
665 | 667 | ||
666 | bd->dbuf = large_malloc(bd->dbufSize * sizeof(int)); | 668 | bd->dbuf = large_malloc(bd->dbufSize * sizeof(int)); |
669 | if (!bd->dbuf) | ||
670 | return RETVAL_OUT_OF_MEMORY; | ||
667 | return RETVAL_OK; | 671 | return RETVAL_OK; |
668 | } | 672 | } |
669 | 673 | ||
@@ -686,7 +690,7 @@ STATIC int INIT bunzip2(unsigned char *buf, int len, | |||
686 | 690 | ||
687 | if (!outbuf) { | 691 | if (!outbuf) { |
688 | error("Could not allocate output bufer"); | 692 | error("Could not allocate output bufer"); |
689 | return -1; | 693 | return RETVAL_OUT_OF_MEMORY; |
690 | } | 694 | } |
691 | if (buf) | 695 | if (buf) |
692 | inbuf = buf; | 696 | inbuf = buf; |
@@ -694,6 +698,7 @@ STATIC int INIT bunzip2(unsigned char *buf, int len, | |||
694 | inbuf = malloc(BZIP2_IOBUF_SIZE); | 698 | inbuf = malloc(BZIP2_IOBUF_SIZE); |
695 | if (!inbuf) { | 699 | if (!inbuf) { |
696 | error("Could not allocate input bufer"); | 700 | error("Could not allocate input bufer"); |
701 | i = RETVAL_OUT_OF_MEMORY; | ||
697 | goto exit_0; | 702 | goto exit_0; |
698 | } | 703 | } |
699 | i = start_bunzip(&bd, inbuf, len, fill); | 704 | i = start_bunzip(&bd, inbuf, len, fill); |
@@ -720,11 +725,14 @@ STATIC int INIT bunzip2(unsigned char *buf, int len, | |||
720 | } else if (i == RETVAL_UNEXPECTED_OUTPUT_EOF) { | 725 | } else if (i == RETVAL_UNEXPECTED_OUTPUT_EOF) { |
721 | error("Compressed file ends unexpectedly"); | 726 | error("Compressed file ends unexpectedly"); |
722 | } | 727 | } |
728 | if (!bd) | ||
729 | goto exit_1; | ||
723 | if (bd->dbuf) | 730 | if (bd->dbuf) |
724 | large_free(bd->dbuf); | 731 | large_free(bd->dbuf); |
725 | if (pos) | 732 | if (pos) |
726 | *pos = bd->inbufPos; | 733 | *pos = bd->inbufPos; |
727 | free(bd); | 734 | free(bd); |
735 | exit_1: | ||
728 | if (!buf) | 736 | if (!buf) |
729 | free(inbuf); | 737 | free(inbuf); |
730 | exit_0: | 738 | exit_0: |
diff --git a/lib/decompress_unlzo.c b/lib/decompress_unlzo.c new file mode 100644 index 000000000000..db521f45626e --- /dev/null +++ b/lib/decompress_unlzo.c | |||
@@ -0,0 +1,209 @@ | |||
1 | /* | ||
2 | * LZO decompressor for the Linux kernel. Code borrowed from the lzo | ||
3 | * implementation by Markus Franz Xaver Johannes Oberhumer. | ||
4 | * | ||
5 | * Linux kernel adaptation: | ||
6 | * Copyright (C) 2009 | ||
7 | * Albin Tonnerre, Free Electrons <albin.tonnerre@free-electrons.com> | ||
8 | * | ||
9 | * Original code: | ||
10 | * Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer | ||
11 | * All Rights Reserved. | ||
12 | * | ||
13 | * lzop and the LZO library are free software; you can redistribute them | ||
14 | * and/or modify them under the terms of the GNU General Public License as | ||
15 | * published by the Free Software Foundation; either version 2 of | ||
16 | * the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | * GNU General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; see the file COPYING. | ||
25 | * If not, write to the Free Software Foundation, Inc., | ||
26 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
27 | * | ||
28 | * Markus F.X.J. Oberhumer | ||
29 | * <markus@oberhumer.com> | ||
30 | * http://www.oberhumer.com/opensource/lzop/ | ||
31 | */ | ||
32 | |||
33 | #ifdef STATIC | ||
34 | #include "lzo/lzo1x_decompress.c" | ||
35 | #else | ||
36 | #include <linux/slab.h> | ||
37 | #include <linux/decompress/unlzo.h> | ||
38 | #endif | ||
39 | |||
40 | #include <linux/types.h> | ||
41 | #include <linux/lzo.h> | ||
42 | #include <linux/decompress/mm.h> | ||
43 | |||
44 | #include <linux/compiler.h> | ||
45 | #include <asm/unaligned.h> | ||
46 | |||
47 | static const unsigned char lzop_magic[] = { | ||
48 | 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a }; | ||
49 | |||
50 | #define LZO_BLOCK_SIZE (256*1024l) | ||
51 | #define HEADER_HAS_FILTER 0x00000800L | ||
52 | |||
53 | STATIC inline int INIT parse_header(u8 *input, u8 *skip) | ||
54 | { | ||
55 | int l; | ||
56 | u8 *parse = input; | ||
57 | u8 level = 0; | ||
58 | u16 version; | ||
59 | |||
60 | /* read magic: 9 first bits */ | ||
61 | for (l = 0; l < 9; l++) { | ||
62 | if (*parse++ != lzop_magic[l]) | ||
63 | return 0; | ||
64 | } | ||
65 | /* get version (2bytes), skip library version (2), | ||
66 | * 'need to be extracted' version (2) and | ||
67 | * method (1) */ | ||
68 | version = get_unaligned_be16(parse); | ||
69 | parse += 7; | ||
70 | if (version >= 0x0940) | ||
71 | level = *parse++; | ||
72 | if (get_unaligned_be32(parse) & HEADER_HAS_FILTER) | ||
73 | parse += 8; /* flags + filter info */ | ||
74 | else | ||
75 | parse += 4; /* flags */ | ||
76 | |||
77 | /* skip mode and mtime_low */ | ||
78 | parse += 8; | ||
79 | if (version >= 0x0940) | ||
80 | parse += 4; /* skip mtime_high */ | ||
81 | |||
82 | l = *parse++; | ||
83 | /* don't care about the file name, and skip checksum */ | ||
84 | parse += l + 4; | ||
85 | |||
86 | *skip = parse - input; | ||
87 | return 1; | ||
88 | } | ||
89 | |||
90 | STATIC inline int INIT unlzo(u8 *input, int in_len, | ||
91 | int (*fill) (void *, unsigned int), | ||
92 | int (*flush) (void *, unsigned int), | ||
93 | u8 *output, int *posp, | ||
94 | void (*error_fn) (char *x)) | ||
95 | { | ||
96 | u8 skip = 0, r = 0; | ||
97 | u32 src_len, dst_len; | ||
98 | size_t tmp; | ||
99 | u8 *in_buf, *in_buf_save, *out_buf; | ||
100 | int obytes_processed = 0; | ||
101 | |||
102 | set_error_fn(error_fn); | ||
103 | |||
104 | if (output) { | ||
105 | out_buf = output; | ||
106 | } else if (!flush) { | ||
107 | error("NULL output pointer and no flush function provided"); | ||
108 | goto exit; | ||
109 | } else { | ||
110 | out_buf = malloc(LZO_BLOCK_SIZE); | ||
111 | if (!out_buf) { | ||
112 | error("Could not allocate output buffer"); | ||
113 | goto exit; | ||
114 | } | ||
115 | } | ||
116 | |||
117 | if (input && fill) { | ||
118 | error("Both input pointer and fill function provided, don't know what to do"); | ||
119 | goto exit_1; | ||
120 | } else if (input) { | ||
121 | in_buf = input; | ||
122 | } else if (!fill || !posp) { | ||
123 | error("NULL input pointer and missing position pointer or fill function"); | ||
124 | goto exit_1; | ||
125 | } else { | ||
126 | in_buf = malloc(lzo1x_worst_compress(LZO_BLOCK_SIZE)); | ||
127 | if (!in_buf) { | ||
128 | error("Could not allocate input buffer"); | ||
129 | goto exit_1; | ||
130 | } | ||
131 | } | ||
132 | in_buf_save = in_buf; | ||
133 | |||
134 | if (posp) | ||
135 | *posp = 0; | ||
136 | |||
137 | if (fill) | ||
138 | fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE)); | ||
139 | |||
140 | if (!parse_header(input, &skip)) { | ||
141 | error("invalid header"); | ||
142 | goto exit_2; | ||
143 | } | ||
144 | in_buf += skip; | ||
145 | |||
146 | if (posp) | ||
147 | *posp = skip; | ||
148 | |||
149 | for (;;) { | ||
150 | /* read uncompressed block size */ | ||
151 | dst_len = get_unaligned_be32(in_buf); | ||
152 | in_buf += 4; | ||
153 | |||
154 | /* exit if last block */ | ||
155 | if (dst_len == 0) { | ||
156 | if (posp) | ||
157 | *posp += 4; | ||
158 | break; | ||
159 | } | ||
160 | |||
161 | if (dst_len > LZO_BLOCK_SIZE) { | ||
162 | error("dest len longer than block size"); | ||
163 | goto exit_2; | ||
164 | } | ||
165 | |||
166 | /* read compressed block size, and skip block checksum info */ | ||
167 | src_len = get_unaligned_be32(in_buf); | ||
168 | in_buf += 8; | ||
169 | |||
170 | if (src_len <= 0 || src_len > dst_len) { | ||
171 | error("file corrupted"); | ||
172 | goto exit_2; | ||
173 | } | ||
174 | |||
175 | /* decompress */ | ||
176 | tmp = dst_len; | ||
177 | r = lzo1x_decompress_safe((u8 *) in_buf, src_len, | ||
178 | out_buf, &tmp); | ||
179 | |||
180 | if (r != LZO_E_OK || dst_len != tmp) { | ||
181 | error("Compressed data violation"); | ||
182 | goto exit_2; | ||
183 | } | ||
184 | |||
185 | obytes_processed += dst_len; | ||
186 | if (flush) | ||
187 | flush(out_buf, dst_len); | ||
188 | if (output) | ||
189 | out_buf += dst_len; | ||
190 | if (posp) | ||
191 | *posp += src_len + 12; | ||
192 | if (fill) { | ||
193 | in_buf = in_buf_save; | ||
194 | fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE)); | ||
195 | } else | ||
196 | in_buf += src_len; | ||
197 | } | ||
198 | |||
199 | exit_2: | ||
200 | if (!input) | ||
201 | free(in_buf); | ||
202 | exit_1: | ||
203 | if (!output) | ||
204 | free(out_buf); | ||
205 | exit: | ||
206 | return obytes_processed; | ||
207 | } | ||
208 | |||
209 | #define decompress unlzo | ||
diff --git a/lib/dma-debug.c b/lib/dma-debug.c index d9b08e0f7f55..7d2f0b33e5a8 100644 --- a/lib/dma-debug.c +++ b/lib/dma-debug.c | |||
@@ -670,12 +670,13 @@ static int device_dma_allocations(struct device *dev) | |||
670 | return count; | 670 | return count; |
671 | } | 671 | } |
672 | 672 | ||
673 | static int dma_debug_device_change(struct notifier_block *nb, | 673 | static int dma_debug_device_change(struct notifier_block *nb, unsigned long action, void *data) |
674 | unsigned long action, void *data) | ||
675 | { | 674 | { |
676 | struct device *dev = data; | 675 | struct device *dev = data; |
677 | int count; | 676 | int count; |
678 | 677 | ||
678 | if (global_disable) | ||
679 | return 0; | ||
679 | 680 | ||
680 | switch (action) { | 681 | switch (action) { |
681 | case BUS_NOTIFY_UNBOUND_DRIVER: | 682 | case BUS_NOTIFY_UNBOUND_DRIVER: |
@@ -697,6 +698,9 @@ void dma_debug_add_bus(struct bus_type *bus) | |||
697 | { | 698 | { |
698 | struct notifier_block *nb; | 699 | struct notifier_block *nb; |
699 | 700 | ||
701 | if (global_disable) | ||
702 | return; | ||
703 | |||
700 | nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL); | 704 | nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL); |
701 | if (nb == NULL) { | 705 | if (nb == NULL) { |
702 | pr_err("dma_debug_add_bus: out of memory\n"); | 706 | pr_err("dma_debug_add_bus: out of memory\n"); |
@@ -909,6 +913,9 @@ static void check_sync(struct device *dev, | |||
909 | ref->size); | 913 | ref->size); |
910 | } | 914 | } |
911 | 915 | ||
916 | if (entry->direction == DMA_BIDIRECTIONAL) | ||
917 | goto out; | ||
918 | |||
912 | if (ref->direction != entry->direction) { | 919 | if (ref->direction != entry->direction) { |
913 | err_printk(dev, entry, "DMA-API: device driver syncs " | 920 | err_printk(dev, entry, "DMA-API: device driver syncs " |
914 | "DMA memory with different direction " | 921 | "DMA memory with different direction " |
@@ -919,9 +926,6 @@ static void check_sync(struct device *dev, | |||
919 | dir2name[ref->direction]); | 926 | dir2name[ref->direction]); |
920 | } | 927 | } |
921 | 928 | ||
922 | if (entry->direction == DMA_BIDIRECTIONAL) | ||
923 | goto out; | ||
924 | |||
925 | if (to_cpu && !(entry->direction == DMA_FROM_DEVICE) && | 929 | if (to_cpu && !(entry->direction == DMA_FROM_DEVICE) && |
926 | !(ref->direction == DMA_TO_DEVICE)) | 930 | !(ref->direction == DMA_TO_DEVICE)) |
927 | err_printk(dev, entry, "DMA-API: device driver syncs " | 931 | err_printk(dev, entry, "DMA-API: device driver syncs " |
@@ -944,7 +948,6 @@ static void check_sync(struct device *dev, | |||
944 | 948 | ||
945 | out: | 949 | out: |
946 | put_hash_bucket(bucket, &flags); | 950 | put_hash_bucket(bucket, &flags); |
947 | |||
948 | } | 951 | } |
949 | 952 | ||
950 | void debug_dma_map_page(struct device *dev, struct page *page, size_t offset, | 953 | void debug_dma_map_page(struct device *dev, struct page *page, size_t offset, |
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index e22c148e4b7f..f93502915988 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/list.h> | 21 | #include <linux/list.h> |
22 | #include <linux/sysctl.h> | 22 | #include <linux/sysctl.h> |
23 | #include <linux/ctype.h> | 23 | #include <linux/ctype.h> |
24 | #include <linux/string.h> | ||
24 | #include <linux/uaccess.h> | 25 | #include <linux/uaccess.h> |
25 | #include <linux/dynamic_debug.h> | 26 | #include <linux/dynamic_debug.h> |
26 | #include <linux/debugfs.h> | 27 | #include <linux/debugfs.h> |
@@ -209,8 +210,7 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords) | |||
209 | char *end; | 210 | char *end; |
210 | 211 | ||
211 | /* Skip leading whitespace */ | 212 | /* Skip leading whitespace */ |
212 | while (*buf && isspace(*buf)) | 213 | buf = skip_spaces(buf); |
213 | buf++; | ||
214 | if (!*buf) | 214 | if (!*buf) |
215 | break; /* oh, it was trailing whitespace */ | 215 | break; /* oh, it was trailing whitespace */ |
216 | 216 | ||
diff --git a/lib/genalloc.c b/lib/genalloc.c index eed2bdb865e7..e67f97495dd5 100644 --- a/lib/genalloc.c +++ b/lib/genalloc.c | |||
@@ -11,6 +11,7 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/bitmap.h> | ||
14 | #include <linux/genalloc.h> | 15 | #include <linux/genalloc.h> |
15 | 16 | ||
16 | 17 | ||
@@ -114,7 +115,7 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size) | |||
114 | struct gen_pool_chunk *chunk; | 115 | struct gen_pool_chunk *chunk; |
115 | unsigned long addr, flags; | 116 | unsigned long addr, flags; |
116 | int order = pool->min_alloc_order; | 117 | int order = pool->min_alloc_order; |
117 | int nbits, bit, start_bit, end_bit; | 118 | int nbits, start_bit, end_bit; |
118 | 119 | ||
119 | if (size == 0) | 120 | if (size == 0) |
120 | return 0; | 121 | return 0; |
@@ -129,29 +130,19 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size) | |||
129 | end_bit -= nbits + 1; | 130 | end_bit -= nbits + 1; |
130 | 131 | ||
131 | spin_lock_irqsave(&chunk->lock, flags); | 132 | spin_lock_irqsave(&chunk->lock, flags); |
132 | bit = -1; | 133 | start_bit = bitmap_find_next_zero_area(chunk->bits, end_bit, 0, |
133 | while (bit + 1 < end_bit) { | 134 | nbits, 0); |
134 | bit = find_next_zero_bit(chunk->bits, end_bit, bit + 1); | 135 | if (start_bit >= end_bit) { |
135 | if (bit >= end_bit) | ||
136 | break; | ||
137 | |||
138 | start_bit = bit; | ||
139 | if (nbits > 1) { | ||
140 | bit = find_next_bit(chunk->bits, bit + nbits, | ||
141 | bit + 1); | ||
142 | if (bit - start_bit < nbits) | ||
143 | continue; | ||
144 | } | ||
145 | |||
146 | addr = chunk->start_addr + | ||
147 | ((unsigned long)start_bit << order); | ||
148 | while (nbits--) | ||
149 | __set_bit(start_bit++, chunk->bits); | ||
150 | spin_unlock_irqrestore(&chunk->lock, flags); | 136 | spin_unlock_irqrestore(&chunk->lock, flags); |
151 | read_unlock(&pool->lock); | 137 | continue; |
152 | return addr; | ||
153 | } | 138 | } |
139 | |||
140 | addr = chunk->start_addr + ((unsigned long)start_bit << order); | ||
141 | |||
142 | bitmap_set(chunk->bits, start_bit, nbits); | ||
154 | spin_unlock_irqrestore(&chunk->lock, flags); | 143 | spin_unlock_irqrestore(&chunk->lock, flags); |
144 | read_unlock(&pool->lock); | ||
145 | return addr; | ||
155 | } | 146 | } |
156 | read_unlock(&pool->lock); | 147 | read_unlock(&pool->lock); |
157 | return 0; | 148 | return 0; |
diff --git a/lib/iommu-helper.c b/lib/iommu-helper.c index 75dbda03f4fb..c0251f4ad08b 100644 --- a/lib/iommu-helper.c +++ b/lib/iommu-helper.c | |||
@@ -3,41 +3,7 @@ | |||
3 | */ | 3 | */ |
4 | 4 | ||
5 | #include <linux/module.h> | 5 | #include <linux/module.h> |
6 | #include <linux/bitops.h> | 6 | #include <linux/bitmap.h> |
7 | |||
8 | static unsigned long find_next_zero_area(unsigned long *map, | ||
9 | unsigned long size, | ||
10 | unsigned long start, | ||
11 | unsigned int nr, | ||
12 | unsigned long align_mask) | ||
13 | { | ||
14 | unsigned long index, end, i; | ||
15 | again: | ||
16 | index = find_next_zero_bit(map, size, start); | ||
17 | |||
18 | /* Align allocation */ | ||
19 | index = (index + align_mask) & ~align_mask; | ||
20 | |||
21 | end = index + nr; | ||
22 | if (end >= size) | ||
23 | return -1; | ||
24 | for (i = index; i < end; i++) { | ||
25 | if (test_bit(i, map)) { | ||
26 | start = i+1; | ||
27 | goto again; | ||
28 | } | ||
29 | } | ||
30 | return index; | ||
31 | } | ||
32 | |||
33 | void iommu_area_reserve(unsigned long *map, unsigned long i, int len) | ||
34 | { | ||
35 | unsigned long end = i + len; | ||
36 | while (i < end) { | ||
37 | __set_bit(i, map); | ||
38 | i++; | ||
39 | } | ||
40 | } | ||
41 | 7 | ||
42 | int iommu_is_span_boundary(unsigned int index, unsigned int nr, | 8 | int iommu_is_span_boundary(unsigned int index, unsigned int nr, |
43 | unsigned long shift, | 9 | unsigned long shift, |
@@ -55,31 +21,24 @@ unsigned long iommu_area_alloc(unsigned long *map, unsigned long size, | |||
55 | unsigned long align_mask) | 21 | unsigned long align_mask) |
56 | { | 22 | { |
57 | unsigned long index; | 23 | unsigned long index; |
24 | |||
25 | /* We don't want the last of the limit */ | ||
26 | size -= 1; | ||
58 | again: | 27 | again: |
59 | index = find_next_zero_area(map, size, start, nr, align_mask); | 28 | index = bitmap_find_next_zero_area(map, size, start, nr, align_mask); |
60 | if (index != -1) { | 29 | if (index < size) { |
61 | if (iommu_is_span_boundary(index, nr, shift, boundary_size)) { | 30 | if (iommu_is_span_boundary(index, nr, shift, boundary_size)) { |
62 | /* we could do more effectively */ | 31 | /* we could do more effectively */ |
63 | start = index + 1; | 32 | start = index + 1; |
64 | goto again; | 33 | goto again; |
65 | } | 34 | } |
66 | iommu_area_reserve(map, index, nr); | 35 | bitmap_set(map, index, nr); |
36 | return index; | ||
67 | } | 37 | } |
68 | return index; | 38 | return -1; |
69 | } | 39 | } |
70 | EXPORT_SYMBOL(iommu_area_alloc); | 40 | EXPORT_SYMBOL(iommu_area_alloc); |
71 | 41 | ||
72 | void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr) | ||
73 | { | ||
74 | unsigned long end = start + nr; | ||
75 | |||
76 | while (start < end) { | ||
77 | __clear_bit(start, map); | ||
78 | start++; | ||
79 | } | ||
80 | } | ||
81 | EXPORT_SYMBOL(iommu_area_free); | ||
82 | |||
83 | unsigned long iommu_num_pages(unsigned long addr, unsigned long len, | 42 | unsigned long iommu_num_pages(unsigned long addr, unsigned long len, |
84 | unsigned long io_page_size) | 43 | unsigned long io_page_size) |
85 | { | 44 | { |
diff --git a/lib/kernel_lock.c b/lib/kernel_lock.c index 5526b46aba94..b135d04aa48a 100644 --- a/lib/kernel_lock.c +++ b/lib/kernel_lock.c | |||
@@ -23,7 +23,7 @@ | |||
23 | * | 23 | * |
24 | * Don't use in new code. | 24 | * Don't use in new code. |
25 | */ | 25 | */ |
26 | static __cacheline_aligned_in_smp DEFINE_SPINLOCK(kernel_flag); | 26 | static __cacheline_aligned_in_smp DEFINE_RAW_SPINLOCK(kernel_flag); |
27 | 27 | ||
28 | 28 | ||
29 | /* | 29 | /* |
@@ -36,12 +36,12 @@ static __cacheline_aligned_in_smp DEFINE_SPINLOCK(kernel_flag); | |||
36 | * If it successfully gets the lock, it should increment | 36 | * If it successfully gets the lock, it should increment |
37 | * the preemption count like any spinlock does. | 37 | * the preemption count like any spinlock does. |
38 | * | 38 | * |
39 | * (This works on UP too - _raw_spin_trylock will never | 39 | * (This works on UP too - do_raw_spin_trylock will never |
40 | * return false in that case) | 40 | * return false in that case) |
41 | */ | 41 | */ |
42 | int __lockfunc __reacquire_kernel_lock(void) | 42 | int __lockfunc __reacquire_kernel_lock(void) |
43 | { | 43 | { |
44 | while (!_raw_spin_trylock(&kernel_flag)) { | 44 | while (!do_raw_spin_trylock(&kernel_flag)) { |
45 | if (need_resched()) | 45 | if (need_resched()) |
46 | return -EAGAIN; | 46 | return -EAGAIN; |
47 | cpu_relax(); | 47 | cpu_relax(); |
@@ -52,27 +52,27 @@ int __lockfunc __reacquire_kernel_lock(void) | |||
52 | 52 | ||
53 | void __lockfunc __release_kernel_lock(void) | 53 | void __lockfunc __release_kernel_lock(void) |
54 | { | 54 | { |
55 | _raw_spin_unlock(&kernel_flag); | 55 | do_raw_spin_unlock(&kernel_flag); |
56 | preempt_enable_no_resched(); | 56 | preempt_enable_no_resched(); |
57 | } | 57 | } |
58 | 58 | ||
59 | /* | 59 | /* |
60 | * These are the BKL spinlocks - we try to be polite about preemption. | 60 | * These are the BKL spinlocks - we try to be polite about preemption. |
61 | * If SMP is not on (ie UP preemption), this all goes away because the | 61 | * If SMP is not on (ie UP preemption), this all goes away because the |
62 | * _raw_spin_trylock() will always succeed. | 62 | * do_raw_spin_trylock() will always succeed. |
63 | */ | 63 | */ |
64 | #ifdef CONFIG_PREEMPT | 64 | #ifdef CONFIG_PREEMPT |
65 | static inline void __lock_kernel(void) | 65 | static inline void __lock_kernel(void) |
66 | { | 66 | { |
67 | preempt_disable(); | 67 | preempt_disable(); |
68 | if (unlikely(!_raw_spin_trylock(&kernel_flag))) { | 68 | if (unlikely(!do_raw_spin_trylock(&kernel_flag))) { |
69 | /* | 69 | /* |
70 | * If preemption was disabled even before this | 70 | * If preemption was disabled even before this |
71 | * was called, there's nothing we can be polite | 71 | * was called, there's nothing we can be polite |
72 | * about - just spin. | 72 | * about - just spin. |
73 | */ | 73 | */ |
74 | if (preempt_count() > 1) { | 74 | if (preempt_count() > 1) { |
75 | _raw_spin_lock(&kernel_flag); | 75 | do_raw_spin_lock(&kernel_flag); |
76 | return; | 76 | return; |
77 | } | 77 | } |
78 | 78 | ||
@@ -82,10 +82,10 @@ static inline void __lock_kernel(void) | |||
82 | */ | 82 | */ |
83 | do { | 83 | do { |
84 | preempt_enable(); | 84 | preempt_enable(); |
85 | while (spin_is_locked(&kernel_flag)) | 85 | while (raw_spin_is_locked(&kernel_flag)) |
86 | cpu_relax(); | 86 | cpu_relax(); |
87 | preempt_disable(); | 87 | preempt_disable(); |
88 | } while (!_raw_spin_trylock(&kernel_flag)); | 88 | } while (!do_raw_spin_trylock(&kernel_flag)); |
89 | } | 89 | } |
90 | } | 90 | } |
91 | 91 | ||
@@ -96,7 +96,7 @@ static inline void __lock_kernel(void) | |||
96 | */ | 96 | */ |
97 | static inline void __lock_kernel(void) | 97 | static inline void __lock_kernel(void) |
98 | { | 98 | { |
99 | _raw_spin_lock(&kernel_flag); | 99 | do_raw_spin_lock(&kernel_flag); |
100 | } | 100 | } |
101 | #endif | 101 | #endif |
102 | 102 | ||
@@ -106,7 +106,7 @@ static inline void __unlock_kernel(void) | |||
106 | * the BKL is not covered by lockdep, so we open-code the | 106 | * the BKL is not covered by lockdep, so we open-code the |
107 | * unlocking sequence (and thus avoid the dep-chain ops): | 107 | * unlocking sequence (and thus avoid the dep-chain ops): |
108 | */ | 108 | */ |
109 | _raw_spin_unlock(&kernel_flag); | 109 | do_raw_spin_unlock(&kernel_flag); |
110 | preempt_enable(); | 110 | preempt_enable(); |
111 | } | 111 | } |
112 | 112 | ||
diff --git a/lib/list_sort.c b/lib/list_sort.c new file mode 100644 index 000000000000..19d11e0bb958 --- /dev/null +++ b/lib/list_sort.c | |||
@@ -0,0 +1,102 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/module.h> | ||
3 | #include <linux/list_sort.h> | ||
4 | #include <linux/slab.h> | ||
5 | #include <linux/list.h> | ||
6 | |||
7 | /** | ||
8 | * list_sort - sort a list. | ||
9 | * @priv: private data, passed to @cmp | ||
10 | * @head: the list to sort | ||
11 | * @cmp: the elements comparison function | ||
12 | * | ||
13 | * This function has been implemented by Mark J Roberts <mjr@znex.org>. It | ||
14 | * implements "merge sort" which has O(nlog(n)) complexity. The list is sorted | ||
15 | * in ascending order. | ||
16 | * | ||
17 | * The comparison function @cmp is supposed to return a negative value if @a is | ||
18 | * less than @b, and a positive value if @a is greater than @b. If @a and @b | ||
19 | * are equivalent, then it does not matter what this function returns. | ||
20 | */ | ||
21 | void list_sort(void *priv, struct list_head *head, | ||
22 | int (*cmp)(void *priv, struct list_head *a, | ||
23 | struct list_head *b)) | ||
24 | { | ||
25 | struct list_head *p, *q, *e, *list, *tail, *oldhead; | ||
26 | int insize, nmerges, psize, qsize, i; | ||
27 | |||
28 | if (list_empty(head)) | ||
29 | return; | ||
30 | |||
31 | list = head->next; | ||
32 | list_del(head); | ||
33 | insize = 1; | ||
34 | for (;;) { | ||
35 | p = oldhead = list; | ||
36 | list = tail = NULL; | ||
37 | nmerges = 0; | ||
38 | |||
39 | while (p) { | ||
40 | nmerges++; | ||
41 | q = p; | ||
42 | psize = 0; | ||
43 | for (i = 0; i < insize; i++) { | ||
44 | psize++; | ||
45 | q = q->next == oldhead ? NULL : q->next; | ||
46 | if (!q) | ||
47 | break; | ||
48 | } | ||
49 | |||
50 | qsize = insize; | ||
51 | while (psize > 0 || (qsize > 0 && q)) { | ||
52 | if (!psize) { | ||
53 | e = q; | ||
54 | q = q->next; | ||
55 | qsize--; | ||
56 | if (q == oldhead) | ||
57 | q = NULL; | ||
58 | } else if (!qsize || !q) { | ||
59 | e = p; | ||
60 | p = p->next; | ||
61 | psize--; | ||
62 | if (p == oldhead) | ||
63 | p = NULL; | ||
64 | } else if (cmp(priv, p, q) <= 0) { | ||
65 | e = p; | ||
66 | p = p->next; | ||
67 | psize--; | ||
68 | if (p == oldhead) | ||
69 | p = NULL; | ||
70 | } else { | ||
71 | e = q; | ||
72 | q = q->next; | ||
73 | qsize--; | ||
74 | if (q == oldhead) | ||
75 | q = NULL; | ||
76 | } | ||
77 | if (tail) | ||
78 | tail->next = e; | ||
79 | else | ||
80 | list = e; | ||
81 | e->prev = tail; | ||
82 | tail = e; | ||
83 | } | ||
84 | p = q; | ||
85 | } | ||
86 | |||
87 | tail->next = list; | ||
88 | list->prev = tail; | ||
89 | |||
90 | if (nmerges <= 1) | ||
91 | break; | ||
92 | |||
93 | insize *= 2; | ||
94 | } | ||
95 | |||
96 | head->next = list; | ||
97 | head->prev = list->prev; | ||
98 | list->prev->next = head; | ||
99 | list->prev = head; | ||
100 | } | ||
101 | |||
102 | EXPORT_SYMBOL(list_sort); | ||
@@ -263,7 +263,7 @@ long __init lmb_reserve(u64 base, u64 size) | |||
263 | return lmb_add_region(_rgn, base, size); | 263 | return lmb_add_region(_rgn, base, size); |
264 | } | 264 | } |
265 | 265 | ||
266 | long __init lmb_overlaps_region(struct lmb_region *rgn, u64 base, u64 size) | 266 | long lmb_overlaps_region(struct lmb_region *rgn, u64 base, u64 size) |
267 | { | 267 | { |
268 | unsigned long i; | 268 | unsigned long i; |
269 | 269 | ||
@@ -493,6 +493,11 @@ int __init lmb_is_reserved(u64 addr) | |||
493 | return 0; | 493 | return 0; |
494 | } | 494 | } |
495 | 495 | ||
496 | int lmb_is_region_reserved(u64 base, u64 size) | ||
497 | { | ||
498 | return lmb_overlaps_region(&lmb.reserved, base, size); | ||
499 | } | ||
500 | |||
496 | /* | 501 | /* |
497 | * Given a <base, len>, find which memory regions belong to this range. | 502 | * Given a <base, len>, find which memory regions belong to this range. |
498 | * Adjust the request and return a contiguous chunk. | 503 | * Adjust the request and return a contiguous chunk. |
diff --git a/lib/lzo/lzo1x_decompress.c b/lib/lzo/lzo1x_decompress.c index 5dc6b29c1575..f2fd09850223 100644 --- a/lib/lzo/lzo1x_decompress.c +++ b/lib/lzo/lzo1x_decompress.c | |||
@@ -11,11 +11,13 @@ | |||
11 | * Richard Purdie <rpurdie@openedhand.com> | 11 | * Richard Purdie <rpurdie@openedhand.com> |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #ifndef STATIC | ||
14 | #include <linux/module.h> | 15 | #include <linux/module.h> |
15 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
16 | #include <linux/lzo.h> | 17 | #endif |
17 | #include <asm/byteorder.h> | 18 | |
18 | #include <asm/unaligned.h> | 19 | #include <asm/unaligned.h> |
20 | #include <linux/lzo.h> | ||
19 | #include "lzodefs.h" | 21 | #include "lzodefs.h" |
20 | 22 | ||
21 | #define HAVE_IP(x, ip_end, ip) ((size_t)(ip_end - ip) < (x)) | 23 | #define HAVE_IP(x, ip_end, ip) ((size_t)(ip_end - ip) < (x)) |
@@ -244,9 +246,10 @@ lookbehind_overrun: | |||
244 | *out_len = op - out; | 246 | *out_len = op - out; |
245 | return LZO_E_LOOKBEHIND_OVERRUN; | 247 | return LZO_E_LOOKBEHIND_OVERRUN; |
246 | } | 248 | } |
247 | 249 | #ifndef STATIC | |
248 | EXPORT_SYMBOL_GPL(lzo1x_decompress_safe); | 250 | EXPORT_SYMBOL_GPL(lzo1x_decompress_safe); |
249 | 251 | ||
250 | MODULE_LICENSE("GPL"); | 252 | MODULE_LICENSE("GPL"); |
251 | MODULE_DESCRIPTION("LZO1X Decompressor"); | 253 | MODULE_DESCRIPTION("LZO1X Decompressor"); |
252 | 254 | ||
255 | #endif | ||
diff --git a/lib/parser.c b/lib/parser.c index b00d02059a5f..fb34977246bb 100644 --- a/lib/parser.c +++ b/lib/parser.c | |||
@@ -56,13 +56,16 @@ static int match_one(char *s, const char *p, substring_t args[]) | |||
56 | 56 | ||
57 | args[argc].from = s; | 57 | args[argc].from = s; |
58 | switch (*p++) { | 58 | switch (*p++) { |
59 | case 's': | 59 | case 's': { |
60 | if (strlen(s) == 0) | 60 | size_t str_len = strlen(s); |
61 | |||
62 | if (str_len == 0) | ||
61 | return 0; | 63 | return 0; |
62 | else if (len == -1 || len > strlen(s)) | 64 | if (len == -1 || len > str_len) |
63 | len = strlen(s); | 65 | len = str_len; |
64 | args[argc].to = s + len; | 66 | args[argc].to = s + len; |
65 | break; | 67 | break; |
68 | } | ||
66 | case 'd': | 69 | case 'd': |
67 | simple_strtol(s, &args[argc].to, 0); | 70 | simple_strtol(s, &args[argc].to, 0); |
68 | goto num; | 71 | goto num; |
diff --git a/lib/plist.c b/lib/plist.c index d6c64a824e1d..1471988d9190 100644 --- a/lib/plist.c +++ b/lib/plist.c | |||
@@ -54,9 +54,11 @@ static void plist_check_list(struct list_head *top) | |||
54 | 54 | ||
55 | static void plist_check_head(struct plist_head *head) | 55 | static void plist_check_head(struct plist_head *head) |
56 | { | 56 | { |
57 | WARN_ON(!head->lock); | 57 | WARN_ON(!head->rawlock && !head->spinlock); |
58 | if (head->lock) | 58 | if (head->rawlock) |
59 | WARN_ON_SMP(!spin_is_locked(head->lock)); | 59 | WARN_ON_SMP(!raw_spin_is_locked(head->rawlock)); |
60 | if (head->spinlock) | ||
61 | WARN_ON_SMP(!spin_is_locked(head->spinlock)); | ||
60 | plist_check_list(&head->prio_list); | 62 | plist_check_list(&head->prio_list); |
61 | plist_check_list(&head->node_list); | 63 | plist_check_list(&head->node_list); |
62 | } | 64 | } |
diff --git a/lib/rational.c b/lib/rational.c index b3c099b5478e..3ed247b80662 100644 --- a/lib/rational.c +++ b/lib/rational.c | |||
@@ -7,6 +7,7 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/rational.h> | 9 | #include <linux/rational.h> |
10 | #include <linux/module.h> | ||
10 | 11 | ||
11 | /* | 12 | /* |
12 | * calculate best rational approximation for a given fraction | 13 | * calculate best rational approximation for a given fraction |
diff --git a/lib/rwsem-spinlock.c b/lib/rwsem-spinlock.c index 9df3ca56db11..ccf95bff7984 100644 --- a/lib/rwsem-spinlock.c +++ b/lib/rwsem-spinlock.c | |||
@@ -17,6 +17,19 @@ struct rwsem_waiter { | |||
17 | #define RWSEM_WAITING_FOR_WRITE 0x00000002 | 17 | #define RWSEM_WAITING_FOR_WRITE 0x00000002 |
18 | }; | 18 | }; |
19 | 19 | ||
20 | int rwsem_is_locked(struct rw_semaphore *sem) | ||
21 | { | ||
22 | int ret = 1; | ||
23 | unsigned long flags; | ||
24 | |||
25 | if (spin_trylock_irqsave(&sem->wait_lock, flags)) { | ||
26 | ret = (sem->activity != 0); | ||
27 | spin_unlock_irqrestore(&sem->wait_lock, flags); | ||
28 | } | ||
29 | return ret; | ||
30 | } | ||
31 | EXPORT_SYMBOL(rwsem_is_locked); | ||
32 | |||
20 | /* | 33 | /* |
21 | * initialise the semaphore | 34 | * initialise the semaphore |
22 | */ | 35 | */ |
@@ -34,6 +47,7 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name, | |||
34 | spin_lock_init(&sem->wait_lock); | 47 | spin_lock_init(&sem->wait_lock); |
35 | INIT_LIST_HEAD(&sem->wait_list); | 48 | INIT_LIST_HEAD(&sem->wait_list); |
36 | } | 49 | } |
50 | EXPORT_SYMBOL(__init_rwsem); | ||
37 | 51 | ||
38 | /* | 52 | /* |
39 | * handle the lock release when processes blocked on it that can now run | 53 | * handle the lock release when processes blocked on it that can now run |
@@ -305,12 +319,3 @@ void __downgrade_write(struct rw_semaphore *sem) | |||
305 | spin_unlock_irqrestore(&sem->wait_lock, flags); | 319 | spin_unlock_irqrestore(&sem->wait_lock, flags); |
306 | } | 320 | } |
307 | 321 | ||
308 | EXPORT_SYMBOL(__init_rwsem); | ||
309 | EXPORT_SYMBOL(__down_read); | ||
310 | EXPORT_SYMBOL(__down_read_trylock); | ||
311 | EXPORT_SYMBOL(__down_write_nested); | ||
312 | EXPORT_SYMBOL(__down_write); | ||
313 | EXPORT_SYMBOL(__down_write_trylock); | ||
314 | EXPORT_SYMBOL(__up_read); | ||
315 | EXPORT_SYMBOL(__up_write); | ||
316 | EXPORT_SYMBOL(__downgrade_write); | ||
diff --git a/lib/spinlock_debug.c b/lib/spinlock_debug.c index 9c4b0256490b..4755b98b6dfb 100644 --- a/lib/spinlock_debug.c +++ b/lib/spinlock_debug.c | |||
@@ -13,8 +13,8 @@ | |||
13 | #include <linux/delay.h> | 13 | #include <linux/delay.h> |
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | 15 | ||
16 | void __spin_lock_init(spinlock_t *lock, const char *name, | 16 | void __raw_spin_lock_init(raw_spinlock_t *lock, const char *name, |
17 | struct lock_class_key *key) | 17 | struct lock_class_key *key) |
18 | { | 18 | { |
19 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 19 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
20 | /* | 20 | /* |
@@ -23,13 +23,13 @@ void __spin_lock_init(spinlock_t *lock, const char *name, | |||
23 | debug_check_no_locks_freed((void *)lock, sizeof(*lock)); | 23 | debug_check_no_locks_freed((void *)lock, sizeof(*lock)); |
24 | lockdep_init_map(&lock->dep_map, name, key, 0); | 24 | lockdep_init_map(&lock->dep_map, name, key, 0); |
25 | #endif | 25 | #endif |
26 | lock->raw_lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; | 26 | lock->raw_lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
27 | lock->magic = SPINLOCK_MAGIC; | 27 | lock->magic = SPINLOCK_MAGIC; |
28 | lock->owner = SPINLOCK_OWNER_INIT; | 28 | lock->owner = SPINLOCK_OWNER_INIT; |
29 | lock->owner_cpu = -1; | 29 | lock->owner_cpu = -1; |
30 | } | 30 | } |
31 | 31 | ||
32 | EXPORT_SYMBOL(__spin_lock_init); | 32 | EXPORT_SYMBOL(__raw_spin_lock_init); |
33 | 33 | ||
34 | void __rwlock_init(rwlock_t *lock, const char *name, | 34 | void __rwlock_init(rwlock_t *lock, const char *name, |
35 | struct lock_class_key *key) | 35 | struct lock_class_key *key) |
@@ -41,7 +41,7 @@ void __rwlock_init(rwlock_t *lock, const char *name, | |||
41 | debug_check_no_locks_freed((void *)lock, sizeof(*lock)); | 41 | debug_check_no_locks_freed((void *)lock, sizeof(*lock)); |
42 | lockdep_init_map(&lock->dep_map, name, key, 0); | 42 | lockdep_init_map(&lock->dep_map, name, key, 0); |
43 | #endif | 43 | #endif |
44 | lock->raw_lock = (raw_rwlock_t) __RAW_RW_LOCK_UNLOCKED; | 44 | lock->raw_lock = (arch_rwlock_t) __ARCH_RW_LOCK_UNLOCKED; |
45 | lock->magic = RWLOCK_MAGIC; | 45 | lock->magic = RWLOCK_MAGIC; |
46 | lock->owner = SPINLOCK_OWNER_INIT; | 46 | lock->owner = SPINLOCK_OWNER_INIT; |
47 | lock->owner_cpu = -1; | 47 | lock->owner_cpu = -1; |
@@ -49,7 +49,7 @@ void __rwlock_init(rwlock_t *lock, const char *name, | |||
49 | 49 | ||
50 | EXPORT_SYMBOL(__rwlock_init); | 50 | EXPORT_SYMBOL(__rwlock_init); |
51 | 51 | ||
52 | static void spin_bug(spinlock_t *lock, const char *msg) | 52 | static void spin_bug(raw_spinlock_t *lock, const char *msg) |
53 | { | 53 | { |
54 | struct task_struct *owner = NULL; | 54 | struct task_struct *owner = NULL; |
55 | 55 | ||
@@ -73,7 +73,7 @@ static void spin_bug(spinlock_t *lock, const char *msg) | |||
73 | #define SPIN_BUG_ON(cond, lock, msg) if (unlikely(cond)) spin_bug(lock, msg) | 73 | #define SPIN_BUG_ON(cond, lock, msg) if (unlikely(cond)) spin_bug(lock, msg) |
74 | 74 | ||
75 | static inline void | 75 | static inline void |
76 | debug_spin_lock_before(spinlock_t *lock) | 76 | debug_spin_lock_before(raw_spinlock_t *lock) |
77 | { | 77 | { |
78 | SPIN_BUG_ON(lock->magic != SPINLOCK_MAGIC, lock, "bad magic"); | 78 | SPIN_BUG_ON(lock->magic != SPINLOCK_MAGIC, lock, "bad magic"); |
79 | SPIN_BUG_ON(lock->owner == current, lock, "recursion"); | 79 | SPIN_BUG_ON(lock->owner == current, lock, "recursion"); |
@@ -81,16 +81,16 @@ debug_spin_lock_before(spinlock_t *lock) | |||
81 | lock, "cpu recursion"); | 81 | lock, "cpu recursion"); |
82 | } | 82 | } |
83 | 83 | ||
84 | static inline void debug_spin_lock_after(spinlock_t *lock) | 84 | static inline void debug_spin_lock_after(raw_spinlock_t *lock) |
85 | { | 85 | { |
86 | lock->owner_cpu = raw_smp_processor_id(); | 86 | lock->owner_cpu = raw_smp_processor_id(); |
87 | lock->owner = current; | 87 | lock->owner = current; |
88 | } | 88 | } |
89 | 89 | ||
90 | static inline void debug_spin_unlock(spinlock_t *lock) | 90 | static inline void debug_spin_unlock(raw_spinlock_t *lock) |
91 | { | 91 | { |
92 | SPIN_BUG_ON(lock->magic != SPINLOCK_MAGIC, lock, "bad magic"); | 92 | SPIN_BUG_ON(lock->magic != SPINLOCK_MAGIC, lock, "bad magic"); |
93 | SPIN_BUG_ON(!spin_is_locked(lock), lock, "already unlocked"); | 93 | SPIN_BUG_ON(!raw_spin_is_locked(lock), lock, "already unlocked"); |
94 | SPIN_BUG_ON(lock->owner != current, lock, "wrong owner"); | 94 | SPIN_BUG_ON(lock->owner != current, lock, "wrong owner"); |
95 | SPIN_BUG_ON(lock->owner_cpu != raw_smp_processor_id(), | 95 | SPIN_BUG_ON(lock->owner_cpu != raw_smp_processor_id(), |
96 | lock, "wrong CPU"); | 96 | lock, "wrong CPU"); |
@@ -98,7 +98,7 @@ static inline void debug_spin_unlock(spinlock_t *lock) | |||
98 | lock->owner_cpu = -1; | 98 | lock->owner_cpu = -1; |
99 | } | 99 | } |
100 | 100 | ||
101 | static void __spin_lock_debug(spinlock_t *lock) | 101 | static void __spin_lock_debug(raw_spinlock_t *lock) |
102 | { | 102 | { |
103 | u64 i; | 103 | u64 i; |
104 | u64 loops = loops_per_jiffy * HZ; | 104 | u64 loops = loops_per_jiffy * HZ; |
@@ -106,7 +106,7 @@ static void __spin_lock_debug(spinlock_t *lock) | |||
106 | 106 | ||
107 | for (;;) { | 107 | for (;;) { |
108 | for (i = 0; i < loops; i++) { | 108 | for (i = 0; i < loops; i++) { |
109 | if (__raw_spin_trylock(&lock->raw_lock)) | 109 | if (arch_spin_trylock(&lock->raw_lock)) |
110 | return; | 110 | return; |
111 | __delay(1); | 111 | __delay(1); |
112 | } | 112 | } |
@@ -125,17 +125,17 @@ static void __spin_lock_debug(spinlock_t *lock) | |||
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | void _raw_spin_lock(spinlock_t *lock) | 128 | void do_raw_spin_lock(raw_spinlock_t *lock) |
129 | { | 129 | { |
130 | debug_spin_lock_before(lock); | 130 | debug_spin_lock_before(lock); |
131 | if (unlikely(!__raw_spin_trylock(&lock->raw_lock))) | 131 | if (unlikely(!arch_spin_trylock(&lock->raw_lock))) |
132 | __spin_lock_debug(lock); | 132 | __spin_lock_debug(lock); |
133 | debug_spin_lock_after(lock); | 133 | debug_spin_lock_after(lock); |
134 | } | 134 | } |
135 | 135 | ||
136 | int _raw_spin_trylock(spinlock_t *lock) | 136 | int do_raw_spin_trylock(raw_spinlock_t *lock) |
137 | { | 137 | { |
138 | int ret = __raw_spin_trylock(&lock->raw_lock); | 138 | int ret = arch_spin_trylock(&lock->raw_lock); |
139 | 139 | ||
140 | if (ret) | 140 | if (ret) |
141 | debug_spin_lock_after(lock); | 141 | debug_spin_lock_after(lock); |
@@ -148,10 +148,10 @@ int _raw_spin_trylock(spinlock_t *lock) | |||
148 | return ret; | 148 | return ret; |
149 | } | 149 | } |
150 | 150 | ||
151 | void _raw_spin_unlock(spinlock_t *lock) | 151 | void do_raw_spin_unlock(raw_spinlock_t *lock) |
152 | { | 152 | { |
153 | debug_spin_unlock(lock); | 153 | debug_spin_unlock(lock); |
154 | __raw_spin_unlock(&lock->raw_lock); | 154 | arch_spin_unlock(&lock->raw_lock); |
155 | } | 155 | } |
156 | 156 | ||
157 | static void rwlock_bug(rwlock_t *lock, const char *msg) | 157 | static void rwlock_bug(rwlock_t *lock, const char *msg) |
@@ -176,7 +176,7 @@ static void __read_lock_debug(rwlock_t *lock) | |||
176 | 176 | ||
177 | for (;;) { | 177 | for (;;) { |
178 | for (i = 0; i < loops; i++) { | 178 | for (i = 0; i < loops; i++) { |
179 | if (__raw_read_trylock(&lock->raw_lock)) | 179 | if (arch_read_trylock(&lock->raw_lock)) |
180 | return; | 180 | return; |
181 | __delay(1); | 181 | __delay(1); |
182 | } | 182 | } |
@@ -193,15 +193,15 @@ static void __read_lock_debug(rwlock_t *lock) | |||
193 | } | 193 | } |
194 | #endif | 194 | #endif |
195 | 195 | ||
196 | void _raw_read_lock(rwlock_t *lock) | 196 | void do_raw_read_lock(rwlock_t *lock) |
197 | { | 197 | { |
198 | RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic"); | 198 | RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic"); |
199 | __raw_read_lock(&lock->raw_lock); | 199 | arch_read_lock(&lock->raw_lock); |
200 | } | 200 | } |
201 | 201 | ||
202 | int _raw_read_trylock(rwlock_t *lock) | 202 | int do_raw_read_trylock(rwlock_t *lock) |
203 | { | 203 | { |
204 | int ret = __raw_read_trylock(&lock->raw_lock); | 204 | int ret = arch_read_trylock(&lock->raw_lock); |
205 | 205 | ||
206 | #ifndef CONFIG_SMP | 206 | #ifndef CONFIG_SMP |
207 | /* | 207 | /* |
@@ -212,10 +212,10 @@ int _raw_read_trylock(rwlock_t *lock) | |||
212 | return ret; | 212 | return ret; |
213 | } | 213 | } |
214 | 214 | ||
215 | void _raw_read_unlock(rwlock_t *lock) | 215 | void do_raw_read_unlock(rwlock_t *lock) |
216 | { | 216 | { |
217 | RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic"); | 217 | RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic"); |
218 | __raw_read_unlock(&lock->raw_lock); | 218 | arch_read_unlock(&lock->raw_lock); |
219 | } | 219 | } |
220 | 220 | ||
221 | static inline void debug_write_lock_before(rwlock_t *lock) | 221 | static inline void debug_write_lock_before(rwlock_t *lock) |
@@ -251,7 +251,7 @@ static void __write_lock_debug(rwlock_t *lock) | |||
251 | 251 | ||
252 | for (;;) { | 252 | for (;;) { |
253 | for (i = 0; i < loops; i++) { | 253 | for (i = 0; i < loops; i++) { |
254 | if (__raw_write_trylock(&lock->raw_lock)) | 254 | if (arch_write_trylock(&lock->raw_lock)) |
255 | return; | 255 | return; |
256 | __delay(1); | 256 | __delay(1); |
257 | } | 257 | } |
@@ -268,16 +268,16 @@ static void __write_lock_debug(rwlock_t *lock) | |||
268 | } | 268 | } |
269 | #endif | 269 | #endif |
270 | 270 | ||
271 | void _raw_write_lock(rwlock_t *lock) | 271 | void do_raw_write_lock(rwlock_t *lock) |
272 | { | 272 | { |
273 | debug_write_lock_before(lock); | 273 | debug_write_lock_before(lock); |
274 | __raw_write_lock(&lock->raw_lock); | 274 | arch_write_lock(&lock->raw_lock); |
275 | debug_write_lock_after(lock); | 275 | debug_write_lock_after(lock); |
276 | } | 276 | } |
277 | 277 | ||
278 | int _raw_write_trylock(rwlock_t *lock) | 278 | int do_raw_write_trylock(rwlock_t *lock) |
279 | { | 279 | { |
280 | int ret = __raw_write_trylock(&lock->raw_lock); | 280 | int ret = arch_write_trylock(&lock->raw_lock); |
281 | 281 | ||
282 | if (ret) | 282 | if (ret) |
283 | debug_write_lock_after(lock); | 283 | debug_write_lock_after(lock); |
@@ -290,8 +290,8 @@ int _raw_write_trylock(rwlock_t *lock) | |||
290 | return ret; | 290 | return ret; |
291 | } | 291 | } |
292 | 292 | ||
293 | void _raw_write_unlock(rwlock_t *lock) | 293 | void do_raw_write_unlock(rwlock_t *lock) |
294 | { | 294 | { |
295 | debug_write_unlock(lock); | 295 | debug_write_unlock(lock); |
296 | __raw_write_unlock(&lock->raw_lock); | 296 | arch_write_unlock(&lock->raw_lock); |
297 | } | 297 | } |
diff --git a/lib/string.c b/lib/string.c index e96421ab9a9a..a1cdcfcc42d0 100644 --- a/lib/string.c +++ b/lib/string.c | |||
@@ -338,20 +338,34 @@ EXPORT_SYMBOL(strnchr); | |||
338 | #endif | 338 | #endif |
339 | 339 | ||
340 | /** | 340 | /** |
341 | * strstrip - Removes leading and trailing whitespace from @s. | 341 | * skip_spaces - Removes leading whitespace from @str. |
342 | * @str: The string to be stripped. | ||
343 | * | ||
344 | * Returns a pointer to the first non-whitespace character in @str. | ||
345 | */ | ||
346 | char *skip_spaces(const char *str) | ||
347 | { | ||
348 | while (isspace(*str)) | ||
349 | ++str; | ||
350 | return (char *)str; | ||
351 | } | ||
352 | EXPORT_SYMBOL(skip_spaces); | ||
353 | |||
354 | /** | ||
355 | * strim - Removes leading and trailing whitespace from @s. | ||
342 | * @s: The string to be stripped. | 356 | * @s: The string to be stripped. |
343 | * | 357 | * |
344 | * Note that the first trailing whitespace is replaced with a %NUL-terminator | 358 | * Note that the first trailing whitespace is replaced with a %NUL-terminator |
345 | * in the given string @s. Returns a pointer to the first non-whitespace | 359 | * in the given string @s. Returns a pointer to the first non-whitespace |
346 | * character in @s. | 360 | * character in @s. |
347 | */ | 361 | */ |
348 | char *strstrip(char *s) | 362 | char *strim(char *s) |
349 | { | 363 | { |
350 | size_t size; | 364 | size_t size; |
351 | char *end; | 365 | char *end; |
352 | 366 | ||
367 | s = skip_spaces(s); | ||
353 | size = strlen(s); | 368 | size = strlen(s); |
354 | |||
355 | if (!size) | 369 | if (!size) |
356 | return s; | 370 | return s; |
357 | 371 | ||
@@ -360,12 +374,9 @@ char *strstrip(char *s) | |||
360 | end--; | 374 | end--; |
361 | *(end + 1) = '\0'; | 375 | *(end + 1) = '\0'; |
362 | 376 | ||
363 | while (*s && isspace(*s)) | ||
364 | s++; | ||
365 | |||
366 | return s; | 377 | return s; |
367 | } | 378 | } |
368 | EXPORT_SYMBOL(strstrip); | 379 | EXPORT_SYMBOL(strim); |
369 | 380 | ||
370 | #ifndef __HAVE_ARCH_STRLEN | 381 | #ifndef __HAVE_ARCH_STRLEN |
371 | /** | 382 | /** |
@@ -656,7 +667,7 @@ EXPORT_SYMBOL(memscan); | |||
656 | */ | 667 | */ |
657 | char *strstr(const char *s1, const char *s2) | 668 | char *strstr(const char *s1, const char *s2) |
658 | { | 669 | { |
659 | int l1, l2; | 670 | size_t l1, l2; |
660 | 671 | ||
661 | l2 = strlen(s2); | 672 | l2 = strlen(s2); |
662 | if (!l2) | 673 | if (!l2) |
@@ -673,6 +684,31 @@ char *strstr(const char *s1, const char *s2) | |||
673 | EXPORT_SYMBOL(strstr); | 684 | EXPORT_SYMBOL(strstr); |
674 | #endif | 685 | #endif |
675 | 686 | ||
687 | #ifndef __HAVE_ARCH_STRNSTR | ||
688 | /** | ||
689 | * strnstr - Find the first substring in a length-limited string | ||
690 | * @s1: The string to be searched | ||
691 | * @s2: The string to search for | ||
692 | * @len: the maximum number of characters to search | ||
693 | */ | ||
694 | char *strnstr(const char *s1, const char *s2, size_t len) | ||
695 | { | ||
696 | size_t l1 = len, l2; | ||
697 | |||
698 | l2 = strlen(s2); | ||
699 | if (!l2) | ||
700 | return (char *)s1; | ||
701 | while (l1 >= l2) { | ||
702 | l1--; | ||
703 | if (!memcmp(s1, s2, l2)) | ||
704 | return (char *)s1; | ||
705 | s1++; | ||
706 | } | ||
707 | return NULL; | ||
708 | } | ||
709 | EXPORT_SYMBOL(strnstr); | ||
710 | #endif | ||
711 | |||
676 | #ifndef __HAVE_ARCH_MEMCHR | 712 | #ifndef __HAVE_ARCH_MEMCHR |
677 | /** | 713 | /** |
678 | * memchr - Find a character in an area of memory. | 714 | * memchr - Find a character in an area of memory. |
diff --git a/lib/swiotlb.c b/lib/swiotlb.c index 5bc01803f8f8..437eedb5a53b 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c | |||
@@ -549,7 +549,7 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size, | |||
549 | dma_mask = hwdev->coherent_dma_mask; | 549 | dma_mask = hwdev->coherent_dma_mask; |
550 | 550 | ||
551 | ret = (void *)__get_free_pages(flags, order); | 551 | ret = (void *)__get_free_pages(flags, order); |
552 | if (ret && swiotlb_virt_to_bus(hwdev, ret) + size > dma_mask) { | 552 | if (ret && swiotlb_virt_to_bus(hwdev, ret) + size - 1 > dma_mask) { |
553 | /* | 553 | /* |
554 | * The allocated memory isn't reachable by the device. | 554 | * The allocated memory isn't reachable by the device. |
555 | */ | 555 | */ |
@@ -571,7 +571,7 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size, | |||
571 | dev_addr = swiotlb_virt_to_bus(hwdev, ret); | 571 | dev_addr = swiotlb_virt_to_bus(hwdev, ret); |
572 | 572 | ||
573 | /* Confirm address can be DMA'd by device */ | 573 | /* Confirm address can be DMA'd by device */ |
574 | if (dev_addr + size > dma_mask) { | 574 | if (dev_addr + size - 1 > dma_mask) { |
575 | printk("hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n", | 575 | printk("hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n", |
576 | (unsigned long long)dma_mask, | 576 | (unsigned long long)dma_mask, |
577 | (unsigned long long)dev_addr); | 577 | (unsigned long long)dev_addr); |
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 6438cd5599ee..3b8aeec4e327 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * Wirzenius wrote this portably, Torvalds fucked it up :-) | 9 | * Wirzenius wrote this portably, Torvalds fucked it up :-) |
10 | */ | 10 | */ |
11 | 11 | ||
12 | /* | 12 | /* |
13 | * Fri Jul 13 2001 Crutcher Dunnavant <crutcher+kernel@datastacks.com> | 13 | * Fri Jul 13 2001 Crutcher Dunnavant <crutcher+kernel@datastacks.com> |
14 | * - changed to provide snprintf and vsnprintf functions | 14 | * - changed to provide snprintf and vsnprintf functions |
15 | * So Feb 1 16:51:32 CET 2004 Juergen Quade <quade@hsnr.de> | 15 | * So Feb 1 16:51:32 CET 2004 Juergen Quade <quade@hsnr.de> |
@@ -47,14 +47,14 @@ static unsigned int simple_guess_base(const char *cp) | |||
47 | } | 47 | } |
48 | 48 | ||
49 | /** | 49 | /** |
50 | * simple_strtoul - convert a string to an unsigned long | 50 | * simple_strtoull - convert a string to an unsigned long long |
51 | * @cp: The start of the string | 51 | * @cp: The start of the string |
52 | * @endp: A pointer to the end of the parsed string will be placed here | 52 | * @endp: A pointer to the end of the parsed string will be placed here |
53 | * @base: The number base to use | 53 | * @base: The number base to use |
54 | */ | 54 | */ |
55 | unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) | 55 | unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) |
56 | { | 56 | { |
57 | unsigned long result = 0; | 57 | unsigned long long result = 0; |
58 | 58 | ||
59 | if (!base) | 59 | if (!base) |
60 | base = simple_guess_base(cp); | 60 | base = simple_guess_base(cp); |
@@ -71,58 +71,39 @@ unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) | |||
71 | result = result * base + value; | 71 | result = result * base + value; |
72 | cp++; | 72 | cp++; |
73 | } | 73 | } |
74 | |||
75 | if (endp) | 74 | if (endp) |
76 | *endp = (char *)cp; | 75 | *endp = (char *)cp; |
76 | |||
77 | return result; | 77 | return result; |
78 | } | 78 | } |
79 | EXPORT_SYMBOL(simple_strtoul); | 79 | EXPORT_SYMBOL(simple_strtoull); |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * simple_strtol - convert a string to a signed long | 82 | * simple_strtoul - convert a string to an unsigned long |
83 | * @cp: The start of the string | 83 | * @cp: The start of the string |
84 | * @endp: A pointer to the end of the parsed string will be placed here | 84 | * @endp: A pointer to the end of the parsed string will be placed here |
85 | * @base: The number base to use | 85 | * @base: The number base to use |
86 | */ | 86 | */ |
87 | long simple_strtol(const char *cp, char **endp, unsigned int base) | 87 | unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) |
88 | { | 88 | { |
89 | if(*cp == '-') | 89 | return simple_strtoull(cp, endp, base); |
90 | return -simple_strtoul(cp + 1, endp, base); | ||
91 | return simple_strtoul(cp, endp, base); | ||
92 | } | 90 | } |
93 | EXPORT_SYMBOL(simple_strtol); | 91 | EXPORT_SYMBOL(simple_strtoul); |
94 | 92 | ||
95 | /** | 93 | /** |
96 | * simple_strtoull - convert a string to an unsigned long long | 94 | * simple_strtol - convert a string to a signed long |
97 | * @cp: The start of the string | 95 | * @cp: The start of the string |
98 | * @endp: A pointer to the end of the parsed string will be placed here | 96 | * @endp: A pointer to the end of the parsed string will be placed here |
99 | * @base: The number base to use | 97 | * @base: The number base to use |
100 | */ | 98 | */ |
101 | unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) | 99 | long simple_strtol(const char *cp, char **endp, unsigned int base) |
102 | { | 100 | { |
103 | unsigned long long result = 0; | 101 | if (*cp == '-') |
104 | 102 | return -simple_strtoul(cp + 1, endp, base); | |
105 | if (!base) | ||
106 | base = simple_guess_base(cp); | ||
107 | |||
108 | if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x') | ||
109 | cp += 2; | ||
110 | |||
111 | while (isxdigit(*cp)) { | ||
112 | unsigned int value; | ||
113 | |||
114 | value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10; | ||
115 | if (value >= base) | ||
116 | break; | ||
117 | result = result * base + value; | ||
118 | cp++; | ||
119 | } | ||
120 | 103 | ||
121 | if (endp) | 104 | return simple_strtoul(cp, endp, base); |
122 | *endp = (char *)cp; | ||
123 | return result; | ||
124 | } | 105 | } |
125 | EXPORT_SYMBOL(simple_strtoull); | 106 | EXPORT_SYMBOL(simple_strtol); |
126 | 107 | ||
127 | /** | 108 | /** |
128 | * simple_strtoll - convert a string to a signed long long | 109 | * simple_strtoll - convert a string to a signed long long |
@@ -132,8 +113,9 @@ EXPORT_SYMBOL(simple_strtoull); | |||
132 | */ | 113 | */ |
133 | long long simple_strtoll(const char *cp, char **endp, unsigned int base) | 114 | long long simple_strtoll(const char *cp, char **endp, unsigned int base) |
134 | { | 115 | { |
135 | if(*cp=='-') | 116 | if (*cp == '-') |
136 | return -simple_strtoull(cp + 1, endp, base); | 117 | return -simple_strtoull(cp + 1, endp, base); |
118 | |||
137 | return simple_strtoull(cp, endp, base); | 119 | return simple_strtoull(cp, endp, base); |
138 | } | 120 | } |
139 | 121 | ||
@@ -173,6 +155,7 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res) | |||
173 | val = simple_strtoul(cp, &tail, base); | 155 | val = simple_strtoul(cp, &tail, base); |
174 | if (tail == cp) | 156 | if (tail == cp) |
175 | return -EINVAL; | 157 | return -EINVAL; |
158 | |||
176 | if ((*tail == '\0') || | 159 | if ((*tail == '\0') || |
177 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { | 160 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { |
178 | *res = val; | 161 | *res = val; |
@@ -285,10 +268,11 @@ EXPORT_SYMBOL(strict_strtoll); | |||
285 | 268 | ||
286 | static int skip_atoi(const char **s) | 269 | static int skip_atoi(const char **s) |
287 | { | 270 | { |
288 | int i=0; | 271 | int i = 0; |
289 | 272 | ||
290 | while (isdigit(**s)) | 273 | while (isdigit(**s)) |
291 | i = i*10 + *((*s)++) - '0'; | 274 | i = i*10 + *((*s)++) - '0'; |
275 | |||
292 | return i; | 276 | return i; |
293 | } | 277 | } |
294 | 278 | ||
@@ -302,7 +286,7 @@ static int skip_atoi(const char **s) | |||
302 | /* Formats correctly any integer in [0,99999]. | 286 | /* Formats correctly any integer in [0,99999]. |
303 | * Outputs from one to five digits depending on input. | 287 | * Outputs from one to five digits depending on input. |
304 | * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ | 288 | * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ |
305 | static char* put_dec_trunc(char *buf, unsigned q) | 289 | static char *put_dec_trunc(char *buf, unsigned q) |
306 | { | 290 | { |
307 | unsigned d3, d2, d1, d0; | 291 | unsigned d3, d2, d1, d0; |
308 | d1 = (q>>4) & 0xf; | 292 | d1 = (q>>4) & 0xf; |
@@ -331,14 +315,15 @@ static char* put_dec_trunc(char *buf, unsigned q) | |||
331 | d3 = d3 - 10*q; | 315 | d3 = d3 - 10*q; |
332 | *buf++ = d3 + '0'; /* next digit */ | 316 | *buf++ = d3 + '0'; /* next digit */ |
333 | if (q != 0) | 317 | if (q != 0) |
334 | *buf++ = q + '0'; /* most sign. digit */ | 318 | *buf++ = q + '0'; /* most sign. digit */ |
335 | } | 319 | } |
336 | } | 320 | } |
337 | } | 321 | } |
322 | |||
338 | return buf; | 323 | return buf; |
339 | } | 324 | } |
340 | /* Same with if's removed. Always emits five digits */ | 325 | /* Same with if's removed. Always emits five digits */ |
341 | static char* put_dec_full(char *buf, unsigned q) | 326 | static char *put_dec_full(char *buf, unsigned q) |
342 | { | 327 | { |
343 | /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ | 328 | /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ |
344 | /* but anyway, gcc produces better code with full-sized ints */ | 329 | /* but anyway, gcc produces better code with full-sized ints */ |
@@ -347,14 +332,15 @@ static char* put_dec_full(char *buf, unsigned q) | |||
347 | d2 = (q>>8) & 0xf; | 332 | d2 = (q>>8) & 0xf; |
348 | d3 = (q>>12); | 333 | d3 = (q>>12); |
349 | 334 | ||
350 | /* Possible ways to approx. divide by 10 */ | 335 | /* |
351 | /* gcc -O2 replaces multiply with shifts and adds */ | 336 | * Possible ways to approx. divide by 10 |
352 | // (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) | 337 | * gcc -O2 replaces multiply with shifts and adds |
353 | // (x * 0x67) >> 10: 1100111 | 338 | * (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) |
354 | // (x * 0x34) >> 9: 110100 - same | 339 | * (x * 0x67) >> 10: 1100111 |
355 | // (x * 0x1a) >> 8: 11010 - same | 340 | * (x * 0x34) >> 9: 110100 - same |
356 | // (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) | 341 | * (x * 0x1a) >> 8: 11010 - same |
357 | 342 | * (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) | |
343 | */ | ||
358 | d0 = 6*(d3 + d2 + d1) + (q & 0xf); | 344 | d0 = 6*(d3 + d2 + d1) + (q & 0xf); |
359 | q = (d0 * 0xcd) >> 11; | 345 | q = (d0 * 0xcd) >> 11; |
360 | d0 = d0 - 10*q; | 346 | d0 = d0 - 10*q; |
@@ -375,10 +361,11 @@ static char* put_dec_full(char *buf, unsigned q) | |||
375 | d3 = d3 - 10*q; | 361 | d3 = d3 - 10*q; |
376 | *buf++ = d3 + '0'; | 362 | *buf++ = d3 + '0'; |
377 | *buf++ = q + '0'; | 363 | *buf++ = q + '0'; |
364 | |||
378 | return buf; | 365 | return buf; |
379 | } | 366 | } |
380 | /* No inlining helps gcc to use registers better */ | 367 | /* No inlining helps gcc to use registers better */ |
381 | static noinline char* put_dec(char *buf, unsigned long long num) | 368 | static noinline char *put_dec(char *buf, unsigned long long num) |
382 | { | 369 | { |
383 | while (1) { | 370 | while (1) { |
384 | unsigned rem; | 371 | unsigned rem; |
@@ -448,9 +435,9 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
448 | spec.flags &= ~ZEROPAD; | 435 | spec.flags &= ~ZEROPAD; |
449 | sign = 0; | 436 | sign = 0; |
450 | if (spec.flags & SIGN) { | 437 | if (spec.flags & SIGN) { |
451 | if ((signed long long) num < 0) { | 438 | if ((signed long long)num < 0) { |
452 | sign = '-'; | 439 | sign = '-'; |
453 | num = - (signed long long) num; | 440 | num = -(signed long long)num; |
454 | spec.field_width--; | 441 | spec.field_width--; |
455 | } else if (spec.flags & PLUS) { | 442 | } else if (spec.flags & PLUS) { |
456 | sign = '+'; | 443 | sign = '+'; |
@@ -478,7 +465,9 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
478 | else if (spec.base != 10) { /* 8 or 16 */ | 465 | else if (spec.base != 10) { /* 8 or 16 */ |
479 | int mask = spec.base - 1; | 466 | int mask = spec.base - 1; |
480 | int shift = 3; | 467 | int shift = 3; |
481 | if (spec.base == 16) shift = 4; | 468 | |
469 | if (spec.base == 16) | ||
470 | shift = 4; | ||
482 | do { | 471 | do { |
483 | tmp[i++] = (digits[((unsigned char)num) & mask] | locase); | 472 | tmp[i++] = (digits[((unsigned char)num) & mask] | locase); |
484 | num >>= shift; | 473 | num >>= shift; |
@@ -493,7 +482,7 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
493 | /* leading space padding */ | 482 | /* leading space padding */ |
494 | spec.field_width -= spec.precision; | 483 | spec.field_width -= spec.precision; |
495 | if (!(spec.flags & (ZEROPAD+LEFT))) { | 484 | if (!(spec.flags & (ZEROPAD+LEFT))) { |
496 | while(--spec.field_width >= 0) { | 485 | while (--spec.field_width >= 0) { |
497 | if (buf < end) | 486 | if (buf < end) |
498 | *buf = ' '; | 487 | *buf = ' '; |
499 | ++buf; | 488 | ++buf; |
@@ -543,15 +532,16 @@ static char *number(char *buf, char *end, unsigned long long num, | |||
543 | *buf = ' '; | 532 | *buf = ' '; |
544 | ++buf; | 533 | ++buf; |
545 | } | 534 | } |
535 | |||
546 | return buf; | 536 | return buf; |
547 | } | 537 | } |
548 | 538 | ||
549 | static char *string(char *buf, char *end, char *s, struct printf_spec spec) | 539 | static char *string(char *buf, char *end, const char *s, struct printf_spec spec) |
550 | { | 540 | { |
551 | int len, i; | 541 | int len, i; |
552 | 542 | ||
553 | if ((unsigned long)s < PAGE_SIZE) | 543 | if ((unsigned long)s < PAGE_SIZE) |
554 | s = "<NULL>"; | 544 | s = "(null)"; |
555 | 545 | ||
556 | len = strnlen(s, spec.precision); | 546 | len = strnlen(s, spec.precision); |
557 | 547 | ||
@@ -572,6 +562,7 @@ static char *string(char *buf, char *end, char *s, struct printf_spec spec) | |||
572 | *buf = ' '; | 562 | *buf = ' '; |
573 | ++buf; | 563 | ++buf; |
574 | } | 564 | } |
565 | |||
575 | return buf; | 566 | return buf; |
576 | } | 567 | } |
577 | 568 | ||
@@ -585,11 +576,13 @@ static char *symbol_string(char *buf, char *end, void *ptr, | |||
585 | sprint_symbol(sym, value); | 576 | sprint_symbol(sym, value); |
586 | else | 577 | else |
587 | kallsyms_lookup(value, NULL, NULL, NULL, sym); | 578 | kallsyms_lookup(value, NULL, NULL, NULL, sym); |
579 | |||
588 | return string(buf, end, sym, spec); | 580 | return string(buf, end, sym, spec); |
589 | #else | 581 | #else |
590 | spec.field_width = 2*sizeof(void *); | 582 | spec.field_width = 2 * sizeof(void *); |
591 | spec.flags |= SPECIAL | SMALL | ZEROPAD; | 583 | spec.flags |= SPECIAL | SMALL | ZEROPAD; |
592 | spec.base = 16; | 584 | spec.base = 16; |
585 | |||
593 | return number(buf, end, value, spec); | 586 | return number(buf, end, value, spec); |
594 | #endif | 587 | #endif |
595 | } | 588 | } |
@@ -718,22 +711,19 @@ static char *ip4_string(char *p, const u8 *addr, bool leading_zeros) | |||
718 | if (i < 3) | 711 | if (i < 3) |
719 | *p++ = '.'; | 712 | *p++ = '.'; |
720 | } | 713 | } |
721 | |||
722 | *p = '\0'; | 714 | *p = '\0'; |
715 | |||
723 | return p; | 716 | return p; |
724 | } | 717 | } |
725 | 718 | ||
726 | static char *ip6_compressed_string(char *p, const char *addr) | 719 | static char *ip6_compressed_string(char *p, const char *addr) |
727 | { | 720 | { |
728 | int i; | 721 | int i, j, range; |
729 | int j; | ||
730 | int range; | ||
731 | unsigned char zerolength[8]; | 722 | unsigned char zerolength[8]; |
732 | int longest = 1; | 723 | int longest = 1; |
733 | int colonpos = -1; | 724 | int colonpos = -1; |
734 | u16 word; | 725 | u16 word; |
735 | u8 hi; | 726 | u8 hi, lo; |
736 | u8 lo; | ||
737 | bool needcolon = false; | 727 | bool needcolon = false; |
738 | bool useIPv4; | 728 | bool useIPv4; |
739 | struct in6_addr in6; | 729 | struct in6_addr in6; |
@@ -787,8 +777,9 @@ static char *ip6_compressed_string(char *p, const char *addr) | |||
787 | p = pack_hex_byte(p, hi); | 777 | p = pack_hex_byte(p, hi); |
788 | else | 778 | else |
789 | *p++ = hex_asc_lo(hi); | 779 | *p++ = hex_asc_lo(hi); |
780 | p = pack_hex_byte(p, lo); | ||
790 | } | 781 | } |
791 | if (hi || lo > 0x0f) | 782 | else if (lo > 0x0f) |
792 | p = pack_hex_byte(p, lo); | 783 | p = pack_hex_byte(p, lo); |
793 | else | 784 | else |
794 | *p++ = hex_asc_lo(lo); | 785 | *p++ = hex_asc_lo(lo); |
@@ -800,22 +791,23 @@ static char *ip6_compressed_string(char *p, const char *addr) | |||
800 | *p++ = ':'; | 791 | *p++ = ':'; |
801 | p = ip4_string(p, &in6.s6_addr[12], false); | 792 | p = ip4_string(p, &in6.s6_addr[12], false); |
802 | } | 793 | } |
803 | |||
804 | *p = '\0'; | 794 | *p = '\0'; |
795 | |||
805 | return p; | 796 | return p; |
806 | } | 797 | } |
807 | 798 | ||
808 | static char *ip6_string(char *p, const char *addr, const char *fmt) | 799 | static char *ip6_string(char *p, const char *addr, const char *fmt) |
809 | { | 800 | { |
810 | int i; | 801 | int i; |
802 | |||
811 | for (i = 0; i < 8; i++) { | 803 | for (i = 0; i < 8; i++) { |
812 | p = pack_hex_byte(p, *addr++); | 804 | p = pack_hex_byte(p, *addr++); |
813 | p = pack_hex_byte(p, *addr++); | 805 | p = pack_hex_byte(p, *addr++); |
814 | if (fmt[0] == 'I' && i != 7) | 806 | if (fmt[0] == 'I' && i != 7) |
815 | *p++ = ':'; | 807 | *p++ = ':'; |
816 | } | 808 | } |
817 | |||
818 | *p = '\0'; | 809 | *p = '\0'; |
810 | |||
819 | return p; | 811 | return p; |
820 | } | 812 | } |
821 | 813 | ||
@@ -842,6 +834,52 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | |||
842 | return string(buf, end, ip4_addr, spec); | 834 | return string(buf, end, ip4_addr, spec); |
843 | } | 835 | } |
844 | 836 | ||
837 | static char *uuid_string(char *buf, char *end, const u8 *addr, | ||
838 | struct printf_spec spec, const char *fmt) | ||
839 | { | ||
840 | char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]; | ||
841 | char *p = uuid; | ||
842 | int i; | ||
843 | static const u8 be[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; | ||
844 | static const u8 le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15}; | ||
845 | const u8 *index = be; | ||
846 | bool uc = false; | ||
847 | |||
848 | switch (*(++fmt)) { | ||
849 | case 'L': | ||
850 | uc = true; /* fall-through */ | ||
851 | case 'l': | ||
852 | index = le; | ||
853 | break; | ||
854 | case 'B': | ||
855 | uc = true; | ||
856 | break; | ||
857 | } | ||
858 | |||
859 | for (i = 0; i < 16; i++) { | ||
860 | p = pack_hex_byte(p, addr[index[i]]); | ||
861 | switch (i) { | ||
862 | case 3: | ||
863 | case 5: | ||
864 | case 7: | ||
865 | case 9: | ||
866 | *p++ = '-'; | ||
867 | break; | ||
868 | } | ||
869 | } | ||
870 | |||
871 | *p = 0; | ||
872 | |||
873 | if (uc) { | ||
874 | p = uuid; | ||
875 | do { | ||
876 | *p = toupper(*p); | ||
877 | } while (*(++p)); | ||
878 | } | ||
879 | |||
880 | return string(buf, end, uuid, spec); | ||
881 | } | ||
882 | |||
845 | /* | 883 | /* |
846 | * Show a '%p' thing. A kernel extension is that the '%p' is followed | 884 | * Show a '%p' thing. A kernel extension is that the '%p' is followed |
847 | * by an extra set of alphanumeric characters that are extended format | 885 | * by an extra set of alphanumeric characters that are extended format |
@@ -865,7 +903,19 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | |||
865 | * IPv6 omits the colons (01020304...0f) | 903 | * IPv6 omits the colons (01020304...0f) |
866 | * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006) | 904 | * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006) |
867 | * - 'I6c' for IPv6 addresses printed as specified by | 905 | * - 'I6c' for IPv6 addresses printed as specified by |
868 | * http://www.ietf.org/id/draft-kawamura-ipv6-text-representation-03.txt | 906 | * http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-00 |
907 | * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form | ||
908 | * "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | ||
909 | * Options for %pU are: | ||
910 | * b big endian lower case hex (default) | ||
911 | * B big endian UPPER case hex | ||
912 | * l little endian lower case hex | ||
913 | * L little endian UPPER case hex | ||
914 | * big endian output byte order is: | ||
915 | * [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15] | ||
916 | * little endian output byte order is: | ||
917 | * [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15] | ||
918 | * | ||
869 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 | 919 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 |
870 | * function pointers are really function descriptors, which contain a | 920 | * function pointers are really function descriptors, which contain a |
871 | * pointer to the real address. | 921 | * pointer to the real address. |
@@ -880,9 +930,9 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
880 | case 'F': | 930 | case 'F': |
881 | case 'f': | 931 | case 'f': |
882 | ptr = dereference_function_descriptor(ptr); | 932 | ptr = dereference_function_descriptor(ptr); |
883 | case 's': | ||
884 | /* Fallthrough */ | 933 | /* Fallthrough */ |
885 | case 'S': | 934 | case 'S': |
935 | case 's': | ||
886 | return symbol_string(buf, end, ptr, spec, *fmt); | 936 | return symbol_string(buf, end, ptr, spec, *fmt); |
887 | case 'R': | 937 | case 'R': |
888 | case 'r': | 938 | case 'r': |
@@ -906,6 +956,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
906 | return ip4_addr_string(buf, end, ptr, spec, fmt); | 956 | return ip4_addr_string(buf, end, ptr, spec, fmt); |
907 | } | 957 | } |
908 | break; | 958 | break; |
959 | case 'U': | ||
960 | return uuid_string(buf, end, ptr, spec, fmt); | ||
909 | } | 961 | } |
910 | spec.flags |= SMALL; | 962 | spec.flags |= SMALL; |
911 | if (spec.field_width == -1) { | 963 | if (spec.field_width == -1) { |
@@ -1023,8 +1075,8 @@ precision: | |||
1023 | qualifier: | 1075 | qualifier: |
1024 | /* get the conversion qualifier */ | 1076 | /* get the conversion qualifier */ |
1025 | spec->qualifier = -1; | 1077 | spec->qualifier = -1; |
1026 | if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || | 1078 | if (*fmt == 'h' || TOLOWER(*fmt) == 'l' || |
1027 | *fmt == 'Z' || *fmt == 'z' || *fmt == 't') { | 1079 | TOLOWER(*fmt) == 'z' || *fmt == 't') { |
1028 | spec->qualifier = *fmt++; | 1080 | spec->qualifier = *fmt++; |
1029 | if (unlikely(spec->qualifier == *fmt)) { | 1081 | if (unlikely(spec->qualifier == *fmt)) { |
1030 | if (spec->qualifier == 'l') { | 1082 | if (spec->qualifier == 'l') { |
@@ -1091,7 +1143,7 @@ qualifier: | |||
1091 | spec->type = FORMAT_TYPE_LONG; | 1143 | spec->type = FORMAT_TYPE_LONG; |
1092 | else | 1144 | else |
1093 | spec->type = FORMAT_TYPE_ULONG; | 1145 | spec->type = FORMAT_TYPE_ULONG; |
1094 | } else if (spec->qualifier == 'Z' || spec->qualifier == 'z') { | 1146 | } else if (TOLOWER(spec->qualifier) == 'z') { |
1095 | spec->type = FORMAT_TYPE_SIZE_T; | 1147 | spec->type = FORMAT_TYPE_SIZE_T; |
1096 | } else if (spec->qualifier == 't') { | 1148 | } else if (spec->qualifier == 't') { |
1097 | spec->type = FORMAT_TYPE_PTRDIFF; | 1149 | spec->type = FORMAT_TYPE_PTRDIFF; |
@@ -1127,7 +1179,18 @@ qualifier: | |||
1127 | * %ps output the name of a text symbol without offset | 1179 | * %ps output the name of a text symbol without offset |
1128 | * %pF output the name of a function pointer with its offset | 1180 | * %pF output the name of a function pointer with its offset |
1129 | * %pf output the name of a function pointer without its offset | 1181 | * %pf output the name of a function pointer without its offset |
1130 | * %pR output the address range in a struct resource | 1182 | * %pR output the address range in a struct resource with decoded flags |
1183 | * %pr output the address range in a struct resource with raw flags | ||
1184 | * %pM output a 6-byte MAC address with colons | ||
1185 | * %pm output a 6-byte MAC address without colons | ||
1186 | * %pI4 print an IPv4 address without leading zeros | ||
1187 | * %pi4 print an IPv4 address with leading zeros | ||
1188 | * %pI6 print an IPv6 address with colons | ||
1189 | * %pi6 print an IPv6 address without colons | ||
1190 | * %pI6c print an IPv6 address as specified by | ||
1191 | * http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-00 | ||
1192 | * %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper | ||
1193 | * case. | ||
1131 | * %n is ignored | 1194 | * %n is ignored |
1132 | * | 1195 | * |
1133 | * The return value is the number of characters which would | 1196 | * The return value is the number of characters which would |
@@ -1144,8 +1207,7 @@ qualifier: | |||
1144 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | 1207 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) |
1145 | { | 1208 | { |
1146 | unsigned long long num; | 1209 | unsigned long long num; |
1147 | char *str, *end, c; | 1210 | char *str, *end; |
1148 | int read; | ||
1149 | struct printf_spec spec = {0}; | 1211 | struct printf_spec spec = {0}; |
1150 | 1212 | ||
1151 | /* Reject out-of-range values early. Large positive sizes are | 1213 | /* Reject out-of-range values early. Large positive sizes are |
@@ -1164,8 +1226,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1164 | 1226 | ||
1165 | while (*fmt) { | 1227 | while (*fmt) { |
1166 | const char *old_fmt = fmt; | 1228 | const char *old_fmt = fmt; |
1167 | 1229 | int read = format_decode(fmt, &spec); | |
1168 | read = format_decode(fmt, &spec); | ||
1169 | 1230 | ||
1170 | fmt += read; | 1231 | fmt += read; |
1171 | 1232 | ||
@@ -1189,7 +1250,9 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1189 | spec.precision = va_arg(args, int); | 1250 | spec.precision = va_arg(args, int); |
1190 | break; | 1251 | break; |
1191 | 1252 | ||
1192 | case FORMAT_TYPE_CHAR: | 1253 | case FORMAT_TYPE_CHAR: { |
1254 | char c; | ||
1255 | |||
1193 | if (!(spec.flags & LEFT)) { | 1256 | if (!(spec.flags & LEFT)) { |
1194 | while (--spec.field_width > 0) { | 1257 | while (--spec.field_width > 0) { |
1195 | if (str < end) | 1258 | if (str < end) |
@@ -1208,6 +1271,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1208 | ++str; | 1271 | ++str; |
1209 | } | 1272 | } |
1210 | break; | 1273 | break; |
1274 | } | ||
1211 | 1275 | ||
1212 | case FORMAT_TYPE_STR: | 1276 | case FORMAT_TYPE_STR: |
1213 | str = string(str, end, va_arg(args, char *), spec); | 1277 | str = string(str, end, va_arg(args, char *), spec); |
@@ -1238,8 +1302,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1238 | if (qualifier == 'l') { | 1302 | if (qualifier == 'l') { |
1239 | long *ip = va_arg(args, long *); | 1303 | long *ip = va_arg(args, long *); |
1240 | *ip = (str - buf); | 1304 | *ip = (str - buf); |
1241 | } else if (qualifier == 'Z' || | 1305 | } else if (TOLOWER(qualifier) == 'z') { |
1242 | qualifier == 'z') { | ||
1243 | size_t *ip = va_arg(args, size_t *); | 1306 | size_t *ip = va_arg(args, size_t *); |
1244 | *ip = (str - buf); | 1307 | *ip = (str - buf); |
1245 | } else { | 1308 | } else { |
@@ -1322,7 +1385,8 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1322 | { | 1385 | { |
1323 | int i; | 1386 | int i; |
1324 | 1387 | ||
1325 | i=vsnprintf(buf,size,fmt,args); | 1388 | i = vsnprintf(buf, size, fmt, args); |
1389 | |||
1326 | return (i >= size) ? (size - 1) : i; | 1390 | return (i >= size) ? (size - 1) : i; |
1327 | } | 1391 | } |
1328 | EXPORT_SYMBOL(vscnprintf); | 1392 | EXPORT_SYMBOL(vscnprintf); |
@@ -1341,14 +1405,15 @@ EXPORT_SYMBOL(vscnprintf); | |||
1341 | * | 1405 | * |
1342 | * See the vsnprintf() documentation for format string extensions over C99. | 1406 | * See the vsnprintf() documentation for format string extensions over C99. |
1343 | */ | 1407 | */ |
1344 | int snprintf(char * buf, size_t size, const char *fmt, ...) | 1408 | int snprintf(char *buf, size_t size, const char *fmt, ...) |
1345 | { | 1409 | { |
1346 | va_list args; | 1410 | va_list args; |
1347 | int i; | 1411 | int i; |
1348 | 1412 | ||
1349 | va_start(args, fmt); | 1413 | va_start(args, fmt); |
1350 | i=vsnprintf(buf,size,fmt,args); | 1414 | i = vsnprintf(buf, size, fmt, args); |
1351 | va_end(args); | 1415 | va_end(args); |
1416 | |||
1352 | return i; | 1417 | return i; |
1353 | } | 1418 | } |
1354 | EXPORT_SYMBOL(snprintf); | 1419 | EXPORT_SYMBOL(snprintf); |
@@ -1364,7 +1429,7 @@ EXPORT_SYMBOL(snprintf); | |||
1364 | * the trailing '\0'. If @size is <= 0 the function returns 0. | 1429 | * the trailing '\0'. If @size is <= 0 the function returns 0. |
1365 | */ | 1430 | */ |
1366 | 1431 | ||
1367 | int scnprintf(char * buf, size_t size, const char *fmt, ...) | 1432 | int scnprintf(char *buf, size_t size, const char *fmt, ...) |
1368 | { | 1433 | { |
1369 | va_list args; | 1434 | va_list args; |
1370 | int i; | 1435 | int i; |
@@ -1372,6 +1437,7 @@ int scnprintf(char * buf, size_t size, const char *fmt, ...) | |||
1372 | va_start(args, fmt); | 1437 | va_start(args, fmt); |
1373 | i = vsnprintf(buf, size, fmt, args); | 1438 | i = vsnprintf(buf, size, fmt, args); |
1374 | va_end(args); | 1439 | va_end(args); |
1440 | |||
1375 | return (i >= size) ? (size - 1) : i; | 1441 | return (i >= size) ? (size - 1) : i; |
1376 | } | 1442 | } |
1377 | EXPORT_SYMBOL(scnprintf); | 1443 | EXPORT_SYMBOL(scnprintf); |
@@ -1409,14 +1475,15 @@ EXPORT_SYMBOL(vsprintf); | |||
1409 | * | 1475 | * |
1410 | * See the vsnprintf() documentation for format string extensions over C99. | 1476 | * See the vsnprintf() documentation for format string extensions over C99. |
1411 | */ | 1477 | */ |
1412 | int sprintf(char * buf, const char *fmt, ...) | 1478 | int sprintf(char *buf, const char *fmt, ...) |
1413 | { | 1479 | { |
1414 | va_list args; | 1480 | va_list args; |
1415 | int i; | 1481 | int i; |
1416 | 1482 | ||
1417 | va_start(args, fmt); | 1483 | va_start(args, fmt); |
1418 | i=vsnprintf(buf, INT_MAX, fmt, args); | 1484 | i = vsnprintf(buf, INT_MAX, fmt, args); |
1419 | va_end(args); | 1485 | va_end(args); |
1486 | |||
1420 | return i; | 1487 | return i; |
1421 | } | 1488 | } |
1422 | EXPORT_SYMBOL(sprintf); | 1489 | EXPORT_SYMBOL(sprintf); |
@@ -1449,7 +1516,6 @@ int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args) | |||
1449 | { | 1516 | { |
1450 | struct printf_spec spec = {0}; | 1517 | struct printf_spec spec = {0}; |
1451 | char *str, *end; | 1518 | char *str, *end; |
1452 | int read; | ||
1453 | 1519 | ||
1454 | str = (char *)bin_buf; | 1520 | str = (char *)bin_buf; |
1455 | end = (char *)(bin_buf + size); | 1521 | end = (char *)(bin_buf + size); |
@@ -1474,14 +1540,15 @@ do { \ | |||
1474 | str += sizeof(type); \ | 1540 | str += sizeof(type); \ |
1475 | } while (0) | 1541 | } while (0) |
1476 | 1542 | ||
1477 | |||
1478 | while (*fmt) { | 1543 | while (*fmt) { |
1479 | read = format_decode(fmt, &spec); | 1544 | int read = format_decode(fmt, &spec); |
1480 | 1545 | ||
1481 | fmt += read; | 1546 | fmt += read; |
1482 | 1547 | ||
1483 | switch (spec.type) { | 1548 | switch (spec.type) { |
1484 | case FORMAT_TYPE_NONE: | 1549 | case FORMAT_TYPE_NONE: |
1550 | case FORMAT_TYPE_INVALID: | ||
1551 | case FORMAT_TYPE_PERCENT_CHAR: | ||
1485 | break; | 1552 | break; |
1486 | 1553 | ||
1487 | case FORMAT_TYPE_WIDTH: | 1554 | case FORMAT_TYPE_WIDTH: |
@@ -1496,13 +1563,14 @@ do { \ | |||
1496 | case FORMAT_TYPE_STR: { | 1563 | case FORMAT_TYPE_STR: { |
1497 | const char *save_str = va_arg(args, char *); | 1564 | const char *save_str = va_arg(args, char *); |
1498 | size_t len; | 1565 | size_t len; |
1566 | |||
1499 | if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE | 1567 | if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE |
1500 | || (unsigned long)save_str < PAGE_SIZE) | 1568 | || (unsigned long)save_str < PAGE_SIZE) |
1501 | save_str = "<NULL>"; | 1569 | save_str = "(null)"; |
1502 | len = strlen(save_str); | 1570 | len = strlen(save_str) + 1; |
1503 | if (str + len + 1 < end) | 1571 | if (str + len < end) |
1504 | memcpy(str, save_str, len + 1); | 1572 | memcpy(str, save_str, len); |
1505 | str += len + 1; | 1573 | str += len; |
1506 | break; | 1574 | break; |
1507 | } | 1575 | } |
1508 | 1576 | ||
@@ -1513,19 +1581,13 @@ do { \ | |||
1513 | fmt++; | 1581 | fmt++; |
1514 | break; | 1582 | break; |
1515 | 1583 | ||
1516 | case FORMAT_TYPE_PERCENT_CHAR: | ||
1517 | break; | ||
1518 | |||
1519 | case FORMAT_TYPE_INVALID: | ||
1520 | break; | ||
1521 | |||
1522 | case FORMAT_TYPE_NRCHARS: { | 1584 | case FORMAT_TYPE_NRCHARS: { |
1523 | /* skip %n 's argument */ | 1585 | /* skip %n 's argument */ |
1524 | int qualifier = spec.qualifier; | 1586 | int qualifier = spec.qualifier; |
1525 | void *skip_arg; | 1587 | void *skip_arg; |
1526 | if (qualifier == 'l') | 1588 | if (qualifier == 'l') |
1527 | skip_arg = va_arg(args, long *); | 1589 | skip_arg = va_arg(args, long *); |
1528 | else if (qualifier == 'Z' || qualifier == 'z') | 1590 | else if (TOLOWER(qualifier) == 'z') |
1529 | skip_arg = va_arg(args, size_t *); | 1591 | skip_arg = va_arg(args, size_t *); |
1530 | else | 1592 | else |
1531 | skip_arg = va_arg(args, int *); | 1593 | skip_arg = va_arg(args, int *); |
@@ -1561,8 +1623,8 @@ do { \ | |||
1561 | } | 1623 | } |
1562 | } | 1624 | } |
1563 | } | 1625 | } |
1564 | return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; | ||
1565 | 1626 | ||
1627 | return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf; | ||
1566 | #undef save_arg | 1628 | #undef save_arg |
1567 | } | 1629 | } |
1568 | EXPORT_SYMBOL_GPL(vbin_printf); | 1630 | EXPORT_SYMBOL_GPL(vbin_printf); |
@@ -1591,11 +1653,9 @@ EXPORT_SYMBOL_GPL(vbin_printf); | |||
1591 | */ | 1653 | */ |
1592 | int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | 1654 | int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) |
1593 | { | 1655 | { |
1594 | unsigned long long num; | ||
1595 | char *str, *end, c; | ||
1596 | const char *args = (const char *)bin_buf; | ||
1597 | |||
1598 | struct printf_spec spec = {0}; | 1656 | struct printf_spec spec = {0}; |
1657 | char *str, *end; | ||
1658 | const char *args = (const char *)bin_buf; | ||
1599 | 1659 | ||
1600 | if (WARN_ON_ONCE((int) size < 0)) | 1660 | if (WARN_ON_ONCE((int) size < 0)) |
1601 | return 0; | 1661 | return 0; |
@@ -1625,10 +1685,8 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1625 | } | 1685 | } |
1626 | 1686 | ||
1627 | while (*fmt) { | 1687 | while (*fmt) { |
1628 | int read; | ||
1629 | const char *old_fmt = fmt; | 1688 | const char *old_fmt = fmt; |
1630 | 1689 | int read = format_decode(fmt, &spec); | |
1631 | read = format_decode(fmt, &spec); | ||
1632 | 1690 | ||
1633 | fmt += read; | 1691 | fmt += read; |
1634 | 1692 | ||
@@ -1652,7 +1710,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1652 | spec.precision = get_arg(int); | 1710 | spec.precision = get_arg(int); |
1653 | break; | 1711 | break; |
1654 | 1712 | ||
1655 | case FORMAT_TYPE_CHAR: | 1713 | case FORMAT_TYPE_CHAR: { |
1714 | char c; | ||
1715 | |||
1656 | if (!(spec.flags & LEFT)) { | 1716 | if (!(spec.flags & LEFT)) { |
1657 | while (--spec.field_width > 0) { | 1717 | while (--spec.field_width > 0) { |
1658 | if (str < end) | 1718 | if (str < end) |
@@ -1670,11 +1730,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1670 | ++str; | 1730 | ++str; |
1671 | } | 1731 | } |
1672 | break; | 1732 | break; |
1733 | } | ||
1673 | 1734 | ||
1674 | case FORMAT_TYPE_STR: { | 1735 | case FORMAT_TYPE_STR: { |
1675 | const char *str_arg = args; | 1736 | const char *str_arg = args; |
1676 | size_t len = strlen(str_arg); | 1737 | args += strlen(str_arg) + 1; |
1677 | args += len + 1; | ||
1678 | str = string(str, end, (char *)str_arg, spec); | 1738 | str = string(str, end, (char *)str_arg, spec); |
1679 | break; | 1739 | break; |
1680 | } | 1740 | } |
@@ -1686,11 +1746,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1686 | break; | 1746 | break; |
1687 | 1747 | ||
1688 | case FORMAT_TYPE_PERCENT_CHAR: | 1748 | case FORMAT_TYPE_PERCENT_CHAR: |
1689 | if (str < end) | ||
1690 | *str = '%'; | ||
1691 | ++str; | ||
1692 | break; | ||
1693 | |||
1694 | case FORMAT_TYPE_INVALID: | 1749 | case FORMAT_TYPE_INVALID: |
1695 | if (str < end) | 1750 | if (str < end) |
1696 | *str = '%'; | 1751 | *str = '%'; |
@@ -1701,15 +1756,15 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1701 | /* skip */ | 1756 | /* skip */ |
1702 | break; | 1757 | break; |
1703 | 1758 | ||
1704 | default: | 1759 | default: { |
1760 | unsigned long long num; | ||
1761 | |||
1705 | switch (spec.type) { | 1762 | switch (spec.type) { |
1706 | 1763 | ||
1707 | case FORMAT_TYPE_LONG_LONG: | 1764 | case FORMAT_TYPE_LONG_LONG: |
1708 | num = get_arg(long long); | 1765 | num = get_arg(long long); |
1709 | break; | 1766 | break; |
1710 | case FORMAT_TYPE_ULONG: | 1767 | case FORMAT_TYPE_ULONG: |
1711 | num = get_arg(unsigned long); | ||
1712 | break; | ||
1713 | case FORMAT_TYPE_LONG: | 1768 | case FORMAT_TYPE_LONG: |
1714 | num = get_arg(unsigned long); | 1769 | num = get_arg(unsigned long); |
1715 | break; | 1770 | break; |
@@ -1739,8 +1794,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) | |||
1739 | } | 1794 | } |
1740 | 1795 | ||
1741 | str = number(str, end, num, spec); | 1796 | str = number(str, end, num, spec); |
1742 | } | 1797 | } /* default: */ |
1743 | } | 1798 | } /* switch(spec.type) */ |
1799 | } /* while(*fmt) */ | ||
1744 | 1800 | ||
1745 | if (size > 0) { | 1801 | if (size > 0) { |
1746 | if (str < end) | 1802 | if (str < end) |
@@ -1774,6 +1830,7 @@ int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) | |||
1774 | va_start(args, fmt); | 1830 | va_start(args, fmt); |
1775 | ret = vbin_printf(bin_buf, size, fmt, args); | 1831 | ret = vbin_printf(bin_buf, size, fmt, args); |
1776 | va_end(args); | 1832 | va_end(args); |
1833 | |||
1777 | return ret; | 1834 | return ret; |
1778 | } | 1835 | } |
1779 | EXPORT_SYMBOL_GPL(bprintf); | 1836 | EXPORT_SYMBOL_GPL(bprintf); |
@@ -1786,27 +1843,23 @@ EXPORT_SYMBOL_GPL(bprintf); | |||
1786 | * @fmt: format of buffer | 1843 | * @fmt: format of buffer |
1787 | * @args: arguments | 1844 | * @args: arguments |
1788 | */ | 1845 | */ |
1789 | int vsscanf(const char * buf, const char * fmt, va_list args) | 1846 | int vsscanf(const char *buf, const char *fmt, va_list args) |
1790 | { | 1847 | { |
1791 | const char *str = buf; | 1848 | const char *str = buf; |
1792 | char *next; | 1849 | char *next; |
1793 | char digit; | 1850 | char digit; |
1794 | int num = 0; | 1851 | int num = 0; |
1795 | int qualifier; | 1852 | int qualifier, base, field_width; |
1796 | int base; | 1853 | bool is_sign; |
1797 | int field_width; | ||
1798 | int is_sign = 0; | ||
1799 | 1854 | ||
1800 | while(*fmt && *str) { | 1855 | while (*fmt && *str) { |
1801 | /* skip any white space in format */ | 1856 | /* skip any white space in format */ |
1802 | /* white space in format matchs any amount of | 1857 | /* white space in format matchs any amount of |
1803 | * white space, including none, in the input. | 1858 | * white space, including none, in the input. |
1804 | */ | 1859 | */ |
1805 | if (isspace(*fmt)) { | 1860 | if (isspace(*fmt)) { |
1806 | while (isspace(*fmt)) | 1861 | fmt = skip_spaces(++fmt); |
1807 | ++fmt; | 1862 | str = skip_spaces(str); |
1808 | while (isspace(*str)) | ||
1809 | ++str; | ||
1810 | } | 1863 | } |
1811 | 1864 | ||
1812 | /* anything that is not a conversion must match exactly */ | 1865 | /* anything that is not a conversion must match exactly */ |
@@ -1819,7 +1872,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1819 | if (!*fmt) | 1872 | if (!*fmt) |
1820 | break; | 1873 | break; |
1821 | ++fmt; | 1874 | ++fmt; |
1822 | 1875 | ||
1823 | /* skip this conversion. | 1876 | /* skip this conversion. |
1824 | * advance both strings to next white space | 1877 | * advance both strings to next white space |
1825 | */ | 1878 | */ |
@@ -1838,8 +1891,8 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1838 | 1891 | ||
1839 | /* get conversion qualifier */ | 1892 | /* get conversion qualifier */ |
1840 | qualifier = -1; | 1893 | qualifier = -1; |
1841 | if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || | 1894 | if (*fmt == 'h' || TOLOWER(*fmt) == 'l' || |
1842 | *fmt == 'Z' || *fmt == 'z') { | 1895 | TOLOWER(*fmt) == 'z') { |
1843 | qualifier = *fmt++; | 1896 | qualifier = *fmt++; |
1844 | if (unlikely(qualifier == *fmt)) { | 1897 | if (unlikely(qualifier == *fmt)) { |
1845 | if (qualifier == 'h') { | 1898 | if (qualifier == 'h') { |
@@ -1851,16 +1904,17 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1851 | } | 1904 | } |
1852 | } | 1905 | } |
1853 | } | 1906 | } |
1854 | base = 10; | ||
1855 | is_sign = 0; | ||
1856 | 1907 | ||
1857 | if (!*fmt || !*str) | 1908 | if (!*fmt || !*str) |
1858 | break; | 1909 | break; |
1859 | 1910 | ||
1860 | switch(*fmt++) { | 1911 | base = 10; |
1912 | is_sign = 0; | ||
1913 | |||
1914 | switch (*fmt++) { | ||
1861 | case 'c': | 1915 | case 'c': |
1862 | { | 1916 | { |
1863 | char *s = (char *) va_arg(args,char*); | 1917 | char *s = (char *)va_arg(args, char*); |
1864 | if (field_width == -1) | 1918 | if (field_width == -1) |
1865 | field_width = 1; | 1919 | field_width = 1; |
1866 | do { | 1920 | do { |
@@ -1871,17 +1925,15 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1871 | continue; | 1925 | continue; |
1872 | case 's': | 1926 | case 's': |
1873 | { | 1927 | { |
1874 | char *s = (char *) va_arg(args, char *); | 1928 | char *s = (char *)va_arg(args, char *); |
1875 | if(field_width == -1) | 1929 | if (field_width == -1) |
1876 | field_width = INT_MAX; | 1930 | field_width = INT_MAX; |
1877 | /* first, skip leading white space in buffer */ | 1931 | /* first, skip leading white space in buffer */ |
1878 | while (isspace(*str)) | 1932 | str = skip_spaces(str); |
1879 | str++; | ||
1880 | 1933 | ||
1881 | /* now copy until next white space */ | 1934 | /* now copy until next white space */ |
1882 | while (*str && !isspace(*str) && field_width--) { | 1935 | while (*str && !isspace(*str) && field_width--) |
1883 | *s++ = *str++; | 1936 | *s++ = *str++; |
1884 | } | ||
1885 | *s = '\0'; | 1937 | *s = '\0'; |
1886 | num++; | 1938 | num++; |
1887 | } | 1939 | } |
@@ -1889,7 +1941,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1889 | case 'n': | 1941 | case 'n': |
1890 | /* return number of characters read so far */ | 1942 | /* return number of characters read so far */ |
1891 | { | 1943 | { |
1892 | int *i = (int *)va_arg(args,int*); | 1944 | int *i = (int *)va_arg(args, int*); |
1893 | *i = str - buf; | 1945 | *i = str - buf; |
1894 | } | 1946 | } |
1895 | continue; | 1947 | continue; |
@@ -1901,14 +1953,14 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1901 | base = 16; | 1953 | base = 16; |
1902 | break; | 1954 | break; |
1903 | case 'i': | 1955 | case 'i': |
1904 | base = 0; | 1956 | base = 0; |
1905 | case 'd': | 1957 | case 'd': |
1906 | is_sign = 1; | 1958 | is_sign = 1; |
1907 | case 'u': | 1959 | case 'u': |
1908 | break; | 1960 | break; |
1909 | case '%': | 1961 | case '%': |
1910 | /* looking for '%' in str */ | 1962 | /* looking for '%' in str */ |
1911 | if (*str++ != '%') | 1963 | if (*str++ != '%') |
1912 | return num; | 1964 | return num; |
1913 | continue; | 1965 | continue; |
1914 | default: | 1966 | default: |
@@ -1919,71 +1971,70 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
1919 | /* have some sort of integer conversion. | 1971 | /* have some sort of integer conversion. |
1920 | * first, skip white space in buffer. | 1972 | * first, skip white space in buffer. |
1921 | */ | 1973 | */ |
1922 | while (isspace(*str)) | 1974 | str = skip_spaces(str); |
1923 | str++; | ||
1924 | 1975 | ||
1925 | digit = *str; | 1976 | digit = *str; |
1926 | if (is_sign && digit == '-') | 1977 | if (is_sign && digit == '-') |
1927 | digit = *(str + 1); | 1978 | digit = *(str + 1); |
1928 | 1979 | ||
1929 | if (!digit | 1980 | if (!digit |
1930 | || (base == 16 && !isxdigit(digit)) | 1981 | || (base == 16 && !isxdigit(digit)) |
1931 | || (base == 10 && !isdigit(digit)) | 1982 | || (base == 10 && !isdigit(digit)) |
1932 | || (base == 8 && (!isdigit(digit) || digit > '7')) | 1983 | || (base == 8 && (!isdigit(digit) || digit > '7')) |
1933 | || (base == 0 && !isdigit(digit))) | 1984 | || (base == 0 && !isdigit(digit))) |
1934 | break; | 1985 | break; |
1935 | 1986 | ||
1936 | switch(qualifier) { | 1987 | switch (qualifier) { |
1937 | case 'H': /* that's 'hh' in format */ | 1988 | case 'H': /* that's 'hh' in format */ |
1938 | if (is_sign) { | 1989 | if (is_sign) { |
1939 | signed char *s = (signed char *) va_arg(args,signed char *); | 1990 | signed char *s = (signed char *)va_arg(args, signed char *); |
1940 | *s = (signed char) simple_strtol(str,&next,base); | 1991 | *s = (signed char)simple_strtol(str, &next, base); |
1941 | } else { | 1992 | } else { |
1942 | unsigned char *s = (unsigned char *) va_arg(args, unsigned char *); | 1993 | unsigned char *s = (unsigned char *)va_arg(args, unsigned char *); |
1943 | *s = (unsigned char) simple_strtoul(str, &next, base); | 1994 | *s = (unsigned char)simple_strtoul(str, &next, base); |
1944 | } | 1995 | } |
1945 | break; | 1996 | break; |
1946 | case 'h': | 1997 | case 'h': |
1947 | if (is_sign) { | 1998 | if (is_sign) { |
1948 | short *s = (short *) va_arg(args,short *); | 1999 | short *s = (short *)va_arg(args, short *); |
1949 | *s = (short) simple_strtol(str,&next,base); | 2000 | *s = (short)simple_strtol(str, &next, base); |
1950 | } else { | 2001 | } else { |
1951 | unsigned short *s = (unsigned short *) va_arg(args, unsigned short *); | 2002 | unsigned short *s = (unsigned short *)va_arg(args, unsigned short *); |
1952 | *s = (unsigned short) simple_strtoul(str, &next, base); | 2003 | *s = (unsigned short)simple_strtoul(str, &next, base); |
1953 | } | 2004 | } |
1954 | break; | 2005 | break; |
1955 | case 'l': | 2006 | case 'l': |
1956 | if (is_sign) { | 2007 | if (is_sign) { |
1957 | long *l = (long *) va_arg(args,long *); | 2008 | long *l = (long *)va_arg(args, long *); |
1958 | *l = simple_strtol(str,&next,base); | 2009 | *l = simple_strtol(str, &next, base); |
1959 | } else { | 2010 | } else { |
1960 | unsigned long *l = (unsigned long*) va_arg(args,unsigned long*); | 2011 | unsigned long *l = (unsigned long *)va_arg(args, unsigned long *); |
1961 | *l = simple_strtoul(str,&next,base); | 2012 | *l = simple_strtoul(str, &next, base); |
1962 | } | 2013 | } |
1963 | break; | 2014 | break; |
1964 | case 'L': | 2015 | case 'L': |
1965 | if (is_sign) { | 2016 | if (is_sign) { |
1966 | long long *l = (long long*) va_arg(args,long long *); | 2017 | long long *l = (long long *)va_arg(args, long long *); |
1967 | *l = simple_strtoll(str,&next,base); | 2018 | *l = simple_strtoll(str, &next, base); |
1968 | } else { | 2019 | } else { |
1969 | unsigned long long *l = (unsigned long long*) va_arg(args,unsigned long long*); | 2020 | unsigned long long *l = (unsigned long long *)va_arg(args, unsigned long long *); |
1970 | *l = simple_strtoull(str,&next,base); | 2021 | *l = simple_strtoull(str, &next, base); |
1971 | } | 2022 | } |
1972 | break; | 2023 | break; |
1973 | case 'Z': | 2024 | case 'Z': |
1974 | case 'z': | 2025 | case 'z': |
1975 | { | 2026 | { |
1976 | size_t *s = (size_t*) va_arg(args,size_t*); | 2027 | size_t *s = (size_t *)va_arg(args, size_t *); |
1977 | *s = (size_t) simple_strtoul(str,&next,base); | 2028 | *s = (size_t)simple_strtoul(str, &next, base); |
1978 | } | 2029 | } |
1979 | break; | 2030 | break; |
1980 | default: | 2031 | default: |
1981 | if (is_sign) { | 2032 | if (is_sign) { |
1982 | int *i = (int *) va_arg(args, int*); | 2033 | int *i = (int *)va_arg(args, int *); |
1983 | *i = (int) simple_strtol(str,&next,base); | 2034 | *i = (int)simple_strtol(str, &next, base); |
1984 | } else { | 2035 | } else { |
1985 | unsigned int *i = (unsigned int*) va_arg(args, unsigned int*); | 2036 | unsigned int *i = (unsigned int *)va_arg(args, unsigned int*); |
1986 | *i = (unsigned int) simple_strtoul(str,&next,base); | 2037 | *i = (unsigned int)simple_strtoul(str, &next, base); |
1987 | } | 2038 | } |
1988 | break; | 2039 | break; |
1989 | } | 2040 | } |
@@ -2014,14 +2065,15 @@ EXPORT_SYMBOL(vsscanf); | |||
2014 | * @fmt: formatting of buffer | 2065 | * @fmt: formatting of buffer |
2015 | * @...: resulting arguments | 2066 | * @...: resulting arguments |
2016 | */ | 2067 | */ |
2017 | int sscanf(const char * buf, const char * fmt, ...) | 2068 | int sscanf(const char *buf, const char *fmt, ...) |
2018 | { | 2069 | { |
2019 | va_list args; | 2070 | va_list args; |
2020 | int i; | 2071 | int i; |
2021 | 2072 | ||
2022 | va_start(args,fmt); | 2073 | va_start(args, fmt); |
2023 | i = vsscanf(buf,fmt,args); | 2074 | i = vsscanf(buf, fmt, args); |
2024 | va_end(args); | 2075 | va_end(args); |
2076 | |||
2025 | return i; | 2077 | return i; |
2026 | } | 2078 | } |
2027 | EXPORT_SYMBOL(sscanf); | 2079 | EXPORT_SYMBOL(sscanf); |
diff --git a/lib/zlib_inflate/inffast.c b/lib/zlib_inflate/inffast.c index 8550b0c05d00..215447c55261 100644 --- a/lib/zlib_inflate/inffast.c +++ b/lib/zlib_inflate/inffast.c | |||
@@ -8,6 +8,21 @@ | |||
8 | #include "inflate.h" | 8 | #include "inflate.h" |
9 | #include "inffast.h" | 9 | #include "inffast.h" |
10 | 10 | ||
11 | /* Only do the unaligned "Faster" variant when | ||
12 | * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is set | ||
13 | * | ||
14 | * On powerpc, it won't be as we don't include autoconf.h | ||
15 | * automatically for the boot wrapper, which is intended as | ||
16 | * we run in an environment where we may not be able to deal | ||
17 | * with (even rare) alignment faults. In addition, we do not | ||
18 | * define __KERNEL__ for arch/powerpc/boot unlike x86 | ||
19 | */ | ||
20 | |||
21 | #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS | ||
22 | #include <asm/unaligned.h> | ||
23 | #include <asm/byteorder.h> | ||
24 | #endif | ||
25 | |||
11 | #ifndef ASMINF | 26 | #ifndef ASMINF |
12 | 27 | ||
13 | /* Allow machine dependent optimization for post-increment or pre-increment. | 28 | /* Allow machine dependent optimization for post-increment or pre-increment. |
@@ -24,9 +39,11 @@ | |||
24 | #ifdef POSTINC | 39 | #ifdef POSTINC |
25 | # define OFF 0 | 40 | # define OFF 0 |
26 | # define PUP(a) *(a)++ | 41 | # define PUP(a) *(a)++ |
42 | # define UP_UNALIGNED(a) get_unaligned((a)++) | ||
27 | #else | 43 | #else |
28 | # define OFF 1 | 44 | # define OFF 1 |
29 | # define PUP(a) *++(a) | 45 | # define PUP(a) *++(a) |
46 | # define UP_UNALIGNED(a) get_unaligned(++(a)) | ||
30 | #endif | 47 | #endif |
31 | 48 | ||
32 | /* | 49 | /* |
@@ -239,18 +256,62 @@ void inflate_fast(z_streamp strm, unsigned start) | |||
239 | } | 256 | } |
240 | } | 257 | } |
241 | else { | 258 | else { |
259 | #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS | ||
260 | unsigned short *sout; | ||
261 | unsigned long loops; | ||
262 | |||
263 | from = out - dist; /* copy direct from output */ | ||
264 | /* minimum length is three */ | ||
265 | /* Align out addr */ | ||
266 | if (!((long)(out - 1 + OFF) & 1)) { | ||
267 | PUP(out) = PUP(from); | ||
268 | len--; | ||
269 | } | ||
270 | sout = (unsigned short *)(out - OFF); | ||
271 | if (dist > 2) { | ||
272 | unsigned short *sfrom; | ||
273 | |||
274 | sfrom = (unsigned short *)(from - OFF); | ||
275 | loops = len >> 1; | ||
276 | do | ||
277 | PUP(sout) = UP_UNALIGNED(sfrom); | ||
278 | while (--loops); | ||
279 | out = (unsigned char *)sout + OFF; | ||
280 | from = (unsigned char *)sfrom + OFF; | ||
281 | } else { /* dist == 1 or dist == 2 */ | ||
282 | unsigned short pat16; | ||
283 | |||
284 | pat16 = *(sout-2+2*OFF); | ||
285 | if (dist == 1) | ||
286 | #if defined(__BIG_ENDIAN) | ||
287 | pat16 = (pat16 & 0xff) | ((pat16 & 0xff) << 8); | ||
288 | #elif defined(__LITTLE_ENDIAN) | ||
289 | pat16 = (pat16 & 0xff00) | ((pat16 & 0xff00) >> 8); | ||
290 | #else | ||
291 | #error __BIG_ENDIAN nor __LITTLE_ENDIAN is defined | ||
292 | #endif | ||
293 | loops = len >> 1; | ||
294 | do | ||
295 | PUP(sout) = pat16; | ||
296 | while (--loops); | ||
297 | out = (unsigned char *)sout + OFF; | ||
298 | } | ||
299 | if (len & 1) | ||
300 | PUP(out) = PUP(from); | ||
301 | #else /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */ | ||
242 | from = out - dist; /* copy direct from output */ | 302 | from = out - dist; /* copy direct from output */ |
243 | do { /* minimum length is three */ | 303 | do { /* minimum length is three */ |
244 | PUP(out) = PUP(from); | 304 | PUP(out) = PUP(from); |
245 | PUP(out) = PUP(from); | 305 | PUP(out) = PUP(from); |
246 | PUP(out) = PUP(from); | 306 | PUP(out) = PUP(from); |
247 | len -= 3; | 307 | len -= 3; |
248 | } while (len > 2); | 308 | } while (len > 2); |
249 | if (len) { | 309 | if (len) { |
250 | PUP(out) = PUP(from); | 310 | PUP(out) = PUP(from); |
251 | if (len > 1) | 311 | if (len > 1) |
252 | PUP(out) = PUP(from); | 312 | PUP(out) = PUP(from); |
253 | } | 313 | } |
314 | #endif /* !CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */ | ||
254 | } | 315 | } |
255 | } | 316 | } |
256 | else if ((op & 64) == 0) { /* 2nd level distance code */ | 317 | else if ((op & 64) == 0) { /* 2nd level distance code */ |