[kernel][vm] Fix end address checks

If the end of a range is at the end of the virtual address space,
(base + size) is 0. Use (base + size - 1) instead.

Change-Id: I7d02250d765df0ab2bd23b60ee7a484951238c58
This commit is contained in:
Arve Hjønnevåg
2015-02-17 16:22:31 -08:00
committed by Travis Geiselbrecht
parent d4fe1afa7d
commit d0c4833b3f
2 changed files with 3 additions and 3 deletions

View File

@@ -46,7 +46,7 @@ static mutex_t lock = MUTEX_INITIAL_VALUE(lock);
(paddr_t)(((uintptr_t)page - (uintptr_t)a->page_array) / sizeof(vm_page_t)) * PAGE_SIZE + a->base;
#define ADDRESS_IN_ARENA(address, arena) \
((address) >= (arena)->base && (address) <= (arena)->base + (arena)->size)
((address) >= (arena)->base && (address) <= (arena)->base + (arena)->size - 1)
static inline bool page_is_free(const vm_page_t *page)
{
@@ -283,7 +283,7 @@ uint pmm_alloc_contiguous(uint count, uint8_t alignment_log2, paddr_t *pa, struc
* is not aligned on the same boundary requested.
*/
paddr_t rounded_base = ROUNDUP(a->base, 1UL << alignment_log2);
if (rounded_base < a->base || rounded_base >= a->base + a->size)
if (rounded_base < a->base || rounded_base > a->base + a->size - 1)
continue;
uint aligned_offset = (rounded_base - a->base) / PAGE_SIZE;

View File

@@ -104,7 +104,7 @@ void *paddr_to_kvaddr(paddr_t pa)
while (map->size > 0) {
if (!(map->flags & MMU_INITIAL_MAPPING_TEMPORARY) &&
pa >= map->phys &&
pa <= map->phys + map->size) {
pa <= map->phys + map->size - 1) {
return (void *)(map->virt + (pa - map->phys));
}
map++;