msgbuf: Externalise error value conversion
We need to simplify the code to satisfy clang's analyzer, which seems
to struggle with assumptions if the code exceeds some unknown complexity
limit.
Specifically, this does away with pldm_msgbuf_init_cc() and all the
associated pldm_msgbuf_status() error translation machinery. All the
call-sites are fixed up, with some additional safety checks put in place
along the way.
I believe this change is viable because unless we're converting legacy
API implementations to use msgbuf there's no additional trickery, and
if we're converting existing implementations then care is required
regardless. The change of approach has no impact on implementation of
new APIs with msgbuf, as the current philosophy is that they should
return negative errnos anyway.
As seems to be the case with this kind of work, the parameter register
allocation seems to have been affected for a number of library APIs.
These are listed in the changelog, and the ABI dump has been updated.
Finally, for msgbuf use in the test cases, all instances have
been converted to use errnos in place of PLDM completion codes in the
expectations. Hopefully there's no more malarky with PLDM completion
code misuse in the future.
Change-Id: Id4a7366ee9f60fb991dfe84aa0bb5aadc9855fcc
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/src/dsp/platform.c b/src/dsp/platform.c
index 4b6898e..52caa53 100644
--- a/src/dsp/platform.c
+++ b/src/dsp/platform.c
@@ -1,4 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
+#include "api.h"
+#include "compiler.h"
#include "dsp/base.h"
#include "msgbuf.h"
#include "msgbuf/platform.h"
@@ -272,10 +274,11 @@
return PLDM_ERROR_INVALID_LENGTH;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_SET_STATE_EFFECTER_STATES_MIN_SIZE,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(buf,
+ PLDM_SET_STATE_EFFECTER_STATES_MIN_SIZE,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, effecter_id);
@@ -290,7 +293,12 @@
pldm_msgbuf_extract(buf, field[i].effecter_state);
}
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -313,10 +321,10 @@
return PLDM_ERROR_INVALID_LENGTH;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_GET_PDR_REQ_BYTES, msg->payload,
- payload_length);
+ rc = pldm_msgbuf_init_errno(buf, PLDM_GET_PDR_REQ_BYTES, msg->payload,
+ payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, record_hndl);
@@ -325,7 +333,12 @@
pldm_msgbuf_extract_p(buf, request_cnt);
pldm_msgbuf_extract_p(buf, record_chg_num);
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -441,10 +454,11 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(buf,
+ PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, completion_code);
@@ -452,7 +466,11 @@
return PLDM_SUCCESS;
}
- pldm_msgbuf_extract_p(buf, repository_state);
+ rc = pldm_msgbuf_extract_p(buf, repository_state);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
if (*repository_state > PLDM_FAILED) {
return PLDM_ERROR_INVALID_DATA;
}
@@ -461,14 +479,14 @@
rc = pldm_msgbuf_extract_array(buf, PLDM_TIMESTAMP104_SIZE, update_time,
PLDM_TIMESTAMP104_SIZE);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
/* NOTE: Memory safety */
rc = pldm_msgbuf_extract_array(buf, PLDM_TIMESTAMP104_SIZE,
oem_update_time, PLDM_TIMESTAMP104_SIZE);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, record_count);
@@ -476,7 +494,12 @@
pldm_msgbuf_extract_p(buf, largest_record_size);
pldm_msgbuf_extract_p(buf, data_transfer_handle_timeout);
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_TESTING
@@ -588,13 +611,17 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_GET_PDR_MIN_RESP_BYTES, msg->payload,
- payload_length);
+ rc = pldm_msgbuf_init_errno(buf, PLDM_GET_PDR_MIN_RESP_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
- pldm_msgbuf_extract_p(buf, completion_code);
+ rc = pldm_msgbuf_extract_p(buf, completion_code);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
if (PLDM_SUCCESS != *completion_code) {
return PLDM_SUCCESS;
}
@@ -604,7 +631,7 @@
pldm_msgbuf_extract_p(buf, transfer_flag);
rc = pldm_msgbuf_extract_p(buf, resp_cnt);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (*resp_cnt > 0 && record_data != NULL) {
@@ -615,7 +642,7 @@
rc = pldm_msgbuf_extract_array(buf, *resp_cnt, record_data,
*resp_cnt);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
}
@@ -623,7 +650,12 @@
pldm_msgbuf_extract_p(buf, transfer_crc);
}
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_TESTING
@@ -695,11 +727,11 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf,
- PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(
+ buf, PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, effecter_id);
@@ -715,7 +747,12 @@
pldm_msgbuf_extract_effecter_value(buf, *effecter_data_size,
effecter_value);
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -916,16 +953,16 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf,
- PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(
+ buf, PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
rc = pldm_msgbuf_extract_p(buf, completion_code);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (PLDM_SUCCESS != *completion_code) {
@@ -934,7 +971,7 @@
rc = pldm_msgbuf_extract_p(buf, comp_sensor_count);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (*comp_sensor_count < 0x1 || *comp_sensor_count > 0x8) {
@@ -948,7 +985,12 @@
pldm_msgbuf_extract(buf, field[i].event_state);
}
- return pldm_msgbuf_destroy_consumed(buf);
+ rc = pldm_msgbuf_destroy_consumed(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -966,17 +1008,23 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(buf,
+ PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, sensor_id);
pldm_msgbuf_extract(buf, sensor_rearm->byte);
pldm_msgbuf_extract_p(buf, reserved);
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -1031,19 +1079,26 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(buf,
+ PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, format_version);
pldm_msgbuf_extract_p(buf, tid);
pldm_msgbuf_extract_p(buf, event_class);
+
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
*event_data_offset =
sizeof(*format_version) + sizeof(*tid) + sizeof(*event_class);
- return pldm_msgbuf_destroy(buf);
+ return PLDM_SUCCESS;
}
static int pldm_platform_poll_for_platform_event_message_validate(
@@ -1080,17 +1135,17 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf,
- PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(
+ buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, format_version);
rc = pldm_msgbuf_extract_p(buf, transfer_operation_flag);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (*transfer_operation_flag > PLDM_ACKNOWLEDGEMENT_ONLY) {
return PLDM_ERROR_INVALID_DATA;
@@ -1099,7 +1154,7 @@
pldm_msgbuf_extract_p(buf, data_transfer_handle);
rc = pldm_msgbuf_extract_p(buf, event_id_to_acknowledge);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
rc = pldm_platform_poll_for_platform_event_message_validate(
@@ -1108,7 +1163,12 @@
return PLDM_ERROR_INVALID_DATA;
}
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -1171,23 +1231,32 @@
return rc;
}
- rc = pldm_msgbuf_init_cc(
+ rc = pldm_msgbuf_init_errno(
buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_insert(buf, completion_code);
pldm_msgbuf_insert(buf, tid);
- pldm_msgbuf_insert(buf, event_id);
+ rc = pldm_msgbuf_insert(buf, event_id);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
if (event_id == 0xffff || event_id == 0x0000) {
if (PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES !=
payload_length) {
return PLDM_ERROR_INVALID_LENGTH;
}
- return pldm_msgbuf_destroy(buf);
+
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
if ((event_data == NULL) && (event_data_size > 0)) {
@@ -1197,13 +1266,16 @@
pldm_msgbuf_insert(buf, next_data_transfer_handle);
pldm_msgbuf_insert(buf, transfer_flag);
pldm_msgbuf_insert(buf, event_class);
- pldm_msgbuf_insert(buf, event_data_size);
+ rc = pldm_msgbuf_insert(buf, event_data_size);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
if ((event_data_size > 0) && event_data) {
rc = pldm_msgbuf_insert_array(buf, event_data_size, event_data,
event_data_size);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
}
@@ -1211,7 +1283,12 @@
pldm_msgbuf_insert(buf, checksum);
}
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -1279,15 +1356,15 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(buf, PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
rc = pldm_msgbuf_extract_p(buf, completion_code);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (PLDM_SUCCESS != *completion_code) {
@@ -1296,14 +1373,19 @@
rc = pldm_msgbuf_extract_p(buf, platform_event_status);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (*platform_event_status > PLDM_EVENT_LOGGING_REJECTED) {
return PLDM_ERROR_INVALID_DATA;
}
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -1345,15 +1427,16 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(buf,
+ PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
rc = pldm_msgbuf_extract_p(buf, completion_code);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (PLDM_SUCCESS != *completion_code) {
@@ -1362,7 +1445,12 @@
pldm_msgbuf_extract_p(buf, terminus_max_buffer_size);
- return pldm_msgbuf_destroy_consumed(buf);
+ rc = pldm_msgbuf_destroy_consumed(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -1417,16 +1505,16 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf,
- PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(buf,
+ PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
rc = pldm_msgbuf_extract_p(buf, completion_code);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (PLDM_SUCCESS != *completion_code) {
@@ -1435,7 +1523,7 @@
rc = pldm_msgbuf_extract_p(buf, synchrony_config);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (*synchrony_config > PLDM_MESSAGE_TYPE_ASYNCHRONOUS_WITH_HEARTBEAT) {
@@ -1446,11 +1534,16 @@
rc = pldm_msgbuf_extract_p(buf, number_event_class_returned);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (*number_event_class_returned == 0) {
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
if (event_class_count < *number_event_class_returned) {
@@ -1461,7 +1554,12 @@
pldm_msgbuf_extract(buf, event_class[i]);
}
- return pldm_msgbuf_destroy_consumed(buf);
+ rc = pldm_msgbuf_destroy_consumed(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -1480,10 +1578,14 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_SENSOR_EVENT_DATA_MIN_LENGTH,
- event_data, event_data_length);
+ rc = pldm_msgbuf_init_errno(buf, PLDM_SENSOR_EVENT_DATA_MIN_LENGTH,
+ event_data, event_data_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
+ }
+
+ if (event_data_length < PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES) {
+ return PLDM_ERROR_INVALID_LENGTH;
}
size_t event_class_data_length =
@@ -1492,7 +1594,7 @@
pldm_msgbuf_extract_p(buf, sensor_id);
rc = pldm_msgbuf_extract_p(buf, sensor_event_class_type);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (*sensor_event_class_type == PLDM_SENSOR_OP_STATE) {
@@ -1519,7 +1621,12 @@
*event_class_data_offset =
sizeof(*sensor_id) + sizeof(*sensor_event_class_type);
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -1535,17 +1642,22 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf,
- PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH,
- sensor_data, sensor_data_length);
+ rc = pldm_msgbuf_init_errno(
+ buf, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH, sensor_data,
+ sensor_data_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, present_op_state);
pldm_msgbuf_extract_p(buf, previous_op_state);
- return pldm_msgbuf_destroy_consumed(buf);
+ rc = pldm_msgbuf_destroy_consumed(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -1563,18 +1675,23 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(
+ rc = pldm_msgbuf_init_errno(
buf, PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH,
sensor_data, sensor_data_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, sensor_offset);
pldm_msgbuf_extract_p(buf, event_state);
pldm_msgbuf_extract_p(buf, previous_event_state);
- return pldm_msgbuf_destroy_consumed(buf);
+ rc = pldm_msgbuf_destroy_consumed(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -1599,18 +1716,18 @@
return PLDM_ERROR_INVALID_LENGTH;
}
- rc = pldm_msgbuf_init_cc(
+ rc = pldm_msgbuf_init_errno(
buf, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MIN_DATA_LENGTH,
sensor_data, sensor_data_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, event_state);
pldm_msgbuf_extract_p(buf, previous_event_state);
rc = pldm_msgbuf_extract_p(buf, sensor_data_size);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
/*
@@ -1665,7 +1782,12 @@
return PLDM_ERROR_INVALID_DATA;
}
- return pldm_msgbuf_destroy_consumed(buf);
+ rc = pldm_msgbuf_destroy_consumed(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -1677,15 +1799,15 @@
struct pldm_msgbuf *buf = &_buf;
int rc;
- rc = pldm_msgbuf_init_cc(buf, PLDM_PDR_NUMERIC_SENSOR_PDR_MIN_LENGTH,
- pdr_data, pdr_data_length);
+ rc = pldm_msgbuf_init_errno(buf, PLDM_PDR_NUMERIC_SENSOR_PDR_MIN_LENGTH,
+ pdr_data, pdr_data_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
rc = pldm_msgbuf_extract_value_pdr_hdr(buf, &pdr_value->hdr);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
rc = pldm_platform_pdr_hdr_validate(
@@ -1715,7 +1837,7 @@
rc = pldm_msgbuf_extract(buf, pdr_value->sensor_data_size);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (pdr_value->sensor_data_size > PLDM_SENSOR_DATA_SIZE_MAX) {
return PLDM_ERROR_INVALID_DATA;
@@ -1740,7 +1862,7 @@
rc = pldm_msgbuf_extract(buf, pdr_value->range_field_format);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (pdr_value->range_field_format > PLDM_RANGE_FIELD_FORMAT_MAX) {
return PLDM_ERROR_INVALID_DATA;
@@ -1766,7 +1888,12 @@
pldm_msgbuf_extract_range_field_format(
buf, pdr_value->range_field_format, pdr_value->fatal_low);
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -1890,15 +2017,21 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(buf,
+ PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, effecter_id);
- return pldm_msgbuf_destroy_consumed(buf);
+ rc = pldm_msgbuf_destroy_consumed(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -1920,16 +2053,16 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf,
- PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(
+ buf, PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
rc = pldm_msgbuf_extract_p(buf, completion_code);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (PLDM_SUCCESS != *completion_code) {
@@ -1938,7 +2071,7 @@
rc = pldm_msgbuf_extract_p(buf, effecter_data_size);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (*effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) {
@@ -1947,7 +2080,7 @@
rc = pldm_msgbuf_extract_p(buf, effecter_oper_state);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (*effecter_oper_state > EFFECTER_OPER_STATE_INTEST) {
@@ -1959,7 +2092,12 @@
pldm_msgbuf_extract_effecter_value(buf, *effecter_data_size,
present_value);
- return pldm_msgbuf_destroy_consumed(buf);
+ rc = pldm_msgbuf_destroy_consumed(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -2043,10 +2181,11 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH,
- event_data, event_data_size);
+ rc = pldm_msgbuf_init_errno(buf,
+ PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH,
+ event_data, event_data_size);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, event_data_format);
@@ -2055,7 +2194,12 @@
*change_record_data_offset =
sizeof(*event_data_format) + sizeof(*number_of_change_records);
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -2137,11 +2281,11 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf,
- PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH,
- change_record_data, change_record_data_size);
+ rc = pldm_msgbuf_init_errno(
+ buf, PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH,
+ change_record_data, change_record_data_size);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, event_data_operation);
@@ -2150,7 +2294,12 @@
*change_entry_data_offset = sizeof(*event_data_operation) +
sizeof(*number_of_change_entries);
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -2202,15 +2351,15 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_GET_SENSOR_READING_MIN_RESP_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(buf, PLDM_GET_SENSOR_READING_MIN_RESP_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
rc = pldm_msgbuf_extract_p(buf, completion_code);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (PLDM_SUCCESS != *completion_code) {
@@ -2219,7 +2368,7 @@
rc = pldm_msgbuf_extract_p(buf, sensor_data_size);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (*sensor_data_size > PLDM_SENSOR_DATA_SIZE_SINT32) {
@@ -2235,7 +2384,12 @@
pldm_msgbuf_extract_sensor_value(buf, *sensor_data_size,
present_reading);
- return pldm_msgbuf_destroy_consumed(buf);
+ rc = pldm_msgbuf_destroy_consumed(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -2322,16 +2476,21 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_GET_SENSOR_READING_REQ_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(buf, PLDM_GET_SENSOR_READING_REQ_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, sensor_id);
pldm_msgbuf_extract_p(buf, rearm_event_state);
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -2392,15 +2551,20 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_SET_EVENT_RECEIVER_RESP_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(buf, PLDM_SET_EVENT_RECEIVER_RESP_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, completion_code);
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -2422,10 +2586,10 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_SET_EVENT_RECEIVER_REQ_BYTES,
- msg->payload, payload_length);
+ rc = pldm_msgbuf_init_errno(buf, PLDM_SET_EVENT_RECEIVER_REQ_BYTES,
+ msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, event_message_global_enable);
@@ -2435,7 +2599,7 @@
rc = pldm_msgbuf_destroy(buf);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if ((*event_message_global_enable ==
@@ -2506,11 +2670,11 @@
return rc;
}
- rc = pldm_msgbuf_init_cc(
+ rc = pldm_msgbuf_init_errno(
buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_insert(buf, format_version);
@@ -2518,7 +2682,12 @@
pldm_msgbuf_insert(buf, data_transfer_handle);
pldm_msgbuf_insert(buf, event_id_to_acknowledge);
- return pldm_msgbuf_destroy(buf);
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE
@@ -2541,16 +2710,16 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(
+ rc = pldm_msgbuf_init_errno(
buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
msg->payload, payload_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
rc = pldm_msgbuf_extract_p(buf, completion_code);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (PLDM_SUCCESS != *completion_code) {
return *completion_code;
@@ -2559,7 +2728,7 @@
pldm_msgbuf_extract_p(buf, tid);
rc = pldm_msgbuf_extract_p(buf, event_id);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if ((*event_id == 0) || (*event_id == 0xffff)) {
return PLDM_SUCCESS;
@@ -2568,13 +2737,13 @@
pldm_msgbuf_extract_p(buf, next_data_transfer_handle);
rc = pldm_msgbuf_extract_p(buf, transfer_flag);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
pldm_msgbuf_extract_p(buf, event_class);
rc = pldm_msgbuf_extract_p(buf, event_data_size);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (*event_data_size > payload_length) {
return PLDM_ERROR_INVALID_DATA;
@@ -2589,7 +2758,12 @@
pldm_msgbuf_extract_p(buf, event_data_integrity_checksum);
}
- return pldm_msgbuf_destroy_consumed(buf);
+ rc = pldm_msgbuf_destroy_consumed(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_TESTING
@@ -2606,15 +2780,16 @@
return PLDM_ERROR_INVALID_DATA;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_PDR_NUMERIC_EFFECTER_PDR_MIN_LENGTH,
- pdr_data, pdr_data_length);
+ rc = pldm_msgbuf_init_errno(buf,
+ PLDM_PDR_NUMERIC_EFFECTER_PDR_MIN_LENGTH,
+ pdr_data, pdr_data_length);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
rc = pldm_msgbuf_extract_value_pdr_hdr(buf, &hdr);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
rc = pldm_platform_pdr_hdr_validate(
@@ -2646,7 +2821,7 @@
rc = pldm_msgbuf_extract(buf, pdr_value->effecter_data_size);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (pdr_value->effecter_data_size > PLDM_SENSOR_DATA_SIZE_MAX) {
return PLDM_ERROR_INVALID_DATA;
@@ -2666,7 +2841,7 @@
rc = pldm_msgbuf_extract(buf, pdr_value->range_field_format);
if (rc) {
- return rc;
+ return pldm_xlate_errno(rc);
}
if (pdr_value->range_field_format > PLDM_RANGE_FIELD_FORMAT_MAX) {
return PLDM_ERROR_INVALID_DATA;
@@ -2684,7 +2859,12 @@
pldm_msgbuf_extract_range_field_format(
buf, pdr_value->range_field_format, pdr_value->rated_min);
- return pldm_msgbuf_destroy_consumed(buf);
+ rc = pldm_msgbuf_destroy_consumed(buf);
+ if (rc) {
+ return pldm_xlate_errno(rc);
+ }
+
+ return PLDM_SUCCESS;
}
LIBPLDM_ABI_STABLE