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;
 	}
 
diff --git a/oem/ibm/libpldm/host.c b/oem/ibm/libpldm/host.c
index 454f6c3..caaaf9e 100644
--- a/oem/ibm/libpldm/host.c
+++ b/oem/ibm/libpldm/host.c
@@ -6,22 +6,24 @@
 int encode_get_alert_status_req(uint8_t instance_id, uint8_t version_id,
 				struct pldm_msg *msg, size_t payload_length)
 {
-	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_HOST_GET_ALERT_STATUS;
-
-	if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
-		return rc;
+	if (msg == NULL) {
+		return PLDM_ERROR_INVALID_LENGTH;
 	}
 
 	if (payload_length != PLDM_GET_ALERT_STATUS_REQ_BYTES) {
 		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_HOST_GET_ALERT_STATUS;
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
+
 	msg->payload[0] = version_id;
 
 	return PLDM_SUCCESS;
@@ -75,22 +77,24 @@
 				 uint32_t rack_entry, uint32_t pri_cec_node,
 				 struct pldm_msg *msg, size_t payload_length)
 {
-	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_HOST_GET_ALERT_STATUS;
-
-	if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
-		return rc;
+	if (msg == NULL) {
+		return PLDM_ERROR_INVALID_LENGTH;
 	}
 
 	if (payload_length != PLDM_GET_ALERT_STATUS_RESP_BYTES) {
 		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_HOST_GET_ALERT_STATUS;
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
+
 	struct pldm_get_alert_status_resp *response =
 	    (struct pldm_get_alert_status_resp *)msg->payload;
 
diff --git a/oem/ibm/libpldm/platform_oem_ibm.c b/oem/ibm/libpldm/platform_oem_ibm.c
index 1cf7e86..7090f95 100644
--- a/oem/ibm/libpldm/platform_oem_ibm.c
+++ b/oem/ibm/libpldm/platform_oem_ibm.c
@@ -9,14 +9,6 @@
 					   size_t payload_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_PLATFORM;

-	header.command = PLDM_PLATFORM_EVENT_MESSAGE;

-

 	if (format_version != 1) {

 		return PLDM_ERROR_INVALID_DATA;

 	}

@@ -35,7 +27,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_PLATFORM;

+	header.command = PLDM_PLATFORM_EVENT_MESSAGE;

+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));

+	if (rc != PLDM_SUCCESS) {

 		return rc;

 	}