Run Nindent on com32/lib/malloc.c
authorH. Peter Anvin <hpa@zytor.com>
Fri, 29 May 2009 22:10:23 +0000 (15:10 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Fri, 29 May 2009 22:10:23 +0000 (15:10 -0700)
Automatically reformat com32/lib/malloc.c using Nindent.

Do this for all files except HDT, gPXE and externally maintained
libraries (zlib, tinyjpeg, libpng).

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
com32/lib/malloc.c

index 40e88b4..ec103ab 100644 (file)
 #include "init.h"
 #include "malloc.h"
 
-struct free_arena_header __malloc_head =
-{
-  {
-    ARENA_TYPE_HEAD,
-    0,
-    &__malloc_head,
+struct free_arena_header __malloc_head = {
+    {
+     ARENA_TYPE_HEAD,
+     0,
+     &__malloc_head,
+     &__malloc_head,
+     },
     &__malloc_head,
-  },
-  &__malloc_head,
-  &__malloc_head
+    &__malloc_head
 };
 
 /* This is extern so it can be overridden by the user application */
@@ -29,9 +28,9 @@ extern void *__mem_end;               /* Produced after argv parsing */
 
 static inline size_t sp(void)
 {
-  size_t sp;
-  asm volatile("movl %%esp,%0" : "=rm" (sp));
-  return sp;
+    size_t sp;
+    asm volatile ("movl %%esp,%0":"=rm" (sp));
+    return sp;
 }
 
 #define E820_MEM_MAX 0xfff00000        /* 4 GB - 1 MB */
@@ -39,119 +38,119 @@ static inline size_t sp(void)
 static int consider_memory_area(void *dummy, addr_t start,
                                addr_t len, bool valid)
 {
-  struct free_arena_header *fp;
-  addr_t end;
+    struct free_arena_header *fp;
+    addr_t end;
 
-  (void)dummy;
+    (void)dummy;
 
-  if (valid && start < E820_MEM_MAX) {
-    if (len > E820_MEM_MAX - start)
-      len = E820_MEM_MAX - start;
+    if (valid && start < E820_MEM_MAX) {
+       if (len > E820_MEM_MAX - start)
+           len = E820_MEM_MAX - start;
 
-    end = start + len;
+       end = start + len;
 
-    if (end > __com32.cs_memsize) {
-      if (start <= __com32.cs_memsize) {
-       start = __com32.cs_memsize;
-       len = end - start;
-      }
+       if (end > __com32.cs_memsize) {
+           if (start <= __com32.cs_memsize) {
+               start = __com32.cs_memsize;
+               len = end - start;
+           }
 
-      if (len >= 2*sizeof(struct arena_header)) {
-       fp = (struct free_arena_header *)start;
-       fp->a.size = len;
-       __inject_free_block(fp);
-      }
+           if (len >= 2 * sizeof(struct arena_header)) {
+               fp = (struct free_arena_header *)start;
+               fp->a.size = len;
+               __inject_free_block(fp);
+           }
+       }
     }
-  }
 
-  return 0;
+    return 0;
 }
 
 static void __constructor init_memory_arena(void)
 {
-  struct free_arena_header *fp;
-  size_t start, total_space;
+    struct free_arena_header *fp;
+    size_t start, total_space;
 
-  start = (size_t)ARENA_ALIGN_UP(__mem_end);
-  total_space = sp() - start;
+    start = (size_t) ARENA_ALIGN_UP(__mem_end);
+    total_space = sp() - start;
 
-  if ( __stack_size == 0 || __stack_size > total_space >> 1 )
-    __stack_size = total_space >> 1; /* Half for the stack, half for the heap... */
+    if (__stack_size == 0 || __stack_size > total_space >> 1)
+       __stack_size = total_space >> 1;        /* Half for the stack, half for the heap... */
 
-  if ( total_space < __stack_size + 4*sizeof(struct arena_header) )
-    __stack_size = total_space - 4*sizeof(struct arena_header);
+    if (total_space < __stack_size + 4 * sizeof(struct arena_header))
+       __stack_size = total_space - 4 * sizeof(struct arena_header);
 
-  fp = (struct free_arena_header *)start;
-  fp->a.size = total_space - __stack_size;
+    fp = (struct free_arena_header *)start;
+    fp->a.size = total_space - __stack_size;
 
-  __inject_free_block(fp);
+    __inject_free_block(fp);
 
-  /* Scan the memory map to look for other suitable regions */
-  if (!__com32.cs_memsize)
-    return;                    /* Old Syslinux core, can't do this... */
+    /* Scan the memory map to look for other suitable regions */
+    if (!__com32.cs_memsize)
+       return;                 /* Old Syslinux core, can't do this... */
 
-  syslinux_scan_memory(consider_memory_area, NULL);
+    syslinux_scan_memory(consider_memory_area, NULL);
 }
 
 static void *__malloc_from_block(struct free_arena_header *fp, size_t size)
 {
-  size_t fsize;
-  struct free_arena_header *nfp, *na;
-
-  fsize = fp->a.size;
-
-  /* We need the 2* to account for the larger requirements of a free block */
-  if ( fsize >= size+2*sizeof(struct arena_header) ) {
-    /* Bigger block than required -- split block */
-    nfp = (struct free_arena_header *)((char *)fp + size);
-    na = fp->a.next;
-
-    nfp->a.type = ARENA_TYPE_FREE;
-    nfp->a.size = fsize-size;
-    fp->a.type  = ARENA_TYPE_USED;
-    fp->a.size  = size;
-
-    /* Insert into all-block chain */
-    nfp->a.prev = fp;
-    nfp->a.next = na;
-    na->a.prev = nfp;
-    fp->a.next = nfp;
-
-    /* Replace current block on free chain */
-    nfp->next_free = fp->next_free;
-    nfp->prev_free = fp->prev_free;
-    fp->next_free->prev_free = nfp;
-    fp->prev_free->next_free = nfp;
-  } else {
-    /* Allocate the whole block */
-    fp->a.type = ARENA_TYPE_USED;
-
-    /* Remove from free chain */
-    fp->next_free->prev_free = fp->prev_free;
-    fp->prev_free->next_free = fp->next_free;
-  }
-
-  return (void *)(&fp->a + 1);
+    size_t fsize;
+    struct free_arena_header *nfp, *na;
+
+    fsize = fp->a.size;
+
+    /* We need the 2* to account for the larger requirements of a free block */
+    if (fsize >= size + 2 * sizeof(struct arena_header)) {
+       /* Bigger block than required -- split block */
+       nfp = (struct free_arena_header *)((char *)fp + size);
+       na = fp->a.next;
+
+       nfp->a.type = ARENA_TYPE_FREE;
+       nfp->a.size = fsize - size;
+       fp->a.type = ARENA_TYPE_USED;
+       fp->a.size = size;
+
+       /* Insert into all-block chain */
+       nfp->a.prev = fp;
+       nfp->a.next = na;
+       na->a.prev = nfp;
+       fp->a.next = nfp;
+
+       /* Replace current block on free chain */
+       nfp->next_free = fp->next_free;
+       nfp->prev_free = fp->prev_free;
+       fp->next_free->prev_free = nfp;
+       fp->prev_free->next_free = nfp;
+    } else {
+       /* Allocate the whole block */
+       fp->a.type = ARENA_TYPE_USED;
+
+       /* Remove from free chain */
+       fp->next_free->prev_free = fp->prev_free;
+       fp->prev_free->next_free = fp->next_free;
+    }
+
+    return (void *)(&fp->a + 1);
 }
 
 void *malloc(size_t size)
 {
-  struct free_arena_header *fp;
+    struct free_arena_header *fp;
 
-  if ( size == 0 )
-    return NULL;
+    if (size == 0)
+       return NULL;
 
-  /* Add the obligatory arena header, and round up */
-  size = (size+2*sizeof(struct arena_header)-1) & ARENA_SIZE_MASK;
+    /* Add the obligatory arena header, and round up */
+    size = (size + 2 * sizeof(struct arena_header) - 1) & ARENA_SIZE_MASK;
 
-  for ( fp = __malloc_head.next_free ; fp->a.type != ARENA_TYPE_HEAD ;
-       fp = fp->next_free ) {
-    if ( fp->a.size >= size ) {
-      /* Found fit -- allocate out of this block */
-      return __malloc_from_block(fp, size);
+    for (fp = __malloc_head.next_free; fp->a.type != ARENA_TYPE_HEAD;
+        fp = fp->next_free) {
+       if (fp->a.size >= size) {
+           /* Found fit -- allocate out of this block */
+           return __malloc_from_block(fp, size);
+       }
     }
-  }
 
-  /* Nothing found... need to request a block from the kernel */
-  return NULL;                 /* No kernel to get stuff from */
+    /* Nothing found... need to request a block from the kernel */
+    return NULL;               /* No kernel to get stuff from */
 }