From: Chris Humbert <mahadri-kernel@drigon.com>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@osdl.org>, Jes Sorensen <jes@trained-monkey.org>
Subject: [PATCH] fix broken lib/genalloc.c
Date: Thu, 24 Nov 2005 05:30:29 -0800 [thread overview]
Message-ID: <20051124133029.GA21470@matrix.drigon.com> (raw)
genalloc improperly stores the size of freed chunks, allocates
overlapping memory regions, and oopses after its in-band data is
overwritten. Jes Sorensen's original patch to LKML used:
> + s = (1 << ALLOC_MIN_SHIFT);
> + while (size > s) {
> + s <<= 1;
> + i++;
> + }
After Andrew Morton suggested roundup_pow_of_two(), Jes changed
it to:
> + size = max(size, 1 << ALLOC_MIN_SHIFT);
> + s = roundup_pow_of_two(size);
but this does not set 'i'. I have verified that genalloc with
the attached patch works correctly.
Chris Humbert
[PATCH] fix broken lib/genalloc.c
genalloc improperly stores the sizes of freed chunks, allocates
overlapping memory regions, and oopses after its in-band data is
overwritten.
Signed-off-by: Chris Humbert <mahadri-kernel@drigon.com>
diff --git a/lib/genalloc.c b/lib/genalloc.c
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -95,12 +95,10 @@ unsigned long gen_pool_alloc(struct gen_
if (size > max_chunk_size)
return 0;
- i = 0;
-
size = max(size, 1 << ALLOC_MIN_SHIFT);
- s = roundup_pow_of_two(size);
-
- j = i;
+ i = fls(size - 1);
+ s = 1 << i;
+ j = i -= ALLOC_MIN_SHIFT;
spin_lock_irqsave(&poolp->lock, flags);
while (!h[j].next) {
@@ -153,10 +151,10 @@ void gen_pool_free(struct gen_pool *pool
if (size > max_chunk_size)
return;
- i = 0;
-
size = max(size, 1 << ALLOC_MIN_SHIFT);
- s = roundup_pow_of_two(size);
+ i = fls(size - 1);
+ s = 1 << i;
+ i -= ALLOC_MIN_SHIFT;
a = ptr;
reply other threads:[~2005-11-24 13:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20051124133029.GA21470@matrix.drigon.com \
--to=mahadri-kernel@drigon.com \
--cc=akpm@osdl.org \
--cc=jes@trained-monkey.org \
--cc=linux-kernel@vger.kernel.org \
/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