diff mbox series

[05/19] libpdbg: Always allocate ffdc data and return to caller

Message ID 20200702033918.708013-6-amitay@ozlabs.org
State Accepted
Headers show
Series Fixes and cleanup before release | expand

Commit Message

Amitay Isaacs July 2, 2020, 3:39 a.m. UTC
Instead of returning the pointer to internally cached ffdc data, copy
the ffdc data.

Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 libpdbg/libpdbg.h |  5 +++--
 libpdbg/target.c  | 17 +++++++++++++++--
 2 files changed, 18 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
index e850108..28380cd 100644
--- a/libpdbg/libpdbg.h
+++ b/libpdbg/libpdbg.h
@@ -1259,9 +1259,10 @@  int sbe_istep(struct pdbg_target *target, uint32_t major, uint32_t minor);
  *
  * @return SBE error code, 0 if there is no ffdc data
  *
- * The ffdc data must be freed by caller.
+ * The ffdc data must be freed by caller.  It is allocated using malloc and
+ * must be freed using free().
  */
-uint32_t sbe_ffdc_get(struct pdbg_target *target, const uint8_t **ffdc, uint32_t *ffdc_len);
+uint32_t sbe_ffdc_get(struct pdbg_target *target, uint8_t **ffdc, uint32_t *ffdc_len);
 
 /**
  * @brief Execute enter mpipl on the pib
diff --git a/libpdbg/target.c b/libpdbg/target.c
index dff446c..69f8b24 100644
--- a/libpdbg/target.c
+++ b/libpdbg/target.c
@@ -463,9 +463,11 @@  int sbe_mpipl_get_ti_info(struct pdbg_target *target, uint8_t **data, uint32_t *
 	return chipop->mpipl_get_ti_info(chipop, data, data_len);
 }
 
-uint32_t sbe_ffdc_get(struct pdbg_target *target, const uint8_t **ffdc, uint32_t *ffdc_len)
+uint32_t sbe_ffdc_get(struct pdbg_target *target, uint8_t **ffdc, uint32_t *ffdc_len)
 {
 	struct chipop *chipop;
+	const uint8_t *data = NULL;
+	uint32_t status, len = 0;
 
 	chipop = pib_to_chipop(target);
 	if (!chipop)
@@ -476,7 +478,18 @@  uint32_t sbe_ffdc_get(struct pdbg_target *target, const uint8_t **ffdc, uint32_t
 		return -1;
 	}
 
-	return chipop->ffdc_get(chipop, ffdc, ffdc_len);
+	status = chipop->ffdc_get(chipop, &data, &len);
+	if (data && len > 0) {
+		*ffdc = malloc(len);
+		assert(*ffdc);
+		memcpy(*ffdc, data, len);
+		*ffdc_len = len;
+	} else {
+		*ffdc = NULL;
+		*ffdc_len = 0;
+	}
+
+	return status;
 }
 
 /* Finds the given class. Returns NULL if not found. */