X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=arch%2Fpowerpc%2Flib%2Frheap.c;h=6c5c5dd183ee3ac79c57bf4f5cf744b91a15ad47;hb=c827ba4cb49a30ce581201fd0ba2be77cde412c7;hp=31e511856dc58bc2b819e80c32a35840db5bd9ca;hpb=ae574a5d7aa1d80469dfcbaa757db2bea536ee66;p=powerpc.git diff --git a/arch/powerpc/lib/rheap.c b/arch/powerpc/lib/rheap.c index 31e511856d..6c5c5dd183 100644 --- a/arch/powerpc/lib/rheap.c +++ b/arch/powerpc/lib/rheap.c @@ -14,6 +14,7 @@ */ #include #include +#include #include #include @@ -85,7 +86,8 @@ static int grow(rh_info_t * info, int max_blocks) info->flags &= ~RHIF_STATIC_BLOCK; /* add all new blocks to the free list */ - for (i = 0, blk = block + info->max_blocks; i < new_blocks; i++, blk++) + blk = block + info->max_blocks - new_blocks; + for (i = 0; i < new_blocks; i++, blk++) list_add(&blk->list, &info->empty_list); return 0; @@ -423,17 +425,21 @@ void *rh_detach_region(rh_info_t * info, void *start, int size) return (void *)s; } -void *rh_alloc(rh_info_t * info, int size, const char *owner) +void *rh_alloc_align(rh_info_t * info, int size, int alignment, const char *owner) { struct list_head *l; rh_block_t *blk; rh_block_t *newblk; void *start; - /* Validate size */ - if (size <= 0) + /* Validate size, (must be power of two) */ + if (size <= 0 || (alignment & (alignment - 1)) != 0) return ERR_PTR(-EINVAL); + /* given alignment larger that default rheap alignment */ + if (alignment > info->alignment) + size += alignment - 1; + /* Align to configured alignment */ size = (size + (info->alignment - 1)) & ~(info->alignment - 1); @@ -476,15 +482,27 @@ void *rh_alloc(rh_info_t * info, int size, const char *owner) attach_taken_block(info, newblk); + /* for larger alignment return fixed up pointer */ + /* this is no problem with the deallocator since */ + /* we scan for pointers that lie in the blocks */ + if (alignment > info->alignment) + start = (void *)(((unsigned long)start + alignment - 1) & + ~(alignment - 1)); + return start; } +void *rh_alloc(rh_info_t * info, int size, const char *owner) +{ + return rh_alloc_align(info, size, info->alignment, owner); +} + /* allocate at precisely the given address */ void *rh_alloc_fixed(rh_info_t * info, void *start, int size, const char *owner) { struct list_head *l; rh_block_t *blk, *newblk1, *newblk2; - unsigned long s, e, m, bs, be; + unsigned long s, e, m, bs = 0, be = 0; /* Validate size */ if (size <= 0) @@ -654,7 +672,7 @@ void rh_dump(rh_info_t * info) int maxnr; int i, nr; - maxnr = sizeof(st) / sizeof(st[0]); + maxnr = ARRAY_SIZE(st); printk(KERN_INFO "info @0x%p (%d slots empty / %d max)\n",