From 1a81e38b17144624415d252a521fd5a06079d681 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 11 Jan 2011 13:01:13 -0500 Subject: make new code like old code Variable declarations at top of function, separate from initialization. Use == 0 instead of ! for checking pointers. Consistent spacing around {, *, casts. Declare 0-parameter functions as (void) not (). Integer valued functions return -1 on failure, 0 on success. --- kalloc.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'kalloc.c') diff --git a/kalloc.c b/kalloc.c index 72ce58a..e31d71d 100644 --- a/kalloc.c +++ b/kalloc.c @@ -23,9 +23,11 @@ extern char end[]; // first address after kernel loaded from ELF file void kinit(void) { + char *p; + initlock(&kmem.lock, "kmem"); - char *p = (char*)PGROUNDUP((uint)end); - for( ; p + PGSIZE - 1 < (char*) PHYSTOP; p += PGSIZE) + p = (char*)PGROUNDUP((uint)end); + for(; p + PGSIZE - 1 < (char*)PHYSTOP; p += PGSIZE) kfree(p); } @@ -39,14 +41,14 @@ kfree(char *v) { struct run *r; - if(((uint) v) % PGSIZE || v < end || (uint)v >= PHYSTOP) + if((uint)v % PGSIZE || v < end || (uint)v >= PHYSTOP) panic("kfree"); // Fill with junk to catch dangling refs. memset(v, 1, PGSIZE); acquire(&kmem.lock); - r = (struct run *) v; + r = (struct run*)v; r->next = kmem.freelist; kmem.freelist = r; release(&kmem.lock); @@ -56,7 +58,7 @@ kfree(char *v) // Returns a pointer that the kernel can use. // Returns 0 if the memory cannot be allocated. char* -kalloc() +kalloc(void) { struct run *r; @@ -65,6 +67,6 @@ kalloc() if(r) kmem.freelist = r->next; release(&kmem.lock); - return (char*) r; + return (char*)r; } -- cgit v1.2.3