public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix calculus of bitmap_scnprintf_len()
@ 2008-04-27 20:43 Bert Wesarg
  2008-04-27 21:01 ` Paul Jackson
  0 siblings, 1 reply; 6+ messages in thread
From: Bert Wesarg @ 2008-04-27 20:43 UTC (permalink / raw)
  To: mingo; +Cc: linux-kernel, torvalds, akpm, Bert Wesarg, Mike Travis,
	Paul Jackson

The function bitmap_scnprintf_len() is currently not used, but the returned
value is 4 times larger than needed. This value is also only a good upper
bound. Which should be mentioned in the comment.

The correct number of chars needed for the buffer, exluding any new line and
terminating zero is:

int bitmap_scnprintf_len(int len)
{
	return  /* complete hunks with commas */
	          ((len / CHUNKSZ) * 9)
	        /* partial hunk, 4 bits in one char */
	       + (((len % CHUNKSZ) + 3) / 4)
	        /* one less comma, if no partial hunk */
	       -  !(len % CHUNKSZ);
}

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
Cc: Mike Travis <travis@sgi.com>
Cc: Paul Jackson <pj@sgi.com>

---
 lib/bitmap.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/bitmap.c b/lib/bitmap.c
index a6939e1..47e6f0f 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -325,7 +325,7 @@ int bitmap_scnprintf_len(unsigned int len)
 	/* 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);
+	int buflen = (bitslen / CHUNKSZ) * (wordlen + 1);
 
 	return buflen;
 }
-- 
1.5.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-04-28 17:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-27 20:43 [PATCH] Fix calculus of bitmap_scnprintf_len() Bert Wesarg
2008-04-27 21:01 ` Paul Jackson
2008-04-28  6:14   ` WANG Cong
2008-04-28 13:13     ` Paul Jackson
2008-04-28 17:09       ` Mike Travis
2008-04-28 17:31         ` Bert Wesarg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox