bios_table: Deprecate pldm_bios_table_attr_value_entry_encode_string()
Users should prefer
pldm_bios_table_attr_value_entry_encode_string_check() which returns an
error code rather than preventing misbehaviour via assert().
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Id1aea49a07ac52858c1a5977e4f96b987f705064
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 347cbc2..4d34dcd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -33,6 +33,10 @@
Migrate to pldm_bios_table_attr_value_entry_encode_enum_check()
+3. bios_table: Deprecate pldm_bios_table_attr_value_entry_encode_string()
+
+ Migrate to pldm_bios_table_attr_value_entry_encode_string_check()
+
### Removed
1. bios_table: Remove deprecated APIs sanitized by assert():
diff --git a/include/libpldm/bios_table.h b/include/libpldm/bios_table.h
index bf4bd46..f69fa71 100644
--- a/include/libpldm/bios_table.h
+++ b/include/libpldm/bios_table.h
@@ -564,7 +564,9 @@
* @param[in] string_length - Length of current string in bytes. 0 indicates
* that the current string value is not set.
* @param[in] string - The current string itsel
- * @return pldm_completion_codes
+ * @return PLDM_SUCCESS on success. PLDM_ERROR_INVALID_DATA if entry is NULL, str is NULL while
+ * str_length is non-zero, or attr_type is not PLDM_BIOS_STRING. PLDM_ERROR_INVALID_LENGTH
+ * if entry_length lacks capacity to encode str into entry.
*/
int pldm_bios_table_attr_value_entry_encode_string_check(
void *entry, size_t entry_length, uint16_t attr_handle,
diff --git a/src/bios_table.c b/src/bios_table.c
index 5b19b1a..c6a2d1f 100644
--- a/src/bios_table.c
+++ b/src/bios_table.c
@@ -718,24 +718,15 @@
sizeof(string_length) + string_length;
}
-LIBPLDM_ABI_STABLE
+LIBPLDM_ABI_DEPRECATED
void pldm_bios_table_attr_value_entry_encode_string(
void *entry, size_t entry_length, uint16_t attr_handle,
uint8_t attr_type, uint16_t str_length, const char *str)
{
- size_t length = pldm_bios_table_attr_value_entry_encode_string_length(
- str_length);
- assert(length <= entry_length);
-
- struct pldm_bios_attr_val_table_entry *table_entry = entry;
- table_entry->attr_handle = htole16(attr_handle);
- table_entry->attr_type = attr_type;
- if (str_length != 0) {
- memcpy(table_entry->value + sizeof(str_length), str,
- str_length);
- }
- str_length = htole16(str_length);
- memcpy(table_entry->value, &str_length, sizeof(str_length));
+ int rc = pldm_bios_table_attr_value_entry_encode_string_check(
+ entry, entry_length, attr_handle, attr_type, str_length, str);
+ (void)rc;
+ assert(rc == PLDM_SUCCESS);
}
LIBPLDM_ABI_STABLE
@@ -771,8 +762,15 @@
size_t length = pldm_bios_table_attr_value_entry_encode_string_length(
str_length);
BUFFER_SIZE_EXPECT(entry_length, length);
- pldm_bios_table_attr_value_entry_encode_string(
- entry, entry_length, attr_handle, attr_type, str_length, str);
+ struct pldm_bios_attr_val_table_entry *table_entry = entry;
+ table_entry->attr_handle = htole16(attr_handle);
+ table_entry->attr_type = attr_type;
+ if (str_length != 0) {
+ memcpy(table_entry->value + sizeof(str_length), str,
+ str_length);
+ }
+ str_length = htole16(str_length);
+ memcpy(table_entry->value, &str_length, sizeof(str_length));
return PLDM_SUCCESS;
}
diff --git a/tests/libpldm_bios_table_test.cpp b/tests/libpldm_bios_table_test.cpp
index 6bf60a7..a7f5677 100644
--- a/tests/libpldm_bios_table_test.cpp
+++ b/tests/libpldm_bios_table_test.cpp
@@ -657,7 +657,7 @@
EXPECT_DEATH(
pldm_bios_table_attr_value_entry_encode_string(
encodeEntry.data(), encodeEntry.size() - 1, 0, 1, 3, "abc"),
- "length <= entry_length");
+ "rc == PLDM_SUCCESS");
auto rc = pldm_bios_table_attr_value_entry_encode_string_check(
encodeEntry.data(), encodeEntry.size(), 0, PLDM_BIOS_STRING, 3, "abc");