diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2020-10-12 08:44:46 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2020-10-12 08:44:46 +0000 |
commit | 48f9770343f309f7fcc86b30dbf340b214a5690b (patch) | |
tree | 95e6674e66ba38d24a2d502b6ad7a0b15bb13a99 /sys/uvm | |
parent | b7a62f55075e38f32d35f8c4cad62222582c6d4b (diff) |
Use KASSERT() instead of if(x) panic() for NULL dereference checks.
Improves readability and reduces the difference with NetBSD without
compromising debuggability on RAMDISK.
While here also use local variables to help with future locking and
reference counting.
ok semarie@
Diffstat (limited to 'sys/uvm')
-rw-r--r-- | sys/uvm/uvm_amap.c | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/sys/uvm/uvm_amap.c b/sys/uvm/uvm_amap.c index 310e5e8446f..b49835e74ef 100644 --- a/sys/uvm/uvm_amap.c +++ b/sys/uvm/uvm_amap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_amap.c,v 1.84 2020/09/25 08:04:48 mpi Exp $ */ +/* $OpenBSD: uvm_amap.c,v 1.85 2020/10/12 08:44:45 mpi Exp $ */ /* $NetBSD: uvm_amap.c,v 1.27 2000/11/25 06:27:59 chs Exp $ */ /* @@ -669,9 +669,7 @@ ReStart: pg = anon->an_page; /* page must be resident since parent is wired */ - if (pg == NULL) - panic("amap_cow_now: non-resident wired page" - " in anon %p", anon); + KASSERT(pg != NULL); /* * if the anon ref count is one, we are safe (the child @@ -740,6 +738,7 @@ ReStart: void amap_splitref(struct vm_aref *origref, struct vm_aref *splitref, vaddr_t offset) { + struct vm_amap *amap = origref->ar_amap; int leftslots; AMAP_B2SLOT(leftslots, offset); @@ -747,17 +746,18 @@ amap_splitref(struct vm_aref *origref, struct vm_aref *splitref, vaddr_t offset) panic("amap_splitref: split at zero offset"); /* now: we have a valid am_mapped array. */ - if (origref->ar_amap->am_nslot - origref->ar_pageoff - leftslots <= 0) + if (amap->am_nslot - origref->ar_pageoff - leftslots <= 0) panic("amap_splitref: map size check failed"); #ifdef UVM_AMAP_PPREF - /* establish ppref before we add a duplicate reference to the amap */ - if (origref->ar_amap->am_ppref == NULL) - amap_pp_establish(origref->ar_amap); + /* Establish ppref before we add a duplicate reference to the amap. */ + if (amap->am_ppref == NULL) + amap_pp_establish(amap); #endif - splitref->ar_amap = origref->ar_amap; - splitref->ar_amap->am_ref++; /* not a share reference */ + /* Note: not a share reference. */ + amap->am_ref++; + splitref->ar_amap = amap; splitref->ar_pageoff = origref->ar_pageoff + leftslots; } @@ -1104,12 +1104,11 @@ amap_add(struct vm_aref *aref, vaddr_t offset, struct vm_anon *anon, slot = UVM_AMAP_SLOTIDX(slot); if (replace) { - if (chunk->ac_anon[slot] == NULL) - panic("amap_add: replacing null anon"); - if (chunk->ac_anon[slot]->an_page != NULL && - (amap->am_flags & AMAP_SHARED) != 0) { - pmap_page_protect(chunk->ac_anon[slot]->an_page, - PROT_NONE); + struct vm_anon *oanon = chunk->ac_anon[slot]; + + KASSERT(oanon != NULL); + if (oanon->an_page && (amap->am_flags & AMAP_SHARED) != 0) { + pmap_page_protect(oanon->an_page, PROT_NONE); /* * XXX: suppose page is supposed to be wired somewhere? */ @@ -1140,12 +1139,10 @@ amap_unadd(struct vm_aref *aref, vaddr_t offset) slot += aref->ar_pageoff; KASSERT(slot < amap->am_nslot); chunk = amap_chunk_get(amap, slot, 0, PR_NOWAIT); - if (chunk == NULL) - panic("amap_unadd: chunk for slot %d not present", slot); + KASSERT(chunk != NULL); slot = UVM_AMAP_SLOTIDX(slot); - if (chunk->ac_anon[slot] == NULL) - panic("amap_unadd: nothing there"); + KASSERT(chunk->ac_anon[slot] != NULL); chunk->ac_anon[slot] = NULL; chunk->ac_usedmap &= ~(1 << slot); |