]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
SLOB: fix bogus ksize calculation fix
authorMatt Mackall <mpm@selenic.com>
Wed, 8 Oct 2008 19:51:57 +0000 (14:51 -0500)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 9 Oct 2008 19:18:27 +0000 (12:18 -0700)
This fixes the previous fix, which was completely wrong on closer
inspection. This version has been manually tested with a user-space
test harness and generates sane values. A nearly identical patch has
been boot-tested.

The problem arose from changing how kmalloc/kfree handled alignment
padding without updating ksize to match. This brings it in sync.

Signed-off-by: Matt Mackall <mpm@selenic.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/slob.c

index 62b679dc660fb9244a745142c79186000793343f..cb675d1267914dc263100b9c4a9ea5eb20fefa48 100644 (file)
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -514,9 +514,11 @@ size_t ksize(const void *block)
                return 0;
 
        sp = (struct slob_page *)virt_to_page(block);
-       if (slob_page(sp))
-               return (((slob_t *)block - 1)->units - 1) * SLOB_UNIT;
-       else
+       if (slob_page(sp)) {
+               int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
+               unsigned int *m = (unsigned int *)(block - align);
+               return SLOB_UNITS(*m) * SLOB_UNIT;
+       } else
                return sp->page.private;
 }