diff mbox

hdat: ignore zero length reserves

Message ID 20170328040644.1374-1-oohall@gmail.com
State Accepted
Headers show

Commit Message

Oliver O'Halloran March 28, 2017, 4:06 a.m. UTC
Hostboot can export reserved regions with a length of zero and these
should be ignored rather than being turned into reserved range. While
we're here fix a memory leak by moving the "too large" region check
to before we allocate space for the label.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 hdata/memory.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

Comments

Stewart Smith March 30, 2017, 9:23 a.m. UTC | #1
Oliver O'Halloran <oohall@gmail.com> writes:
> Hostboot can export reserved regions with a length of zero and these
> should be ignored rather than being turned into reserved range. While
> we're here fix a memory leak by moving the "too large" region check
> to before we allocate space for the label.
>
> Signed-off-by: Oliver O'Halloran <oohall@gmail.com>

Appears to work okay, so merged to master as of
15511cfb042075b5a0e0962f830c4143626546d2

although I had to fiddle things a bit to make it apply, not exactly sure
why.... some minor change in there.
diff mbox

Patch

diff --git a/hdata/memory.c b/hdata/memory.c
index 657090da8b0c..7ab83f8b6134 100644
--- a/hdata/memory.c
+++ b/hdata/memory.c
@@ -436,6 +436,21 @@  static void get_hb_reserved_mem(struct HDIF_common_hdr *ms_vpd)
 		start_addr = be64_to_cpu(hb_resv_mem->start_addr);
 		end_addr = be64_to_cpu(hb_resv_mem->end_addr);
 
+		/* Zero length regions are a normal, but should be ignored */
+		if (start_addr - end_addr == 0) {
+			prlog(PR_DEBUG, "MEM: Ignoring zero length range\n");
+			continue;
+		}
+
+		/*
+		 * Workaround broken HDAT reserve regions which are
+		 * bigger than 512MB
+		 */
+		if ((end_addr - start_addr) > 0x20000000) {
+			prlog(PR_ERR, "MEM: Ignoring Bad HDAT reserve: too big\n");
+			continue;
+		}
+
 		/* remove the HRMOR bypass bit */
 		start_addr &= ~HRMOR_BIT;
 		end_addr &= ~HRMOR_BIT;
@@ -454,20 +469,6 @@  static void get_hb_reserved_mem(struct HDIF_common_hdr *ms_vpd)
 		prlog(PR_DEBUG, "MEM: Reserve '%s' %#" PRIx64 "-%#" PRIx64 " (type/inst=0x%08x)\n",
 		      label, start_addr, end_addr, be32_to_cpu(hb_resv_mem->type_instance));
 
-		if (start_addr == 0) {
-			prlog(PR_DEBUG, "MEM:   .. skipping\n");
-			continue;
-		}
-
-		/*
-		 * Workaround broken HDAT reserve regions which are
-		 * bigger than 512MB
-		 */
-		if ((end_addr - start_addr) > 0x20000000) {
-			prlog(PR_ERR, "MEM: Ignoring Bad HDAT reserve: too big\n");
-			continue;
-		}
-
 		if ((start_addr & 65535) || (end_addr & 65535))
 			prerror("MEM: '%s' does not start and end on a 64K boundary!", label);