alloc: fix page header size calculation bug, increase type safety.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 9 Jun 2010 13:04:44 +0000 (22:34 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 9 Jun 2010 13:04:44 +0000 (22:34 +0930)
ccan/alloc/alloc.c

index 28f850dcc7f6ac805c7302c2d9812d95b80b693b..e6ed97d2d3910069b471486efa16bdec26206809 100644 (file)
@@ -275,9 +275,9 @@ static unsigned long align_up(unsigned long x, unsigned long align)
        return (x + align - 1) & ~(align - 1);
 }
 
-static void *from_off(struct header *head, unsigned long off)
+static struct page_header *from_off(struct header *head, unsigned long off)
 {
-       return (char *)head + off;
+       return (struct page_header *)((char *)head + off);
 }
 
 static unsigned long to_off(struct header *head, void *p)
@@ -287,7 +287,7 @@ static unsigned long to_off(struct header *head, void *p)
 
 static size_t used_size(unsigned int num_elements)
 {
-       return (num_elements + BITS_PER_LONG-1) / BITS_PER_LONG;
+       return align_up(num_elements, BITS_PER_LONG) / CHAR_BIT;
 }
 
 /*