pdr: pldm_entity_association_tree_visit(): Exit early on failure

Failure may take the form of invalid parameters or an allocation
failure. Avoid NULL dereferences where possible.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Iebef851345fb61ab678cfd0e1c763162780c8091
diff --git a/CHANGELOG.md b/CHANGELOG.md
index de92471..93415da 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -54,6 +54,7 @@
 10. pdr: pldm_pdr_fru_record_set_find_by_rsi(): Exit early on NULL arguments
 11. pdr: pldm_entity_association_tree_init(): Return NULL on failed alloc
 12. pdr: pldm_entity_association_tree_visit(): Document preconditions
+13. pdr: pldm_entity_association_tree_visit(): Exit early on failure
 
 ### Deprecated
 
diff --git a/src/pdr.c b/src/pdr.c
index be8b2fe..285aae6 100644
--- a/src/pdr.c
+++ b/src/pdr.c
@@ -667,6 +667,9 @@
 					pldm_entity **entities, size_t *size)
 {
 	assert(tree != NULL);
+	if (!tree || !entities || !size) {
+		return;
+	}
 
 	*size = 0;
 	if (tree->root == NULL) {
@@ -675,6 +678,9 @@
 
 	get_num_nodes(tree->root, size);
 	*entities = malloc(*size * sizeof(pldm_entity));
+	if (!entities) {
+		return;
+	}
 	size_t index = 0;
 	entity_association_tree_visit(tree->root, *entities, &index);
 }