From: Alan Cox Date: Fri, 9 Mar 2018 20:56:16 +0000 (+0000) Subject: malloc: tidy formatting to match core code standard X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=021d9d27ef924b00c1209f9075ed38d37ec3f4b7;p=FUZIX.git malloc: tidy formatting to match core code standard --- diff --git a/Kernel/malloc.c b/Kernel/malloc.c index a34edda6..c9e8236c 100644 --- a/Kernel/malloc.c +++ b/Kernel/malloc.c @@ -22,7 +22,7 @@ struct block { - struct block* next; + struct block *next; size_t length; /* high bit set if used */ }; @@ -31,12 +31,13 @@ struct block static struct block start = { NULL, sizeof(struct block) }; /* - * Add a memory block to the pool + * Add a memory block to the pool. Must be aligned to the alginment boundary + * in use. */ void kmemaddblk(void *base, size_t size) { - struct block* b = &start; - struct block* n = (struct block*) base; + struct block *b = &start; + struct block *n = (struct block *) base; /* Run down the list until we find the last block. */ @@ -48,19 +49,19 @@ void kmemaddblk(void *base, size_t size) b->next = n; n->next = NULL; n->length = size; - #if defined(DEBUG_MEMORY) - kprintf("mem: add %x+%x\n", n, n->length); - #endif +#if defined(DEBUG_MEMORY) + kprintf("mem: add %x+%x\n", n, n->length); +#endif } /* * Find the smallest unused block containing at least length bytes. */ -static struct block* find_smallest(size_t length) +static struct block *find_smallest(size_t length) { static struct block dummy = { NULL, 0x7fffffff }; - struct block* smallest = &dummy; - struct block* b = &start; + struct block *smallest = &dummy; + struct block *b = &start; while (b->next) { @@ -81,22 +82,22 @@ static struct block* find_smallest(size_t length) * Split the supplied block into a used section and an unused section * immediately following it (if big enough). */ -static void split_block(struct block* b, size_t size) +static void split_block(struct block *b, size_t size) { int32_t newsize = b->length - size; /* might be negative */ - if (newsize > sizeof(struct block)*4) + if (newsize > sizeof(struct block) * 4) { - struct block* n = (struct block*)((uint8_t*)b + size); - #if defined(DEBUG_MEMORY) - kprintf("mem: split %x+%x -> ", b, b->length); - #endif + struct block *n = (struct block *)((uint8_t *)b + size); +#if defined(DEBUG_MEMORY) + kprintf("mem: split %x+%x -> ", b, b->length); +#endif n->next = b->next; b->next = n; b->length = size; n->length = newsize; - #if defined(DEBUG_MEMORY) - kprintf("%x+%x and %x+%x\n", b, b->length, n, n->length); - #endif +#if defined(DEBUG_MEMORY) + kprintf("%x+%x and %x+%x\n", b, b->length, n, n->length); +#endif } b->length |= 0x80000000; @@ -105,9 +106,9 @@ static void split_block(struct block* b, size_t size) /* * Allocate a block. */ -void* kmalloc(size_t size) +void *kmalloc(size_t size) { - struct block* b; + struct block *b; size = ALIGNUP(size) + sizeof(struct block); b = find_smallest(size); @@ -115,10 +116,10 @@ void* kmalloc(size_t size) return NULL; split_block(b, size); - #if defined(DEBUG_MEMORY) - kprintf("mem: alloc %x+%x\n", b, b->length); - #endif - return b+1; +#if defined(DEBUG_MEMORY) + kprintf("mem: alloc %x+%x\n", b, b->length); +#endif + return b + 1; } /* @@ -126,26 +127,26 @@ void* kmalloc(size_t size) */ static void merge_all_blocks(void) { - struct block* b = &start; + struct block *b = &start; while (b->next) { - struct block* n = b->next; + struct block *n = b->next; if (UNUSED(b) && UNUSED(n) && (((uint8_t*)b + b->length) == (uint8_t*)n)) { /* Two mergeable blocks are adjacent. */ - #if defined(DEBUG_MEMORY) - kprintf("mem: merge %x+%x and %x+%x -> ", - b, b->length, n, n->length); - #endif +#if defined(DEBUG_MEMORY) + kprintf("mem: merge %x+%x and %x+%x -> ", + b, b->length, n, n->length); +#endif b->next = n->next; b->length += n->length; - #if defined(DEBUG_MEMORY) - kprintf("%x+%x\n", b, b->length); - #endif +#if defined(DEBUG_MEMORY) + kprintf("%x+%x\n", b, b->length); +#endif } else { @@ -160,12 +161,12 @@ static void merge_all_blocks(void) * Free a block. If there's a block immediately after this one, merge it. * (This maintains ordering within split blocks.) */ -void kfree(void* p) +void kfree(void *p) { - struct block* b = (struct block*)p - 1; - #if defined(DEBUG_MEMORY) - kprintf("mem: free %x+%x\n", b, b->length); - #endif + struct block *b = (struct block *)p - 1; +#if defined(DEBUG_MEMORY) + kprintf("mem: free %x+%x\n", b, b->length); +#endif if (UNUSED(b)) panic(PANIC_BADFREE);