make kfree loop same as kalloc

This commit is contained in:
rsc 2007-08-27 12:50:36 +00:00
parent 7bb73cdbc7
commit e0240674f5

View file

@ -93,20 +93,17 @@ char*
kalloc(int n)
{
char *p;
struct run *r, **rr;
struct run *r, **rp;
if(n % PAGE || n <= 0)
panic("kalloc");
acquire(&kalloc_lock);
rr = &freelist;
while(*rr){
r = *rr;
for(rp=&freelist; (r=*rp) != 0; rp=&r->next){
if(r->len == n){
*rr = r->next;
*rp = r->next;
release(&kalloc_lock);
return (char*) r;
return (char*)r;
}
if(r->len > n){
r->len -= n;
@ -114,9 +111,9 @@ kalloc(int n)
release(&kalloc_lock);
return p;
}
rr = &(*rr)->next;
}
release(&kalloc_lock);
cprintf("kalloc: out of memory\n");
return 0;
}