diff --git a/kalloc.c b/kalloc.c index cc2faac..00c15bc 100644 --- a/kalloc.c +++ b/kalloc.c @@ -47,9 +47,7 @@ kinit(void) void kfree(char *v, int len) { - struct run **rr; - struct run *p = (struct run*)v; - struct run *pend = (struct run*)(v + len); + struct run **rr, *p, *pend; if(len % PAGE) panic("kfree"); @@ -58,7 +56,8 @@ kfree(char *v, int len) memset(v, 1, len); acquire(&kalloc_lock); - + p = (struct run*)v; + pend = (struct run*)(v + len); rr = &freelist; while(*rr){ struct run *rend = (struct run*) ((char*)(*rr) + (*rr)->len); @@ -100,7 +99,8 @@ kfree(char *v, int len) char* kalloc(int n) { - struct run **rr; + char *p; + struct run *r, **rr; if(n % PAGE) panic("kalloc"); @@ -109,15 +109,15 @@ kalloc(int n) rr = &freelist; while(*rr){ - struct run *r = *rr; + r = *rr; if(r->len == n){ *rr = r->next; release(&kalloc_lock); return (char*) r; } if(r->len > n){ - char *p = (char*)r + (r->len - n); r->len -= n; + p = (char*)r + r->len; release(&kalloc_lock); return p; }