pldmd: Migrate to pldm_pdr_add_check()
pldm_pdr_add() is deprecated in libpldm as it uses assert() to
communicate to the caller that an error occurred. pldm_pdr_add_check()
instead returns a value that indicates success or failure.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Icca92fd742f07fb935202a9d9e62f5648916b12b
diff --git a/common/test/pldm_utils_test.cpp b/common/test/pldm_utils_test.cpp
index fed65d1..549e289 100644
--- a/common/test/pldm_utils_test.cpp
+++ b/common/test/pldm_utils_test.cpp
@@ -104,7 +104,9 @@
state->state_set_id = 196;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
@@ -137,7 +139,9 @@
state->state_set_id = 196;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
@@ -186,7 +190,9 @@
state->state_set_id = 129;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
std::vector<uint8_t> pdr_second(
sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
@@ -206,7 +212,10 @@
state_second->state_set_id = 129;
state_second->possible_states_size = 1;
- pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), 0, false, 1);
+ handle = 0;
+ ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(),
+ false, 1, &handle),
+ 0);
uint16_t entityID_ = 31;
uint16_t stateSetId_ = 129;
@@ -243,7 +252,9 @@
state->state_set_id = 198;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
std::vector<uint8_t> pdr_second(
sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
@@ -263,7 +274,10 @@
state_second->state_set_id = 169;
state_second->possible_states_size = 1;
- pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), 0, false, 1);
+ handle = 0;
+ ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(),
+ false, 1, &handle),
+ 0);
auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
@@ -296,7 +310,9 @@
state->state_set_id = 198;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
std::vector<uint8_t> pdr_second(
sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
@@ -316,7 +332,10 @@
state_second->state_set_id = 192;
state_second->possible_states_size = 1;
- pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), 0, false, 1);
+ handle = 0;
+ ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(),
+ false, 1, &handle),
+ 0);
auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
@@ -350,7 +369,9 @@
state->state_set_id = 198;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
std::vector<uint8_t> pdr_second(
sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
@@ -370,7 +391,10 @@
state_second->state_set_id = 192;
state_second->possible_states_size = 1;
- pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), 0, false, 1);
+ handle = 0;
+ ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(),
+ false, 1, &handle),
+ 0);
std::vector<uint8_t> pdr_third(
sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
@@ -434,7 +458,9 @@
state->state_set_id = 192;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
@@ -479,7 +505,9 @@
state->state_set_id = 123;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
@@ -512,7 +540,9 @@
state->state_set_id = 1;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
auto record = findStateSensorPDR(tid, entityID, stateSetId, repo);
@@ -545,7 +575,9 @@
state->state_set_id = 1;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
auto record = findStateSensorPDR(tid, entityID, stateSetId, repo);
@@ -594,7 +626,9 @@
state->state_set_id = 1;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
std::vector<uint8_t> pdr_second(
sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
@@ -614,7 +648,10 @@
state_second->state_set_id = 1;
state_second->possible_states_size = 1;
- pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), 0, false, 1);
+ handle = 0;
+ ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(),
+ false, 1, &handle),
+ 0);
uint16_t entityID_ = 5;
uint16_t stateSetId_ = 1;
@@ -651,7 +688,9 @@
state->state_set_id = 2;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
std::vector<uint8_t> pdr_second(
sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
@@ -671,7 +710,10 @@
state_second->state_set_id = 3;
state_second->possible_states_size = 1;
- pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), 0, false, 1);
+ handle = 0;
+ ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(),
+ false, 1, &handle),
+ 0);
auto record = findStateSensorPDR(tid, entityID, stateSetId, repo);
@@ -704,7 +746,9 @@
state->state_set_id = 20;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
std::vector<uint8_t> pdr_second(
sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
@@ -724,7 +768,10 @@
state_second->state_set_id = 1;
state_second->possible_states_size = 1;
- pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), 0, false, 1);
+ handle = 0;
+ ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(),
+ false, 1, &handle),
+ 0);
auto record = findStateSensorPDR(tid, entityID, stateSetId, repo);
@@ -758,7 +805,9 @@
state->state_set_id = 9;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
std::vector<uint8_t> pdr_second(
sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
@@ -778,7 +827,10 @@
state_second->state_set_id = 1;
state_second->possible_states_size = 1;
- pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), 0, false, 1);
+ handle = 0;
+ ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(),
+ false, 1, &handle),
+ 0);
std::vector<uint8_t> pdr_third(sizeof(struct pldm_state_sensor_pdr) -
sizeof(uint8_t) +
@@ -843,7 +895,9 @@
state->state_set_id = 1;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
auto record = findStateSensorPDR(tid, entityID, stateSetId, repo);
@@ -888,7 +942,9 @@
state->state_set_id = 39;
state->possible_states_size = 1;
- pldm_pdr_add(repo, pdr.data(), pdr.size(), 0, false, 1);
+ uint32_t handle = 0;
+ ASSERT_EQ(
+ pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
auto record = findStateSensorPDR(tid, entityID, stateSetId, repo);
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index 1913f0b..89c170e 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -531,8 +531,13 @@
}
else
{
- pldm_pdr_add(repo, pdr.data(), respCount, rh, true,
- pdrTerminusHandle);
+ rc = pldm_pdr_add_check(repo, pdr.data(), respCount, true,
+ pdrTerminusHandle, &rh);
+ if (rc)
+ {
+ // pldm_pdr_add() assert()ed on failure to add a PDR.
+ throw std::runtime_error("Failed to add PDR");
+ }
}
}
}
diff --git a/libpldmresponder/pdr_utils.cpp b/libpldmresponder/pdr_utils.cpp
index dc6294e..7e5e491 100644
--- a/libpldmresponder/pdr_utils.cpp
+++ b/libpldmresponder/pdr_utils.cpp
@@ -23,8 +23,15 @@
RecordHandle Repo::addRecord(const PdrEntry& pdrEntry)
{
- return pldm_pdr_add(repo, pdrEntry.data, pdrEntry.size,
- pdrEntry.handle.recordHandle, false, TERMINUS_HANDLE);
+ uint32_t handle = pdrEntry.handle.recordHandle;
+ int rc = pldm_pdr_add_check(repo, pdrEntry.data, pdrEntry.size, false,
+ TERMINUS_HANDLE, &handle);
+ if (rc)
+ {
+ // pldm_pdr_add() assert()ed on failure to add PDR
+ throw std::runtime_error("Failed to add PDR");
+ }
+ return handle;
}
const pldm_pdr_record* Repo::getFirstRecord(PdrEntry& pdrEntry)