lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20080507222601.GB14375@martell.zuzino.mipt.ru>
Date:	Thu, 8 May 2008 02:26:01 +0400
From:	Alexey Dobriyan <adobriyan@...il.com>
To:	akpm@...l.org
Cc:	linux-kernel@...r.kernel.org, travis@....com
Subject: [PATCH 2/5] Fix bitmap_scnprintf_len()

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@...il.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);
 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ