memory: Don't map extra page unnecessarily

When offset2 != 0 it doesn't necessarily mean that we need an extra page.
Fix calculation to map extra page only when necesarry.

This is needed as next page may be unavailable like when available RAM
follows XSDT and hence not available for mapping.
This commit is contained in:
Vladimir Serbinenko 2023-08-16 02:47:15 +02:00
parent 0a70170952
commit dfac99781c
1 changed files with 2 additions and 1 deletions

View File

@ -1325,7 +1325,8 @@ void *MMMapPhysical(MMSpace *space, uintptr_t offset, size_t bytes, uint64_t cac
uintptr_t offset2 = offset & (K_PAGE_SIZE - 1);
offset -= offset2;
if (offset2) bytes += K_PAGE_SIZE;
bytes += offset2;
bytes = (bytes + K_PAGE_SIZE - 1) & ~(K_PAGE_SIZE - 1);
MMRegion *region;