]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[pcbios] Take alignment into account when checking for available space
authorDavid Decotigny <ddecotig@gmail.com>
Wed, 15 Jan 2020 07:42:05 +0000 (23:42 -0800)
committerMichael Brown <mcb30@ipxe.org>
Tue, 21 Jul 2020 13:51:32 +0000 (14:51 +0100)
Signed-off-by: David Decotigny <ddecotig@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/interface/pcbios/memtop_umalloc.c

index d7b82189a7e5b7a4a431d2ab96735d8d87029fc8..1d3f40a1cff213a88ec0eb739783632c348f2a51 100644 (file)
@@ -190,14 +190,14 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) {
        /* Expand/shrink block if possible */
        if ( ptr == bottom ) {
                /* Update block */
-               if ( new_size > ( heap_size + extmem.size ) ) {
-                       DBG ( "EXTMEM out of space\n" );
-                       return UNULL;
-               }
                new = userptr_add ( ptr, - ( new_size - extmem.size ) );
                align = ( user_to_phys ( new, 0 ) & ( EM_ALIGN - 1 ) );
                new_size += align;
                new = userptr_add ( new, -align );
+               if ( new_size > ( heap_size + extmem.size ) ) {
+                       DBG ( "EXTMEM out of space\n" );
+                       return UNULL;
+               }
                DBG ( "EXTMEM expanding [%lx,%lx) to [%lx,%lx)\n",
                      user_to_phys ( ptr, 0 ),
                      user_to_phys ( ptr, extmem.size ),