aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bitmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bitmap.c')
-rw-r--r--lib/bitmap.c61
1 files changed, 2 insertions, 59 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c
index a13c7f4e325a..e85040ba1f22 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -383,28 +383,7 @@ EXPORT_SYMBOL(bitmap_find_next_zero_area_off);
383int bitmap_scnprintf(char *buf, unsigned int buflen, 383int bitmap_scnprintf(char *buf, unsigned int buflen,
384 const unsigned long *maskp, int nmaskbits) 384 const unsigned long *maskp, int nmaskbits)
385{ 385{
386 int i, word, bit, len = 0; 386 return scnprintf(buf, buflen, "%*pb", nmaskbits, maskp);
387 unsigned long val;
388 const char *sep = "";
389 int chunksz;
390 u32 chunkmask;
391
392 chunksz = nmaskbits & (CHUNKSZ - 1);
393 if (chunksz == 0)
394 chunksz = CHUNKSZ;
395
396 i = ALIGN(nmaskbits, CHUNKSZ) - CHUNKSZ;
397 for (; i >= 0; i -= CHUNKSZ) {
398 chunkmask = ((1ULL << chunksz) - 1);
399 word = i / BITS_PER_LONG;
400 bit = i % BITS_PER_LONG;
401 val = (maskp[word] >> bit) & chunkmask;
402 len += scnprintf(buf+len, buflen-len, "%s%0*lx", sep,
403 (chunksz+3)/4, val);
404 chunksz = CHUNKSZ;
405 sep = ",";
406 }
407 return len;
408} 387}
409EXPORT_SYMBOL(bitmap_scnprintf); 388EXPORT_SYMBOL(bitmap_scnprintf);
410 389
@@ -521,25 +500,6 @@ int bitmap_parse_user(const char __user *ubuf,
521} 500}
522EXPORT_SYMBOL(bitmap_parse_user); 501EXPORT_SYMBOL(bitmap_parse_user);
523 502
524/*
525 * bscnl_emit(buf, buflen, rbot, rtop, bp)
526 *
527 * Helper routine for bitmap_scnlistprintf(). Write decimal number
528 * or range to buf, suppressing output past buf+buflen, with optional
529 * comma-prefix. Return len of what was written to *buf, excluding the
530 * trailing \0.
531 */
532static inline int bscnl_emit(char *buf, int buflen, int rbot, int rtop, int len)
533{
534 if (len > 0)
535 len += scnprintf(buf + len, buflen - len, ",");
536 if (rbot == rtop)
537 len += scnprintf(buf + len, buflen - len, "%d", rbot);
538 else
539 len += scnprintf(buf + len, buflen - len, "%d-%d", rbot, rtop);
540 return len;
541}
542
543/** 503/**
544 * bitmap_scnlistprintf - convert bitmap to list format ASCII string 504 * bitmap_scnlistprintf - convert bitmap to list format ASCII string
545 * @buf: byte buffer into which string is placed 505 * @buf: byte buffer into which string is placed
@@ -559,24 +519,7 @@ static inline int bscnl_emit(char *buf, int buflen, int rbot, int rtop, int len)
559int bitmap_scnlistprintf(char *buf, unsigned int buflen, 519int bitmap_scnlistprintf(char *buf, unsigned int buflen,
560 const unsigned long *maskp, int nmaskbits) 520 const unsigned long *maskp, int nmaskbits)
561{ 521{
562 int len = 0; 522 return scnprintf(buf, buflen, "%*pbl", nmaskbits, maskp);
563 /* current bit is 'cur', most recently seen range is [rbot, rtop] */
564 int cur, rbot, rtop;
565
566 if (buflen == 0)
567 return 0;
568 buf[0] = 0;
569
570 rbot = cur = find_first_bit(maskp, nmaskbits);
571 while (cur < nmaskbits) {
572 rtop = cur;
573 cur = find_next_bit(maskp, nmaskbits, cur+1);
574 if (cur >= nmaskbits || cur > rtop + 1) {
575 len = bscnl_emit(buf, buflen, rbot, rtop, len);
576 rbot = cur;
577 }
578 }
579 return len;
580} 523}
581EXPORT_SYMBOL(bitmap_scnlistprintf); 524EXPORT_SYMBOL(bitmap_scnlistprintf);
582 525