pdr: pldm_entity_get_num_children(): Return zero for invalid arguments

It's not possible to return a sensible value if the arguments are
invalid. Return zero as there are no children to match if a NULL node is
passed, and similarly, no matching nodes if the assocation type doesn't
meet the requirements.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ia0edf397a01a1652992a258f80e9836a57209d2d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fd00073..4741f1c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -56,6 +56,7 @@
 12. pdr: pldm_entity_association_tree_visit(): Document preconditions
 13. pdr: pldm_entity_association_tree_visit(): Exit early on failure
 14. pdr: pldm_entity_association_tree_destroy(): Exit early on bad argument
+15. pdr: pldm_entity_get_num_children(): Return zero for invalid arguments
 
 ### Deprecated
 
diff --git a/include/libpldm/pdr.h b/include/libpldm/pdr.h
index 88608aa..91b41de 100644
--- a/include/libpldm/pdr.h
+++ b/include/libpldm/pdr.h
@@ -463,7 +463,9 @@
  *  @param[in] node - opaque pointer acting as a handle to an entity node
  *  @param[in] association_type - relation type filter : logical or physical
  *
- *  @return uint8_t number of children
+ *  @return uint8_t number of children. The returned value is zero if node is NULL or
+ *  	    association_type is not one of PLDM_ENTITY_ASSOCIAION_PHYSICAL or
+ *  	    PLDM_ENTITY_ASSOCIAION_LOGICAL.
  */
 uint8_t pldm_entity_get_num_children(pldm_entity_node *node,
 				     uint8_t association_type);
diff --git a/src/pdr.c b/src/pdr.c
index 3c9db5d..7bf0f67 100644
--- a/src/pdr.c
+++ b/src/pdr.c
@@ -742,8 +742,16 @@
 				     uint8_t association_type)
 {
 	assert(node != NULL);
+	if (!node) {
+		return 0;
+	}
+
 	assert(association_type == PLDM_ENTITY_ASSOCIAION_PHYSICAL ||
 	       association_type == PLDM_ENTITY_ASSOCIAION_LOGICAL);
+	if (!(association_type == PLDM_ENTITY_ASSOCIAION_PHYSICAL ||
+	      association_type == PLDM_ENTITY_ASSOCIAION_LOGICAL)) {
+		return 0;
+	}
 
 	size_t count = 0;
 	pldm_entity_node *curr = node->first_child;