diff options
author | Paul Mackerras <paulus@samba.org> | 2008-05-16 09:13:42 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2008-05-16 09:13:42 -0400 |
commit | fcff474ea5cb17ff015aa40e92ed86fede41f1e2 (patch) | |
tree | a99c0e14daaf31cb078812fb2fbc6abadfcd738f /lib | |
parent | 541b2755c2ef7dd2242ac606c115daa11e43ef69 (diff) | |
parent | f26a3988917913b3d11b2bd741601a2c64ab9204 (diff) |
Merge branch 'linux-2.6' into powerpc-next
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bitmap.c | 16 | ||||
-rw-r--r-- | lib/hexdump.c | 7 | ||||
-rw-r--r-- | lib/lmb.c | 45 | ||||
-rw-r--r-- | lib/parser.c | 32 |
4 files changed, 55 insertions, 45 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c index c4cb48f77f0c..482df94ea21e 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c | |||
@@ -316,22 +316,6 @@ int bitmap_scnprintf(char *buf, unsigned int buflen, | |||
316 | EXPORT_SYMBOL(bitmap_scnprintf); | 316 | EXPORT_SYMBOL(bitmap_scnprintf); |
317 | 317 | ||
318 | /** | 318 | /** |
319 | * bitmap_scnprintf_len - return buffer length needed to convert | ||
320 | * bitmap to an ASCII hex string. | ||
321 | * @len: number of bits to be converted | ||
322 | */ | ||
323 | int bitmap_scnprintf_len(unsigned int len) | ||
324 | { | ||
325 | /* we need 9 chars per word for 32 bit words (8 hexdigits + sep/null) */ | ||
326 | int bitslen = ALIGN(len, CHUNKSZ); | ||
327 | int wordlen = CHUNKSZ / 4; | ||
328 | int buflen = (bitslen / wordlen) * (wordlen + 1) * sizeof(char); | ||
329 | |||
330 | return buflen; | ||
331 | } | ||
332 | EXPORT_SYMBOL(bitmap_scnprintf_len); | ||
333 | |||
334 | /** | ||
335 | * __bitmap_parse - convert an ASCII hex string into a bitmap. | 319 | * __bitmap_parse - convert an ASCII hex string into a bitmap. |
336 | * @buf: pointer to buffer containing string. | 320 | * @buf: pointer to buffer containing string. |
337 | * @buflen: buffer size in bytes. If string is smaller than this | 321 | * @buflen: buffer size in bytes. If string is smaller than this |
diff --git a/lib/hexdump.c b/lib/hexdump.c index 343546550dc9..f07c0db81d26 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c | |||
@@ -12,6 +12,9 @@ | |||
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | 14 | ||
15 | const char hex_asc[] = "0123456789abcdef"; | ||
16 | EXPORT_SYMBOL(hex_asc); | ||
17 | |||
15 | /** | 18 | /** |
16 | * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory | 19 | * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory |
17 | * @buf: data blob to dump | 20 | * @buf: data blob to dump |
@@ -93,8 +96,8 @@ void hex_dump_to_buffer(const void *buf, size_t len, int rowsize, | |||
93 | for (j = 0; (j < rowsize) && (j < len) && (lx + 4) < linebuflen; | 96 | for (j = 0; (j < rowsize) && (j < len) && (lx + 4) < linebuflen; |
94 | j++) { | 97 | j++) { |
95 | ch = ptr[j]; | 98 | ch = ptr[j]; |
96 | linebuf[lx++] = hex_asc(ch >> 4); | 99 | linebuf[lx++] = hex_asc_hi(ch); |
97 | linebuf[lx++] = hex_asc(ch & 0x0f); | 100 | linebuf[lx++] = hex_asc_lo(ch); |
98 | linebuf[lx++] = ' '; | 101 | linebuf[lx++] = ' '; |
99 | } | 102 | } |
100 | ascii_column = 3 * rowsize + 2; | 103 | ascii_column = 3 * rowsize + 2; |
@@ -19,31 +19,42 @@ | |||
19 | 19 | ||
20 | struct lmb lmb; | 20 | struct lmb lmb; |
21 | 21 | ||
22 | static int lmb_debug; | ||
23 | |||
24 | static int __init early_lmb(char *p) | ||
25 | { | ||
26 | if (p && strstr(p, "debug")) | ||
27 | lmb_debug = 1; | ||
28 | return 0; | ||
29 | } | ||
30 | early_param("lmb", early_lmb); | ||
31 | |||
22 | void lmb_dump_all(void) | 32 | void lmb_dump_all(void) |
23 | { | 33 | { |
24 | #ifdef DEBUG | ||
25 | unsigned long i; | 34 | unsigned long i; |
26 | 35 | ||
27 | pr_debug("lmb_dump_all:\n"); | 36 | if (!lmb_debug) |
28 | pr_debug(" memory.cnt = 0x%lx\n", lmb.memory.cnt); | 37 | return; |
29 | pr_debug(" memory.size = 0x%llx\n", | 38 | |
39 | pr_info("lmb_dump_all:\n"); | ||
40 | pr_info(" memory.cnt = 0x%lx\n", lmb.memory.cnt); | ||
41 | pr_info(" memory.size = 0x%llx\n", | ||
30 | (unsigned long long)lmb.memory.size); | 42 | (unsigned long long)lmb.memory.size); |
31 | for (i=0; i < lmb.memory.cnt ;i++) { | 43 | for (i=0; i < lmb.memory.cnt ;i++) { |
32 | pr_debug(" memory.region[0x%x].base = 0x%llx\n", | 44 | pr_info(" memory.region[0x%lx].base = 0x%llx\n", |
33 | i, (unsigned long long)lmb.memory.region[i].base); | 45 | i, (unsigned long long)lmb.memory.region[i].base); |
34 | pr_debug(" .size = 0x%llx\n", | 46 | pr_info(" .size = 0x%llx\n", |
35 | (unsigned long long)lmb.memory.region[i].size); | 47 | (unsigned long long)lmb.memory.region[i].size); |
36 | } | 48 | } |
37 | 49 | ||
38 | pr_debug(" reserved.cnt = 0x%lx\n", lmb.reserved.cnt); | 50 | pr_info(" reserved.cnt = 0x%lx\n", lmb.reserved.cnt); |
39 | pr_debug(" reserved.size = 0x%lx\n", lmb.reserved.size); | 51 | pr_info(" reserved.size = 0x%lx\n", lmb.reserved.size); |
40 | for (i=0; i < lmb.reserved.cnt ;i++) { | 52 | for (i=0; i < lmb.reserved.cnt ;i++) { |
41 | pr_debug(" reserved.region[0x%x].base = 0x%llx\n", | 53 | pr_info(" reserved.region[0x%lx].base = 0x%llx\n", |
42 | i, (unsigned long long)lmb.reserved.region[i].base); | 54 | i, (unsigned long long)lmb.reserved.region[i].base); |
43 | pr_debug(" .size = 0x%llx\n", | 55 | pr_info(" .size = 0x%llx\n", |
44 | (unsigned long long)lmb.reserved.region[i].size); | 56 | (unsigned long long)lmb.reserved.region[i].size); |
45 | } | 57 | } |
46 | #endif /* DEBUG */ | ||
47 | } | 58 | } |
48 | 59 | ||
49 | static unsigned long lmb_addrs_overlap(u64 base1, u64 size1, u64 base2, | 60 | static unsigned long lmb_addrs_overlap(u64 base1, u64 size1, u64 base2, |
@@ -286,8 +297,7 @@ static u64 __init lmb_alloc_nid_unreserved(u64 start, u64 end, | |||
286 | j = lmb_overlaps_region(&lmb.reserved, base, size); | 297 | j = lmb_overlaps_region(&lmb.reserved, base, size); |
287 | if (j < 0) { | 298 | if (j < 0) { |
288 | /* this area isn't reserved, take it */ | 299 | /* this area isn't reserved, take it */ |
289 | if (lmb_add_region(&lmb.reserved, base, | 300 | if (lmb_add_region(&lmb.reserved, base, size) < 0) |
290 | lmb_align_up(size, align)) < 0) | ||
291 | base = ~(u64)0; | 301 | base = ~(u64)0; |
292 | return base; | 302 | return base; |
293 | } | 303 | } |
@@ -333,6 +343,10 @@ u64 __init lmb_alloc_nid(u64 size, u64 align, int nid, | |||
333 | struct lmb_region *mem = &lmb.memory; | 343 | struct lmb_region *mem = &lmb.memory; |
334 | int i; | 344 | int i; |
335 | 345 | ||
346 | BUG_ON(0 == size); | ||
347 | |||
348 | size = lmb_align_up(size, align); | ||
349 | |||
336 | for (i = 0; i < mem->cnt; i++) { | 350 | for (i = 0; i < mem->cnt; i++) { |
337 | u64 ret = lmb_alloc_nid_region(&mem->region[i], | 351 | u64 ret = lmb_alloc_nid_region(&mem->region[i], |
338 | nid_range, | 352 | nid_range, |
@@ -370,6 +384,8 @@ u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr) | |||
370 | 384 | ||
371 | BUG_ON(0 == size); | 385 | BUG_ON(0 == size); |
372 | 386 | ||
387 | size = lmb_align_up(size, align); | ||
388 | |||
373 | /* On some platforms, make sure we allocate lowmem */ | 389 | /* On some platforms, make sure we allocate lowmem */ |
374 | /* Note that LMB_REAL_LIMIT may be LMB_ALLOC_ANYWHERE */ | 390 | /* Note that LMB_REAL_LIMIT may be LMB_ALLOC_ANYWHERE */ |
375 | if (max_addr == LMB_ALLOC_ANYWHERE) | 391 | if (max_addr == LMB_ALLOC_ANYWHERE) |
@@ -393,8 +409,7 @@ u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr) | |||
393 | j = lmb_overlaps_region(&lmb.reserved, base, size); | 409 | j = lmb_overlaps_region(&lmb.reserved, base, size); |
394 | if (j < 0) { | 410 | if (j < 0) { |
395 | /* this area isn't reserved, take it */ | 411 | /* this area isn't reserved, take it */ |
396 | if (lmb_add_region(&lmb.reserved, base, | 412 | if (lmb_add_region(&lmb.reserved, base, size) < 0) |
397 | lmb_align_up(size, align)) < 0) | ||
398 | return 0; | 413 | return 0; |
399 | return base; | 414 | return base; |
400 | } | 415 | } |
diff --git a/lib/parser.c b/lib/parser.c index 703c8c13b346..4f0cbc03e0e8 100644 --- a/lib/parser.c +++ b/lib/parser.c | |||
@@ -182,18 +182,25 @@ int match_hex(substring_t *s, int *result) | |||
182 | } | 182 | } |
183 | 183 | ||
184 | /** | 184 | /** |
185 | * match_strcpy: - copies the characters from a substring_t to a string | 185 | * match_strlcpy: - Copy the characters from a substring_t to a sized buffer |
186 | * @to: string to copy characters to. | 186 | * @dest: where to copy to |
187 | * @s: &substring_t to copy | 187 | * @src: &substring_t to copy |
188 | * @size: size of destination buffer | ||
188 | * | 189 | * |
189 | * Description: Copies the set of characters represented by the given | 190 | * Description: Copy the characters in &substring_t @src to the |
190 | * &substring_t @s to the c-style string @to. Caller guarantees that @to is | 191 | * c-style string @dest. Copy no more than @size - 1 characters, plus |
191 | * large enough to hold the characters of @s. | 192 | * the terminating NUL. Return length of @src. |
192 | */ | 193 | */ |
193 | void match_strcpy(char *to, const substring_t *s) | 194 | size_t match_strlcpy(char *dest, const substring_t *src, size_t size) |
194 | { | 195 | { |
195 | memcpy(to, s->from, s->to - s->from); | 196 | size_t ret = src->to - src->from; |
196 | to[s->to - s->from] = '\0'; | 197 | |
198 | if (size) { | ||
199 | size_t len = ret >= size ? size - 1 : ret; | ||
200 | memcpy(dest, src->from, len); | ||
201 | dest[len] = '\0'; | ||
202 | } | ||
203 | return ret; | ||
197 | } | 204 | } |
198 | 205 | ||
199 | /** | 206 | /** |
@@ -206,9 +213,10 @@ void match_strcpy(char *to, const substring_t *s) | |||
206 | */ | 213 | */ |
207 | char *match_strdup(const substring_t *s) | 214 | char *match_strdup(const substring_t *s) |
208 | { | 215 | { |
209 | char *p = kmalloc(s->to - s->from + 1, GFP_KERNEL); | 216 | size_t sz = s->to - s->from + 1; |
217 | char *p = kmalloc(sz, GFP_KERNEL); | ||
210 | if (p) | 218 | if (p) |
211 | match_strcpy(p, s); | 219 | match_strlcpy(p, s, sz); |
212 | return p; | 220 | return p; |
213 | } | 221 | } |
214 | 222 | ||
@@ -216,5 +224,5 @@ EXPORT_SYMBOL(match_token); | |||
216 | EXPORT_SYMBOL(match_int); | 224 | EXPORT_SYMBOL(match_int); |
217 | EXPORT_SYMBOL(match_octal); | 225 | EXPORT_SYMBOL(match_octal); |
218 | EXPORT_SYMBOL(match_hex); | 226 | EXPORT_SYMBOL(match_hex); |
219 | EXPORT_SYMBOL(match_strcpy); | 227 | EXPORT_SYMBOL(match_strlcpy); |
220 | EXPORT_SYMBOL(match_strdup); | 228 | EXPORT_SYMBOL(match_strdup); |