From 920c766d445f87dbcd073694eb5da2ed384399ce Mon Sep 17 00:00:00 2001 From: Axel Heider Date: Fri, 3 Nov 2023 16:25:29 +0100 Subject: [PATCH] libsel4allocman: simplify code Signed-off-by: Axel Heider --- libsel4allocman/src/bootstrap.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/libsel4allocman/src/bootstrap.c b/libsel4allocman/src/bootstrap.c index 172946b2..3a95b7f4 100644 --- a/libsel4allocman/src/bootstrap.c +++ b/libsel4allocman/src/bootstrap.c @@ -1011,10 +1011,7 @@ static int handle_device_untyped_cap(add_untypeds_state_t *state, uintptr_t padd bool cap_tainted = false; int error; uintptr_t ut_end = paddr + BIT(size_bits); - int num_regions = 0; - if (state != NULL) { - num_regions = state->num_regions; - } + int num_regions = state ? state->num_regions : 0; for (int i = 0; i < num_regions; i++) { pmem_region_t *region = &state->regions[i]; uint64_t region_end = region->base_addr + region->length; @@ -1128,15 +1125,14 @@ int allocman_add_simple_untypeds_with_regions(allocman_t *alloc, simple_t *simpl uintptr_t paddr; bool device; cspacepath_t path = allocman_cspace_make_path(alloc, simple_get_nth_untyped(simple, i, &size_bits, &paddr, &device)); - int dev_type = device ? ALLOCMAN_UT_DEV : ALLOCMAN_UT_KERNEL; - // If it is regular UT memory, then we add cap and move on. - if (dev_type == ALLOCMAN_UT_KERNEL) { - error = allocman_utspace_add_uts(alloc, 1, &path, &size_bits, &paddr, dev_type); - ZF_LOGF_IF(error, "Could not add kernel untyped."); - } else { - // Otherwise we are Device untyped. + if (device) { + // Separates device RAM memory into separate untyped caps error = handle_device_untyped_cap(state, paddr, size_bits, &path, alloc); - ZF_LOGF_IF(error, "bootstrap_arch_handle_device_untyped_cap failed."); + ZF_LOGF_IF(error, "handle_device_untyped_cap failed (%d).", error); + } else { + // for regular UT memory we add cap + error = allocman_utspace_add_uts(alloc, 1, &path, &size_bits, &paddr, ALLOCMAN_UT_KERNEL); + ZF_LOGF_IF(error, "Could not add kernel untyped (%d).", error); } } if (state) {