public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Bert Wesarg <bert.wesarg@googlemail.com>
To: mingo@elte.hu
Cc: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
	akpm@linux-foundation.org,
	Bert Wesarg <bert.wesarg@googlemail.com>,
	Mike Travis <travis@sgi.com>, Paul Jackson <pj@sgi.com>
Subject: [PATCH] Fix calculus of bitmap_scnprintf_len()
Date: Sun, 27 Apr 2008 22:43:23 +0200	[thread overview]
Message-ID: <1209329003-22036-1-git-send-email-bert.wesarg@googlemail.com> (raw)

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


             reply	other threads:[~2008-04-27 20:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-27 20:43 Bert Wesarg [this message]
2008-04-27 21:01 ` [PATCH] Fix calculus of bitmap_scnprintf_len() 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1209329003-22036-1-git-send-email-bert.wesarg@googlemail.com \
    --to=bert.wesarg@googlemail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=pj@sgi.com \
    --cc=torvalds@linux-foundation.org \
    --cc=travis@sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox