a5bd9f6
From 9a854b2d6f1c40dc029d74a46af934908bf1cd5f Mon Sep 17 00:00:00 2001
a5bd9f6
From: Colin Watson <cjwatson@ubuntu.com>
a5bd9f6
Date: Mon, 21 Jan 2013 14:41:06 +0000
a5bd9f6
Subject: [PATCH 130/364] Fix powerpc and sparc64 build failures caused by
a5bd9f6
 un-nesting memory map iterators.
a5bd9f6
a5bd9f6
---
a5bd9f6
 ChangeLog                                 |  5 ++++
a5bd9f6
 grub-core/loader/powerpc/ieee1275/linux.c | 41 +++++++++++++++++++++----------
a5bd9f6
 grub-core/loader/sparc64/ieee1275/linux.c | 38 +++++++++++++++++-----------
a5bd9f6
 3 files changed, 57 insertions(+), 27 deletions(-)
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index 1c3958f..04572d2 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,5 +1,10 @@
a5bd9f6
 2013-01-21  Colin Watson  <cjwatson@ubuntu.com>
a5bd9f6
 
a5bd9f6
+	Fix powerpc and sparc64 build failures caused by un-nesting memory
a5bd9f6
+	map iterators.
a5bd9f6
+
a5bd9f6
+2013-01-21  Colin Watson  <cjwatson@ubuntu.com>
a5bd9f6
+
a5bd9f6
 	* grub-core/disk/arc/arcdisk.c (grub_arcdisk_iterate): Fix
a5bd9f6
 	parameter declarations.
a5bd9f6
 
a5bd9f6
diff --git a/grub-core/loader/powerpc/ieee1275/linux.c b/grub-core/loader/powerpc/ieee1275/linux.c
a5bd9f6
index b150904..c977941 100644
a5bd9f6
--- a/grub-core/loader/powerpc/ieee1275/linux.c
a5bd9f6
+++ b/grub-core/loader/powerpc/ieee1275/linux.c
a5bd9f6
@@ -51,37 +51,47 @@ static char *linux_args;
a5bd9f6
 typedef void (*kernel_entry_t) (void *, unsigned long, int (void *),
a5bd9f6
 				unsigned long, unsigned long);
a5bd9f6
 
a5bd9f6
+/* Context for grub_linux_claimmap_iterate.  */
a5bd9f6
+struct grub_linux_claimmap_iterate_ctx
a5bd9f6
+{
a5bd9f6
+  grub_addr_t target;
a5bd9f6
+  grub_size_t size;
a5bd9f6
+  grub_size_t align;
a5bd9f6
+  grub_addr_t found_addr;
a5bd9f6
+};
a5bd9f6
+
a5bd9f6
 /* Helper for grub_linux_claimmap_iterate.  */
a5bd9f6
 static int
a5bd9f6
 alloc_mem (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type,
a5bd9f6
 	   void *data)
a5bd9f6
 {
a5bd9f6
-  grub_addr_t *found_addr = data;
a5bd9f6
+  struct grub_linux_claimmap_iterate_ctx *ctx = data;
a5bd9f6
 
a5bd9f6
   grub_uint64_t end = addr + len;
a5bd9f6
-  addr = ALIGN_UP (addr, align);
a5bd9f6
-  target = ALIGN_UP (target, align);
a5bd9f6
+  addr = ALIGN_UP (addr, ctx->align);
a5bd9f6
+  ctx->target = ALIGN_UP (ctx->target, ctx->align);
a5bd9f6
 
a5bd9f6
   /* Target above the memory chunk.  */
a5bd9f6
-  if (type != GRUB_MEMORY_AVAILABLE || target > end)
a5bd9f6
+  if (type != GRUB_MEMORY_AVAILABLE || ctx->target > end)
a5bd9f6
     return 0;
a5bd9f6
 
a5bd9f6
   /* Target inside the memory chunk.  */
a5bd9f6
-  if (target >= addr && target < end && size <= end - target)
a5bd9f6
+  if (ctx->target >= addr && ctx->target < end &&
a5bd9f6
+      ctx->size <= end - ctx->target)
a5bd9f6
     {
a5bd9f6
-      if (grub_claimmap (target, size) == GRUB_ERR_NONE)
a5bd9f6
+      if (grub_claimmap (ctx->target, ctx->size) == GRUB_ERR_NONE)
a5bd9f6
 	{
a5bd9f6
-	  *found_addr = target;
a5bd9f6
+	  ctx->found_addr = ctx->target;
a5bd9f6
 	  return 1;
a5bd9f6
 	}
a5bd9f6
       grub_print_error ();
a5bd9f6
     }
a5bd9f6
   /* Target below the memory chunk.  */
a5bd9f6
-  if (target < addr && addr + size <= end)
a5bd9f6
+  if (ctx->target < addr && addr + ctx->size <= end)
a5bd9f6
     {
a5bd9f6
-      if (grub_claimmap (addr, size) == GRUB_ERR_NONE)
a5bd9f6
+      if (grub_claimmap (addr, ctx->size) == GRUB_ERR_NONE)
a5bd9f6
 	{
a5bd9f6
-	  *found_addr = addr;
a5bd9f6
+	  ctx->found_addr = addr;
a5bd9f6
 	  return 1;
a5bd9f6
 	}
a5bd9f6
       grub_print_error ();
a5bd9f6
@@ -93,11 +103,16 @@ static grub_addr_t
a5bd9f6
 grub_linux_claimmap_iterate (grub_addr_t target, grub_size_t size,
a5bd9f6
 			     grub_size_t align)
a5bd9f6
 {
a5bd9f6
-  grub_addr_t found_addr = (grub_addr_t) -1;
a5bd9f6
+  struct grub_linux_claimmap_iterate_ctx ctx = {
a5bd9f6
+    .target = target,
a5bd9f6
+    .size = size,
a5bd9f6
+    .align = align,
a5bd9f6
+    .found_addr = (grub_addr_t) -1
a5bd9f6
+  };
a5bd9f6
 
a5bd9f6
-  grub_machine_mmap_iterate (alloc_mem, &found_addr);
a5bd9f6
+  grub_machine_mmap_iterate (alloc_mem, &ctx;;
a5bd9f6
 
a5bd9f6
-  return found_addr;
a5bd9f6
+  return ctx.found_addr;
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 static grub_err_t
a5bd9f6
diff --git a/grub-core/loader/sparc64/ieee1275/linux.c b/grub-core/loader/sparc64/ieee1275/linux.c
a5bd9f6
index a485284..c85fcfd 100644
a5bd9f6
--- a/grub-core/loader/sparc64/ieee1275/linux.c
a5bd9f6
+++ b/grub-core/loader/sparc64/ieee1275/linux.c
a5bd9f6
@@ -180,32 +180,39 @@ grub_linux_unload (void)
a5bd9f6
 
a5bd9f6
 #define FOUR_MB	(4 * 1024 * 1024)
a5bd9f6
 
a5bd9f6
+/* Context for alloc_phys.  */
a5bd9f6
+struct alloc_phys_ctx
a5bd9f6
+{
a5bd9f6
+  grub_addr_t size;
a5bd9f6
+  grub_addr_t ret;
a5bd9f6
+};
a5bd9f6
+
a5bd9f6
 /* Helper for alloc_phys.  */
a5bd9f6
 static int
a5bd9f6
 alloc_phys_choose (grub_uint64_t addr, grub_uint64_t len,
a5bd9f6
 		   grub_memory_type_t type, void *data)
a5bd9f6
 {
a5bd9f6
-  grub_addr_t *ret = data;
a5bd9f6
+  struct alloc_phys_ctx *ctx = data;
a5bd9f6
   grub_addr_t end = addr + len;
a5bd9f6
 
a5bd9f6
   if (type != 1)
a5bd9f6
     return 0;
a5bd9f6
 
a5bd9f6
   addr = ALIGN_UP (addr, FOUR_MB);
a5bd9f6
-  if (addr + size >= end)
a5bd9f6
+  if (addr + ctx->size >= end)
a5bd9f6
     return 0;
a5bd9f6
 
a5bd9f6
   if (addr >= grub_phys_start && addr < grub_phys_end)
a5bd9f6
     {
a5bd9f6
       addr = ALIGN_UP (grub_phys_end, FOUR_MB);
a5bd9f6
-      if (addr + size >= end)
a5bd9f6
+      if (addr + ctx->size >= end)
a5bd9f6
 	return 0;
a5bd9f6
     }
a5bd9f6
-  if ((addr + size) >= grub_phys_start
a5bd9f6
-      && (addr + size) < grub_phys_end)
a5bd9f6
+  if ((addr + ctx->size) >= grub_phys_start
a5bd9f6
+      && (addr + ctx->size) < grub_phys_end)
a5bd9f6
     {
a5bd9f6
       addr = ALIGN_UP (grub_phys_end, FOUR_MB);
a5bd9f6
-      if (addr + size >= end)
a5bd9f6
+      if (addr + ctx->size >= end)
a5bd9f6
 	return 0;
a5bd9f6
     }
a5bd9f6
 
a5bd9f6
@@ -216,30 +223,33 @@ alloc_phys_choose (grub_uint64_t addr, grub_uint64_t len,
a5bd9f6
       if (addr >= linux_paddr && addr < linux_end)
a5bd9f6
 	{
a5bd9f6
 	  addr = linux_end;
a5bd9f6
-	  if (addr + size >= end)
a5bd9f6
+	  if (addr + ctx->size >= end)
a5bd9f6
 	    return 0;
a5bd9f6
 	}
a5bd9f6
-      if ((addr + size) >= linux_paddr
a5bd9f6
-	  && (addr + size) < linux_end)
a5bd9f6
+      if ((addr + ctx->size) >= linux_paddr
a5bd9f6
+	  && (addr + ctx->size) < linux_end)
a5bd9f6
 	{
a5bd9f6
 	  addr = linux_end;
a5bd9f6
-	  if (addr + size >= end)
a5bd9f6
+	  if (addr + ctx->size >= end)
a5bd9f6
 	    return 0;
a5bd9f6
 	}
a5bd9f6
     }
a5bd9f6
 
a5bd9f6
-  *ret = addr;
a5bd9f6
+  ctx->ret = addr;
a5bd9f6
   return 1;
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 static grub_addr_t
a5bd9f6
 alloc_phys (grub_addr_t size)
a5bd9f6
 {
a5bd9f6
-  grub_addr_t ret = (grub_addr_t) -1;
a5bd9f6
+  struct alloc_phys_ctx ctx = {
a5bd9f6
+    .size = size,
a5bd9f6
+    .ret = (grub_addr_t) -1
a5bd9f6
+  };
a5bd9f6
 
a5bd9f6
-  grub_machine_mmap_iterate (alloc_phys_choose, &ret;;
a5bd9f6
+  grub_machine_mmap_iterate (alloc_phys_choose, &ctx;;
a5bd9f6
 
a5bd9f6
-  return ret;
a5bd9f6
+  return ctx.ret;
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 static grub_err_t
a5bd9f6
-- 
a5bd9f6
1.8.1.4
a5bd9f6