diff options
Diffstat (limited to 'lib/bitmap.c')
| -rw-r--r-- | lib/bitmap.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c index 11bf49750583..741fae905ae3 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c | |||
| @@ -359,7 +359,6 @@ EXPORT_SYMBOL(bitmap_find_next_zero_area); | |||
| 359 | 359 | ||
| 360 | #define CHUNKSZ 32 | 360 | #define CHUNKSZ 32 |
| 361 | #define nbits_to_hold_value(val) fls(val) | 361 | #define nbits_to_hold_value(val) fls(val) |
| 362 | #define unhex(c) (isdigit(c) ? (c - '0') : (toupper(c) - 'A' + 10)) | ||
| 363 | #define BASEDEC 10 /* fancier cpuset lists input in decimal */ | 362 | #define BASEDEC 10 /* fancier cpuset lists input in decimal */ |
| 364 | 363 | ||
| 365 | /** | 364 | /** |
| @@ -466,7 +465,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen, | |||
| 466 | if (chunk & ~((1UL << (CHUNKSZ - 4)) - 1)) | 465 | if (chunk & ~((1UL << (CHUNKSZ - 4)) - 1)) |
| 467 | return -EOVERFLOW; | 466 | return -EOVERFLOW; |
| 468 | 467 | ||
| 469 | chunk = (chunk << 4) | unhex(c); | 468 | chunk = (chunk << 4) | hex_to_bin(c); |
| 470 | ndigits++; totaldigits++; | 469 | ndigits++; totaldigits++; |
| 471 | } | 470 | } |
| 472 | if (ndigits == 0) | 471 | if (ndigits == 0) |
| @@ -487,7 +486,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen, | |||
| 487 | EXPORT_SYMBOL(__bitmap_parse); | 486 | EXPORT_SYMBOL(__bitmap_parse); |
| 488 | 487 | ||
| 489 | /** | 488 | /** |
| 490 | * bitmap_parse_user() | 489 | * bitmap_parse_user - convert an ASCII hex string in a user buffer into a bitmap |
| 491 | * | 490 | * |
| 492 | * @ubuf: pointer to user buffer containing string. | 491 | * @ubuf: pointer to user buffer containing string. |
| 493 | * @ulen: buffer size in bytes. If string is smaller than this | 492 | * @ulen: buffer size in bytes. If string is smaller than this |
| @@ -619,7 +618,7 @@ int bitmap_parselist(const char *bp, unsigned long *maskp, int nmaskbits) | |||
| 619 | EXPORT_SYMBOL(bitmap_parselist); | 618 | EXPORT_SYMBOL(bitmap_parselist); |
| 620 | 619 | ||
| 621 | /** | 620 | /** |
| 622 | * bitmap_pos_to_ord(buf, pos, bits) | 621 | * bitmap_pos_to_ord - find ordinal of set bit at given position in bitmap |
| 623 | * @buf: pointer to a bitmap | 622 | * @buf: pointer to a bitmap |
| 624 | * @pos: a bit position in @buf (0 <= @pos < @bits) | 623 | * @pos: a bit position in @buf (0 <= @pos < @bits) |
| 625 | * @bits: number of valid bit positions in @buf | 624 | * @bits: number of valid bit positions in @buf |
| @@ -655,7 +654,7 @@ static int bitmap_pos_to_ord(const unsigned long *buf, int pos, int bits) | |||
| 655 | } | 654 | } |
| 656 | 655 | ||
| 657 | /** | 656 | /** |
| 658 | * bitmap_ord_to_pos(buf, ord, bits) | 657 | * bitmap_ord_to_pos - find position of n-th set bit in bitmap |
| 659 | * @buf: pointer to bitmap | 658 | * @buf: pointer to bitmap |
| 660 | * @ord: ordinal bit position (n-th set bit, n >= 0) | 659 | * @ord: ordinal bit position (n-th set bit, n >= 0) |
| 661 | * @bits: number of valid bit positions in @buf | 660 | * @bits: number of valid bit positions in @buf |
| @@ -733,10 +732,9 @@ void bitmap_remap(unsigned long *dst, const unsigned long *src, | |||
| 733 | bitmap_zero(dst, bits); | 732 | bitmap_zero(dst, bits); |
| 734 | 733 | ||
| 735 | w = bitmap_weight(new, bits); | 734 | w = bitmap_weight(new, bits); |
| 736 | for (oldbit = find_first_bit(src, bits); | 735 | for_each_set_bit(oldbit, src, bits) { |
| 737 | oldbit < bits; | ||
| 738 | oldbit = find_next_bit(src, bits, oldbit + 1)) { | ||
| 739 | int n = bitmap_pos_to_ord(old, oldbit, bits); | 736 | int n = bitmap_pos_to_ord(old, oldbit, bits); |
| 737 | |||
| 740 | if (n < 0 || w == 0) | 738 | if (n < 0 || w == 0) |
| 741 | set_bit(oldbit, dst); /* identity map */ | 739 | set_bit(oldbit, dst); /* identity map */ |
| 742 | else | 740 | else |
| @@ -903,9 +901,7 @@ void bitmap_onto(unsigned long *dst, const unsigned long *orig, | |||
| 903 | */ | 901 | */ |
| 904 | 902 | ||
| 905 | m = 0; | 903 | m = 0; |
| 906 | for (n = find_first_bit(relmap, bits); | 904 | for_each_set_bit(n, relmap, bits) { |
| 907 | n < bits; | ||
| 908 | n = find_next_bit(relmap, bits, n + 1)) { | ||
| 909 | /* m == bitmap_pos_to_ord(relmap, n, bits) */ | 905 | /* m == bitmap_pos_to_ord(relmap, n, bits) */ |
| 910 | if (test_bit(m, orig)) | 906 | if (test_bit(m, orig)) |
| 911 | set_bit(n, dst); | 907 | set_bit(n, dst); |
| @@ -934,9 +930,7 @@ void bitmap_fold(unsigned long *dst, const unsigned long *orig, | |||
| 934 | return; | 930 | return; |
| 935 | bitmap_zero(dst, bits); | 931 | bitmap_zero(dst, bits); |
| 936 | 932 | ||
| 937 | for (oldbit = find_first_bit(orig, bits); | 933 | for_each_set_bit(oldbit, orig, bits) |
| 938 | oldbit < bits; | ||
| 939 | oldbit = find_next_bit(orig, bits, oldbit + 1)) | ||
| 940 | set_bit(oldbit % sz, dst); | 934 | set_bit(oldbit % sz, dst); |
| 941 | } | 935 | } |
| 942 | EXPORT_SYMBOL(bitmap_fold); | 936 | EXPORT_SYMBOL(bitmap_fold); |
