[v3,2/2] hdata/vpd: Improve vpd node find logic

Message ID 20171010054018.11301-2-hegdevasant@linux.vnet.ibm.com
State Accepted
Headers show
Series
  • [v3,1/2] hdata/vpd: Rework vpd node creation logic
Related show

Commit Message

Vasant Hegde Oct. 10, 2017, 5:40 a.m.
Use dt_find_by_name_addr() instead of dt_find_by_name(). That way we
can avoid unnecessary memory allocation/cleanup.

CC: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
---
 hdata/vpd.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

Patch

diff --git a/hdata/vpd.c b/hdata/vpd.c
index df9e1bf..6abbd59 100644
--- a/hdata/vpd.c
+++ b/hdata/vpd.c
@@ -435,8 +435,6 @@  struct dt_node *dt_add_vpd_node(const struct HDIF_common_hdr *hdr,
 	const void *fruvpd;
 	const char *name;
 	uint64_t addr;
-	char *lname;
-	int len;
 
 	fru_id = HDIF_get_idata(hdr, indx_fru, &fru_id_sz);
 	if (!fru_id)
@@ -455,19 +453,9 @@  struct dt_node *dt_add_vpd_node(const struct HDIF_common_hdr *hdr,
 		return NULL;
 
 	name = vpd_map_name(entry->fru_id);
-	addr = (uint64_t)be16_to_cpu(entry->rsrc_id);
-	len = strlen(name) + STR_MAX_CHARS(addr) + 2;
-	lname = zalloc(len);
-	if (!lname) {
-		prerror("VPD: Failed to allocate memory\n");
-		return NULL;
-	}
-
-	snprintf(lname, len, "%s@%llx", name, (long long)addr);
-
+	addr = be16_to_cpu(entry->rsrc_id);
 	/* Get the node already created */
-	node = dt_find_by_name(dt_vpd, lname);
-	free(lname);
+	node = dt_find_by_name_addr(dt_vpd, name, addr);
 	/*
 	 * It is unlikely that node not found because vpd nodes have the
 	 * corresponding slca entry which we would have used to populate the vpd