pdr: Add pldm_pdr_find_last_in_range()

Adds a new libpldm API to find the last PDR record from the PDR repo
based on the range of record handle values given as input. This API is
used when a record needs to be added in a particular range of record
handles to the repo that contains all PDRs (inclusive of BMC and remote
endpoints).

Change-Id: Ica5187053361b27810577a4985fab4b994d35961
Signed-off-by: Pavithra Barithaya <pavithra.b@ibm.com>
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/src/pdr.c b/src/pdr.c
index 752fd57..8a63e95 100644
--- a/src/pdr.c
+++ b/src/pdr.c
@@ -966,6 +966,28 @@
 	}
 }
 
+LIBPLDM_ABI_TESTING
+pldm_pdr_record *pldm_pdr_find_last_in_range(const pldm_pdr *repo,
+					     uint32_t first, uint32_t last)
+{
+	pldm_pdr_record *record = NULL;
+	pldm_pdr_record *curr;
+
+	if (!repo) {
+		return NULL;
+	}
+	for (curr = repo->first; curr; curr = curr->next) {
+		if (first > curr->record_handle || last < curr->record_handle) {
+			continue;
+		}
+		if (!record || curr->record_handle > record->record_handle) {
+			record = curr;
+		}
+	}
+
+	return record;
+}
+
 static void entity_association_tree_find_if_remote(pldm_entity_node *node,
 						   pldm_entity *entity,
 						   pldm_entity_node **out,