From f6d21b50ff672dee48d6bbe4f85bc1efd92fac2c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 9 Jun 2010 22:34:44 +0930 Subject: [PATCH] alloc: fix page header size calculation bug, increase type safety. --- ccan/alloc/alloc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ccan/alloc/alloc.c b/ccan/alloc/alloc.c index 28f850dc..e6ed97d2 100644 --- a/ccan/alloc/alloc.c +++ b/ccan/alloc/alloc.c @@ -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; } /* -- 2.39.2