Skip to content

Commit

Permalink
mmu: fix virt_region_alloc() unused region free when aligned
Browse files Browse the repository at this point in the history
In the case where the aligned memory range is on top of the allocated
memory range, freeing the 0 sized top unused memory will trigger
an assert in the virt_region_free() call since vaddr could be equal
to Z_VIRT_REGION_END_ADDR.

Signed-off-by: Neil Armstrong <[email protected]>
  • Loading branch information
superna9999 authored and nashif committed Oct 13, 2021
1 parent 513d691 commit 2f359ae
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kernel/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,10 @@ static void *virt_region_alloc(size_t size, size_t align)
/* Free the two unused regions */
virt_region_free(UINT_TO_POINTER(dest_addr),
aligned_dest_addr - dest_addr);
virt_region_free(UINT_TO_POINTER(aligned_dest_addr + size),
(dest_addr + alloc_size) - (aligned_dest_addr + size));
if (((dest_addr + alloc_size) - (aligned_dest_addr + size)) > 0) {
virt_region_free(UINT_TO_POINTER(aligned_dest_addr + size),
(dest_addr + alloc_size) - (aligned_dest_addr + size));
}

dest_addr = aligned_dest_addr;
}
Expand Down

0 comments on commit 2f359ae

Please sign in to comment.