aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bitmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bitmap.c')
-rw-r--r--lib/bitmap.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 64c0926f5dd8..a578a0189199 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -462,19 +462,20 @@ EXPORT_SYMBOL(bitmap_parse_user);
462 * Output format is a comma-separated list of decimal numbers and 462 * Output format is a comma-separated list of decimal numbers and
463 * ranges if list is specified or hex digits grouped into comma-separated 463 * ranges if list is specified or hex digits grouped into comma-separated
464 * sets of 8 digits/set. Returns the number of characters written to buf. 464 * sets of 8 digits/set. Returns the number of characters written to buf.
465 *
466 * It is assumed that @buf is a pointer into a PAGE_SIZE area and that
467 * sufficient storage remains at @buf to accommodate the
468 * bitmap_print_to_pagebuf() output.
465 */ 469 */
466int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp, 470int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp,
467 int nmaskbits) 471 int nmaskbits)
468{ 472{
469 ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf - 2; 473 ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf;
470 int n = 0; 474 int n = 0;
471 475
472 if (len > 1) { 476 if (len > 1)
473 n = list ? scnprintf(buf, len, "%*pbl", nmaskbits, maskp) : 477 n = list ? scnprintf(buf, len, "%*pbl\n", nmaskbits, maskp) :
474 scnprintf(buf, len, "%*pb", nmaskbits, maskp); 478 scnprintf(buf, len, "%*pb\n", nmaskbits, maskp);
475 buf[n++] = '\n';
476 buf[n] = '\0';
477 }
478 return n; 479 return n;
479} 480}
480EXPORT_SYMBOL(bitmap_print_to_pagebuf); 481EXPORT_SYMBOL(bitmap_print_to_pagebuf);
@@ -506,12 +507,12 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
506 unsigned a, b; 507 unsigned a, b;
507 int c, old_c, totaldigits; 508 int c, old_c, totaldigits;
508 const char __user __force *ubuf = (const char __user __force *)buf; 509 const char __user __force *ubuf = (const char __user __force *)buf;
509 int exp_digit, in_range; 510 int at_start, in_range;
510 511
511 totaldigits = c = 0; 512 totaldigits = c = 0;
512 bitmap_zero(maskp, nmaskbits); 513 bitmap_zero(maskp, nmaskbits);
513 do { 514 do {
514 exp_digit = 1; 515 at_start = 1;
515 in_range = 0; 516 in_range = 0;
516 a = b = 0; 517 a = b = 0;
517 518
@@ -540,11 +541,10 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
540 break; 541 break;
541 542
542 if (c == '-') { 543 if (c == '-') {
543 if (exp_digit || in_range) 544 if (at_start || in_range)
544 return -EINVAL; 545 return -EINVAL;
545 b = 0; 546 b = 0;
546 in_range = 1; 547 in_range = 1;
547 exp_digit = 1;
548 continue; 548 continue;
549 } 549 }
550 550
@@ -554,16 +554,18 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
554 b = b * 10 + (c - '0'); 554 b = b * 10 + (c - '0');
555 if (!in_range) 555 if (!in_range)
556 a = b; 556 a = b;
557 exp_digit = 0; 557 at_start = 0;
558 totaldigits++; 558 totaldigits++;
559 } 559 }
560 if (!(a <= b)) 560 if (!(a <= b))
561 return -EINVAL; 561 return -EINVAL;
562 if (b >= nmaskbits) 562 if (b >= nmaskbits)
563 return -ERANGE; 563 return -ERANGE;
564 while (a <= b) { 564 if (!at_start) {
565 set_bit(a, maskp); 565 while (a <= b) {
566 a++; 566 set_bit(a, maskp);
567 a++;
568 }
567 } 569 }
568 } while (buflen && c == ','); 570 } while (buflen && c == ',');
569 return 0; 571 return 0;