bios_table: pldm_bios_table_iter_create(): Return NULL on failed alloc

Given we're already returning the pointer, take the opportunity to
return a NULL pointer if the allocation fails. This provides a signal to
the caller that an error has occurred and allows us to escape from
relying on assert() as the signal.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I58a82a240e64f981c28ad69e317ac8e3d1e41d40
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e5652cb..86905bf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@
 1. requester: Mark pldm_close() as LIBPLDM_ABI_TESTING
 2. requester: Expose pldm_close() in header
 3. bios_table: pldm_bios_table_string_entry_encode_check(): Handle overflow
+4. bios_table: pldm_bios_table_iter_create(): Return NULL on failed alloc
 
 ### Deprecated
 
diff --git a/include/libpldm/bios_table.h b/include/libpldm/bios_table.h
index db3aeef..0424b49 100644
--- a/include/libpldm/bios_table.h
+++ b/include/libpldm/bios_table.h
@@ -20,7 +20,7 @@
  *  @param[in] table - Pointer to table data
  *  @param[in] length - Length of table data
  *  @param[in] type - Type of pldm bios table
- *  @return Iterator to the beginning
+ *  @return Iterator to the beginning on success. Returns NULL on failure.
  */
 struct pldm_bios_table_iter *
 pldm_bios_table_iter_create(const void *table, size_t length,
diff --git a/src/bios_table.c b/src/bios_table.c
index 2605e40..910a499 100644
--- a/src/bios_table.c
+++ b/src/bios_table.c
@@ -961,6 +961,9 @@
 {
 	struct pldm_bios_table_iter *iter = malloc(sizeof(*iter));
 	assert(iter != NULL);
+	if (!iter) {
+		return NULL;
+	}
 	iter->table_data = table;
 	iter->table_len = length;
 	iter->current_pos = 0;