pdr: Rework pldm_pdr_find_container_id_range_exclude() API
The API was returning the child container id, so renamed the API as
pldm_pdr_find_child_container_id_index_range_exclude(). The API returns
the child container id based on the index passed as an argument.
This commit addresses the comment in
https://gerrit.openbmc.org/c/openbmc/libpldm/+/63615/comment/439b3560_78f6dbbc/
Fixes: 5dc025719dc3 (“pdr: Add pldm_pdr_find_container_id_range_exclude() API”)
Change-Id: I811105d9ccc64e6f5ab28133e75ff63fdcc2c6bc
Signed-off-by: Pavithra Barithaya <pavithra.b@ibm.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fa8e9a9..6e04a27 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -33,6 +33,7 @@
### Fixes
1. pdr: Return success for pldm_pdr_find_child_container_id_range_exclude() API
+2. pdr: Rework pldm_pdr_find_container_id_range_exclude() API
## [0.3.0] - 2023-06-23
diff --git a/include/libpldm/pdr.h b/include/libpldm/pdr.h
index 27ad6f1..de5a787 100644
--- a/include/libpldm/pdr.h
+++ b/include/libpldm/pdr.h
@@ -186,19 +186,20 @@
* @param[in] repo - opaque pointer acting as a PDR repo handle
* @param[in] entity_type - entity type
* @param[in] entity_instance - instance of the entity
+ * @param[in] child_index - index of the child entity whose container id needs to be found
* @param[in] range_exclude_start_handle - first record handle in the range of the remote endpoint
- * which is ignored
+ * which is ignored
* @param[in] range_exclude_end_handle - last record handle in the range of the remote endpoint
- * which is ignored
+ * which is ignored
* @param[out] container_id - container id of the contained entity
*
- * @return container id of the PDR record found on success, -EINVAL when repo is NULL, or -ENOKEY if
- * the container id is not found.
+ * @return container id of the PDR record found on success,-EINVAL when repo is NULL
+ * or -ENOKEY if the container id is not found.
*/
-int pldm_pdr_find_container_id_range_exclude(
+int pldm_pdr_find_child_container_id_index_range_exclude(
const pldm_pdr *repo, uint16_t entity_type, uint16_t entity_instance,
- uint32_t range_exclude_start_handle, uint32_t range_exclude_end_handle,
- uint16_t *container_id);
+ uint8_t child_index, uint32_t range_exclude_start_handle,
+ uint32_t range_exclude_end_handle, uint16_t *container_id);
/* ======================= */
/* FRU Record Set PDR APIs */
diff --git a/src/pdr.c b/src/pdr.c
index 3b86f88..55350a8 100644
--- a/src/pdr.c
+++ b/src/pdr.c
@@ -374,10 +374,10 @@
}
LIBPLDM_ABI_TESTING
-int pldm_pdr_find_container_id_range_exclude(
+int pldm_pdr_find_child_container_id_index_range_exclude(
const pldm_pdr *repo, uint16_t entity_type, uint16_t entity_instance,
- uint32_t range_exclude_start_handle, uint32_t range_exclude_end_handle,
- uint16_t *container_id)
+ uint8_t child_index, uint32_t range_exclude_start_handle,
+ uint32_t range_exclude_end_handle, uint16_t *container_id)
{
pldm_pdr_record *record;
if (!repo) {
@@ -408,10 +408,11 @@
// this cast is valid with respect to alignment because
// struct pldm_pdr_hdr is declared with __attribute__((packed))
pdr = (void *)(record->data + sizeof(struct pldm_pdr_hdr));
- if (pdr->num_children == 0) {
+ if (child_index >= pdr->num_children) {
continue;
}
- child = (&pdr->children[0]);
+
+ child = (&pdr->children[child_index]);
is_container_entity_type = pdr->container.entity_type ==
entity_type;
is_container_entity_instance_number =
diff --git a/tests/libpldm_pdr_test.cpp b/tests/libpldm_pdr_test.cpp
index 174873c..869b1b7 100644
--- a/tests/libpldm_pdr_test.cpp
+++ b/tests/libpldm_pdr_test.cpp
@@ -1643,7 +1643,7 @@
}
#ifdef LIBPLDM_API_TESTING
-TEST(EntityAssociationPDR, testFindContainerID)
+TEST(EntityAssociationPDR, testFindChildContainerID)
{
pldm_entity entities[3]{};
entities[0].entity_type = 1;
@@ -1676,13 +1676,13 @@
EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u);
uint16_t container_id{};
- pldm_pdr_find_container_id_range_exclude(repo, 1, 1, 0x01000000, 0x01FFFFFF,
- &container_id);
+ pldm_pdr_find_child_container_id_index_range_exclude(
+ repo, 1, 1, 0, 0x01000000, 0x01FFFFFF, &container_id);
EXPECT_EQ(container_id, 2);
uint16_t container_id1{};
- pldm_pdr_find_container_id_range_exclude(repo, 1, 1, 0x00000001, 0x00FFFFFF,
- &container_id1);
+ pldm_pdr_find_child_container_id_index_range_exclude(
+ repo, 1, 1, 0, 0x00000001, 0x00FFFFFF, &container_id1);
EXPECT_EQ(container_id1, 0);
pldm_pdr_destroy(repo);