summaryrefslogtreecommitdiff
path: root/kalloc.c
diff options
context:
space:
mode:
authorRuss Cox <[email protected]>2011-01-11 13:01:13 -0500
committerRuss Cox <[email protected]>2011-01-11 13:01:13 -0500
commit1a81e38b17144624415d252a521fd5a06079d681 (patch)
treeea7d895bcf77aa25861c09ee490488b6f729e0f3 /kalloc.c
parent240679608cd46649d1144408f28f83141f9f3a86 (diff)
downloadxv6-labs-1a81e38b17144624415d252a521fd5a06079d681.tar.gz
xv6-labs-1a81e38b17144624415d252a521fd5a06079d681.tar.bz2
xv6-labs-1a81e38b17144624415d252a521fd5a06079d681.zip
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.
Diffstat (limited to 'kalloc.c')
-rw-r--r--kalloc.c14
1 files changed, 8 insertions, 6 deletions
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;
}