malloc: tidy formatting to match core code standard
authorAlan Cox <alan@linux.intel.com>
Fri, 9 Mar 2018 20:56:16 +0000 (20:56 +0000)
committerAlan Cox <alan@linux.intel.com>
Fri, 9 Mar 2018 20:56:16 +0000 (20:56 +0000)
Kernel/malloc.c

index a34edda..c9e8236 100644 (file)
@@ -22,7 +22,7 @@
 
 struct block
 {
-       struct blocknext;
+       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 blockb = &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 blockfind_smallest(size_t length)
+static struct block *find_smallest(size_t length)
 {
        static struct block dummy = { NULL, 0x7fffffff };
-       struct blocksmallest = &dummy;
-       struct blockb = &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 blockb, 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.
  */
-voidkmalloc(size_t size)
+void *kmalloc(size_t size)
 {
-       struct blockb;
+       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 blockb = &start;
+       struct block *b = &start;
 
        while (b->next)
        {
-               struct blockn = 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(voidp)
+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);