Fix the return value of pack_pldm_header and unpack_pldm_header
- The intent behind this commit is to fix the return value of the
pack_pldm_header and the unpack_pldm_header methods.
- According to PLDM spec, their return value should be `uint8_t`, not
`int`, so 0 is PLDM_SUCCESS and non-0 is failure.
- Also, when we call the pack_pldm_header and unpack_pldm_header
methods, we need to verify the return value of the method.
Tested: Built pldm successfully and Unit Test passes.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I0bd6838c4fb3b90f821c10324e4536ed352ffcfa
diff --git a/oem/ibm/libpldm/file_io.c b/oem/ibm/libpldm/file_io.c
index 788f480..262af47 100644
--- a/oem/ibm/libpldm/file_io.c
+++ b/oem/ibm/libpldm/file_io.c
@@ -30,15 +30,17 @@
uint8_t completion_code, uint32_t length,
struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+ struct pldm_header_info header = {0};
header.msg_type = PLDM_RESPONSE;
header.instance = instance_id;
header.pldm_type = PLDM_OEM;
header.command = command;
-
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}
@@ -57,18 +59,17 @@
uint32_t length, uint64_t address,
struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
+ struct pldm_header_info header = {0};
header.msg_type = PLDM_REQUEST;
header.instance = instance_id;
header.pldm_type = PLDM_OEM;
header.command = command;
-
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}
@@ -131,15 +132,17 @@
uint8_t transfer_flag, const uint8_t *table_data,
size_t table_size, struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+ struct pldm_header_info header = {0};
header.msg_type = PLDM_RESPONSE;
header.instance = instance_id;
header.pldm_type = PLDM_OEM;
header.command = PLDM_GET_FILE_TABLE;
-
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}
@@ -160,19 +163,17 @@
uint8_t transfer_opflag, uint8_t table_type,
struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
-
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
+ struct pldm_header_info header = {0};
header.msg_type = PLDM_REQUEST;
header.instance = instance_id;
header.pldm_type = PLDM_OEM;
header.command = PLDM_GET_FILE_TABLE;
-
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}
@@ -248,14 +249,6 @@
int encode_read_file_req(uint8_t instance_id, uint32_t file_handle,
uint32_t offset, uint32_t length, struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
-
- header.msg_type = PLDM_REQUEST;
- header.instance = instance_id;
- header.pldm_type = PLDM_OEM;
- header.command = PLDM_READ_FILE;
-
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
@@ -264,7 +257,13 @@
return PLDM_ERROR_INVALID_LENGTH;
}
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ struct pldm_header_info header = {0};
+ header.msg_type = PLDM_REQUEST;
+ header.instance = instance_id;
+ header.pldm_type = PLDM_OEM;
+ header.command = PLDM_READ_FILE;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}
@@ -308,19 +307,17 @@
int encode_read_file_resp(uint8_t instance_id, uint8_t completion_code,
uint32_t length, struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
-
- header.msg_type = PLDM_RESPONSE;
- header.instance = instance_id;
- header.pldm_type = PLDM_OEM;
- header.command = PLDM_READ_FILE;
-
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ struct pldm_header_info header = {0};
+ header.msg_type = PLDM_RESPONSE;
+ header.instance = instance_id;
+ header.pldm_type = PLDM_OEM;
+ header.command = PLDM_READ_FILE;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}
@@ -366,26 +363,24 @@
uint32_t offset, uint32_t length,
struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
-
- header.msg_type = PLDM_REQUEST;
- header.instance = instance_id;
- header.pldm_type = PLDM_OEM;
- header.command = PLDM_WRITE_FILE;
-
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
- return rc;
- }
-
if (length == 0) {
return PLDM_ERROR_INVALID_LENGTH;
}
+ struct pldm_header_info header = {0};
+ header.msg_type = PLDM_REQUEST;
+ header.instance = instance_id;
+ header.pldm_type = PLDM_OEM;
+ header.command = PLDM_WRITE_FILE;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
+ return rc;
+ }
+
struct pldm_write_file_req *request =
(struct pldm_write_file_req *)msg->payload;
@@ -421,19 +416,17 @@
int encode_write_file_resp(uint8_t instance_id, uint8_t completion_code,
uint32_t length, struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
-
- header.msg_type = PLDM_RESPONSE;
- header.instance = instance_id;
- header.pldm_type = PLDM_OEM;
- header.command = PLDM_WRITE_FILE;
-
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ struct pldm_header_info header = {0};
+ header.msg_type = PLDM_RESPONSE;
+ header.instance = instance_id;
+ header.pldm_type = PLDM_OEM;
+ header.command = PLDM_WRITE_FILE;
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}
@@ -478,19 +471,17 @@
uint8_t completion_code, uint32_t length,
struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
-
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
+ struct pldm_header_info header = {0};
header.msg_type = PLDM_RESPONSE;
header.instance = instance_id;
header.pldm_type = PLDM_OEM;
header.command = command;
-
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}
@@ -509,19 +500,17 @@
uint32_t offset, uint32_t length,
uint64_t address, struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
-
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
+ struct pldm_header_info header = {0};
header.msg_type = PLDM_REQUEST;
header.instance = instance_id;
header.pldm_type = PLDM_OEM;
header.command = command;
-
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}
@@ -584,19 +573,17 @@
int encode_new_file_resp(uint8_t instance_id, uint8_t completion_code,
struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
-
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
+ struct pldm_header_info header = {0};
header.msg_type = PLDM_RESPONSE;
header.instance = instance_id;
header.pldm_type = PLDM_OEM;
header.command = PLDM_NEW_FILE_AVAILABLE;
-
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}
@@ -611,19 +598,17 @@
uint32_t file_handle, uint64_t length,
struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
-
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
+ struct pldm_header_info header = {0};
header.msg_type = PLDM_REQUEST;
header.instance = instance_id;
header.pldm_type = PLDM_OEM;
header.command = PLDM_NEW_FILE_AVAILABLE;
-
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}
@@ -682,9 +667,6 @@
uint8_t completion_code, uint32_t length,
struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
-
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
@@ -693,12 +675,13 @@
return PLDM_ERROR_INVALID_DATA;
}
+ struct pldm_header_info header = {0};
header.msg_type = PLDM_RESPONSE;
header.instance = instance_id;
header.pldm_type = PLDM_OEM;
header.command = command;
-
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}
@@ -717,9 +700,6 @@
uint32_t offset, uint32_t length,
struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
-
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
@@ -728,12 +708,13 @@
return PLDM_ERROR_INVALID_DATA;
}
+ struct pldm_header_info header = {0};
header.msg_type = PLDM_REQUEST;
header.instance = instance_id;
header.pldm_type = PLDM_OEM;
header.command = command;
-
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}
@@ -793,19 +774,17 @@
int encode_file_ack_resp(uint8_t instance_id, uint8_t completion_code,
struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
-
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
+ struct pldm_header_info header = {0};
header.msg_type = PLDM_RESPONSE;
header.instance = instance_id;
header.pldm_type = PLDM_OEM;
header.command = PLDM_FILE_ACK;
-
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}
@@ -820,19 +799,17 @@
uint32_t file_handle, uint8_t file_status,
struct pldm_msg *msg)
{
- struct pldm_header_info header = {0};
- int rc = PLDM_SUCCESS;
-
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
+ struct pldm_header_info header = {0};
header.msg_type = PLDM_REQUEST;
header.instance = instance_id;
header.pldm_type = PLDM_OEM;
header.command = PLDM_FILE_ACK;
-
- if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+ if (rc != PLDM_SUCCESS) {
return rc;
}