pdr: Introduce pldm_pdr_add_fru_record_set_check()

pldm_pdr_add_fru_record_set() relied on assert() to communicate failure
to the caller. Introduce pldm_pdr_add_fru_record_set_check() which
instead returns a value indicating success or failure.
pldm_pdr_add_fru_record_set() will be deprecated once
pldm_pdr_add_fru_record_set_check() is stabilised.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I1e09a5663895f1e09b5e40afe5db4b4864d3496e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f944cf6..e786b5a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,7 @@
 2. fru: Introduce get_fru_record_by_option_check()
 3. pdr: Introduce pldm_entity_association_pdr_add_from_node_check()
 4. pdr: Introduce pldm_pdr_add_check()
+5. pdr: Introduce pldm_pdr_add_fru_record_set_check()
 
 ### Changed
 
diff --git a/include/libpldm/pdr.h b/include/libpldm/pdr.h
index 621974a..e929914 100644
--- a/include/libpldm/pdr.h
+++ b/include/libpldm/pdr.h
@@ -260,6 +260,29 @@
 				     uint16_t container_id,
 				     uint32_t bmc_record_handle);
 
+/** @brief Add a FRU record set PDR record to a PDR repository, or return an error
+ *
+ *  @param[in/out] repo - opaque pointer acting as a PDR repo handle
+ *  @param[in] terminus_handle - PLDM terminus handle of terminus owning the PDR
+ *  record
+ *  @param[in] fru_rsi - FRU record set identifier
+ *  @param[in] entity_type - entity type of FRU
+ *  @param[in] entity_instance_num - entity instance number of FRU
+ *  @param[in] container_id - container id of FRU
+ *  @param[in,out] bmc_record_handle - A pointer to the handle used to construct the next record. If
+ *  		   the value is zero on input then a new handle is automatically allocated.
+ *  		   Otherwise, the provided handle is used. If a new handle is automatically
+ *  		   allocated then the object pointed to by bmc_record_handle will contain its value
+ *  		   as output.
+ *  @return 0 on success, -EINVAL if the arguments are invalid, or -ENOMEM if an internal allocation
+ *  	    fails.
+ */
+int pldm_pdr_add_fru_record_set_check(pldm_pdr *repo, uint16_t terminus_handle,
+				      uint16_t fru_rsi, uint16_t entity_type,
+				      uint16_t entity_instance_num,
+				      uint16_t container_id,
+				      uint32_t *bmc_record_handle);
+
 /** @brief Find a FRU record set PDR by FRU record set identifier
  *
  *  @param[in] repo - opaque pointer acting as a PDR repo handle
diff --git a/src/pdr.c b/src/pdr.c
index 01f5002..2bafed7 100644
--- a/src/pdr.c
+++ b/src/pdr.c
@@ -293,13 +293,28 @@
 				     uint16_t container_id,
 				     uint32_t bmc_record_handle)
 {
+	int rc = pldm_pdr_add_fru_record_set_check(
+		repo, terminus_handle, fru_rsi, entity_type,
+		entity_instance_num, container_id, &bmc_record_handle);
+	(void)rc;
+	assert(!rc);
+	return bmc_record_handle;
+}
+
+LIBPLDM_ABI_TESTING
+int pldm_pdr_add_fru_record_set_check(pldm_pdr *repo, uint16_t terminus_handle,
+				      uint16_t fru_rsi, uint16_t entity_type,
+				      uint16_t entity_instance_num,
+				      uint16_t container_id,
+				      uint32_t *bmc_record_handle)
+{
 	uint32_t size = sizeof(struct pldm_pdr_hdr) +
 			sizeof(struct pldm_pdr_fru_record_set);
 	uint8_t data[size];
 
 	struct pldm_pdr_hdr *hdr = (struct pldm_pdr_hdr *)&data;
 	hdr->version = 1;
-	hdr->record_handle = bmc_record_handle;
+	hdr->record_handle = *bmc_record_handle;
 	hdr->type = PLDM_PDR_FRU_RECORD_SET;
 	hdr->record_change_num = 0;
 	hdr->length = htole16(sizeof(struct pldm_pdr_fru_record_set));
@@ -312,8 +327,8 @@
 	fru->entity_instance_num = htole16(entity_instance_num);
 	fru->container_id = htole16(container_id);
 
-	return pldm_pdr_add(repo, data, size, bmc_record_handle, false,
-			    terminus_handle);
+	return pldm_pdr_add_check(repo, data, size, false, terminus_handle,
+				  bmc_record_handle);
 }
 
 LIBPLDM_ABI_STABLE