If a single memory block is requested (GRUB_MM_ADD_REGION_CONSECUTIVE)
then check early on whether the given block from the memory map is
big enough to satisfy the request.

Signed-off-by: Stefan Berger <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Pavithra Prakash <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Carolyn Scherrer <[email protected]>
Cc: Mahesh Salgaonkar <[email protected]>
Cc: Sourabh Jain <[email protected]>
---
 grub-core/kern/ieee1275/init.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
index e09db4192..a0ce9d55e 100644
--- a/grub-core/kern/ieee1275/init.c
+++ b/grub-core/kern/ieee1275/init.c
@@ -328,6 +328,10 @@ regions_claim (grub_uint64_t addr, grub_uint64_t len, 
grub_memory_type_t type,
   if (type != GRUB_MEMORY_AVAILABLE)
     return 0;
 
+  /* If a specific size was requested: is this chunk big enough? */
+  if (rcr->flags & GRUB_MM_ADD_REGION_CONSECUTIVE && len < rcr->total)
+    return 0;
+
   /* Do not consider memory beyond 4GB */
   if (addr > 0xffffffffULL)
     return 0;
-- 
2.25.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to