diff mbox series

[v3,1/2] hdata: Cleanup get_hb_reserved_mem

Message ID 20180907051655.5812-1-hegdevasant@linux.vnet.ibm.com
State Accepted
Headers show
Series [v3,1/2] hdata: Cleanup get_hb_reserved_mem | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success master/apply_patch Successfully applied

Commit Message

Vasant Hegde Sept. 7, 2018, 5:16 a.m. UTC
- Use macro for label size
- Replace malloc with array

Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Reviewed-by: Oliver O'Halloran <oohall@gmail.com>
---
Changes in v3:
  - s/LABLE/LABEL/s - Thanks Oliver

-Vasant

 hdata/memory.c | 14 +++++---------
 hdata/spira.h  |  3 ++-
 2 files changed, 7 insertions(+), 10 deletions(-)

Comments

Stewart Smith Sept. 13, 2018, 8:53 a.m. UTC | #1
Vasant Hegde <hegdevasant@linux.vnet.ibm.com> writes:
> - Use macro for label size
> - Replace malloc with array
>
> Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
> Reviewed-by: Oliver O'Halloran <oohall@gmail.com>
> ---
> Changes in v3:
>   - s/LABLE/LABEL/s - Thanks Oliver
>
> -Vasant
>
>  hdata/memory.c | 14 +++++---------
>  hdata/spira.h  |  3 ++-
>  2 files changed, 7 insertions(+), 10 deletions(-)

Series merged as of 50d508c3cd62499ae0d3c6f0f800926869a1cd01
diff mbox series

Patch

diff --git a/hdata/memory.c b/hdata/memory.c
index ecce881d1..d9c9ddda9 100644
--- a/hdata/memory.c
+++ b/hdata/memory.c
@@ -596,7 +596,7 @@  static void get_hb_reserved_mem(struct HDIF_common_hdr *ms_vpd)
 	u64 start_addr, end_addr, label_size;
 	struct dt_node *node;
 	int count, i;
-	char *label;
+	char label[HB_RESERVE_MEM_LABEL_SIZE + 1];
 
 	/*
 	 * XXX: Reservation names only exist on P9 and on P7/8 we get the
@@ -640,20 +640,16 @@  static void get_hb_reserved_mem(struct HDIF_common_hdr *ms_vpd)
 		/* remove the HRMOR bypass bit */
 		start_addr &= ~HRMOR_BIT;
 		end_addr &= ~HRMOR_BIT;
-		if (label_size > 64)
-			label_size = 64;
-
-		label = malloc(label_size+1);
-		assert(label);
+		if (label_size > HB_RESERVE_MEM_LABEL_SIZE)
+			label_size = HB_RESERVE_MEM_LABEL_SIZE;
 
+		memset(label, 0, HB_RESERVE_MEM_LABEL_SIZE + 1);
 		memcpy(label, hb_resv_mem->label, label_size);
 		label[label_size] = '\0';
 
 		/* Unnamed reservations are always broken. Ignore them. */
-		if (strlen(label) == 0) {
-			free(label);
+		if (strlen(label) == 0)
 			continue;
-		}
 
 		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));
diff --git a/hdata/spira.h b/hdata/spira.h
index ef2aec257..476cfba1d 100644
--- a/hdata/spira.h
+++ b/hdata/spira.h
@@ -541,6 +541,7 @@  struct msvpd_trace {
 
 /* Idata index 5: Hostboot reserved memory address range */
 #define MSVPD_IDATA_HB_RESERVED_MEM	5
+#define HB_RESERVE_MEM_LABEL_SIZE	64
 struct msvpd_hb_reserved_mem {
 #define MSVPD_HBRMEM_RANGE_TYPE	PPC_BITMASK32(0,7)
 #define HBRMEM_CONTAINER_VERIFICATION_CODE 	0x3
@@ -548,7 +549,7 @@  struct msvpd_hb_reserved_mem {
 	__be64		start_addr;
 	__be64		end_addr;
 	__be32		label_size;
-	uint8_t		label[64];
+	uint8_t		label[HB_RESERVE_MEM_LABEL_SIZE];
 	uint8_t		rw_perms;
 #define HB_RESERVE_READABLE 0x80
 #define HB_RESERVE_WRITEABLE 0x40