login
Header Space

 
 

[PATCH 2/5] Fix bitmap_scnprintf_len()

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <akpm@...>
Cc: <linux-kernel@...>, <travis@...>
Date: Wednesday, May 7, 2008 - 6:26 pm

bitmap_scnprintf_len() returns 36 (thirty six) for NR_CPUS=2 which is
ridiculous. So, rewrite the whole thing. Fixed version allows correct
seq_bitmap/seq_cpumask.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 include/linux/bitmap.h |    2 +-
 lib/bitmap.c           |   12 ++++--------
 2 files changed, 5 insertions(+), 9 deletions(-)

--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -110,7 +110,7 @@ extern int __bitmap_weight(const unsigned long *bitmap, int bits);
 
 extern int bitmap_scnprintf(char *buf, unsigned int len,
 			const unsigned long *src, int nbits);
-extern int bitmap_scnprintf_len(unsigned int len);
+extern int bitmap_scnprintf_len(unsigned int nr_bits);
 extern int __bitmap_parse(const char *buf, unsigned int buflen, int is_user,
 			unsigned long *dst, int nbits);
 extern int bitmap_parse_user(const char __user *ubuf, unsigned int ulen,
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -318,16 +318,12 @@ EXPORT_SYMBOL(bitmap_scnprintf);
 /**
  * bitmap_scnprintf_len - return buffer length needed to convert
  * bitmap to an ASCII hex string.
- * @len: number of bits to be converted
+ * @nr_bits: number of bits to be converted
  */
-int bitmap_scnprintf_len(unsigned int len)
+int bitmap_scnprintf_len(unsigned int nr_bits)
 {
-	/* we need 9 chars per word for 32 bit words (8 hexdigits + sep/null) */
-	int bitslen = ALIGN(len, CHUNKSZ);
-	int wordlen = CHUNKSZ / 4;
-	int buflen = (bitslen / wordlen) * (wordlen + 1) * sizeof(char);
-
-	return buflen;
+	unsigned int nr_nibbles = ALIGN(nr_bits, 4) / 4;
+	return nr_nibbles + ALIGN(nr_nibbles, CHUNKSZ / 4) / (CHUNKSZ / 4) - 1;
 }
 EXPORT_SYMBOL(bitmap_scnprintf_len);
 

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 2/5] Fix bitmap_scnprintf_len(), Alexey Dobriyan, (Wed May 7, 6:26 pm)
Re: [PATCH 2/5] Fix bitmap_scnprintf_len(), Bert Wesarg, (Thu May 8, 10:59 am)
speck-geostationary