make kfree loop same as kalloc
This commit is contained in:
parent
7bb73cdbc7
commit
e0240674f5
1 changed files with 5 additions and 8 deletions
13
kalloc.c
13
kalloc.c
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue