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/libpldm/base.c b/libpldm/base.c
index c8369f8..83cd22a 100644
--- a/libpldm/base.c
+++ b/libpldm/base.c
@@ -3,8 +3,8 @@
 
 #include "base.h"
 
-int pack_pldm_header(const struct pldm_header_info *hdr,
-		     struct pldm_msg_hdr *msg)
+uint8_t pack_pldm_header(const struct pldm_header_info *hdr,
+			 struct pldm_msg_hdr *msg)
 {
 	if (msg == NULL || hdr == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
@@ -41,8 +41,8 @@
 	return PLDM_SUCCESS;
 }
 
-int unpack_pldm_header(const struct pldm_msg_hdr *msg,
-		       struct pldm_header_info *hdr)
+uint8_t unpack_pldm_header(const struct pldm_msg_hdr *msg,
+			   struct pldm_header_info *hdr)
 {
 	if (msg == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
@@ -72,9 +72,8 @@
 	header.instance = instance_id;
 	header.msg_type = PLDM_REQUEST;
 	header.command = PLDM_GET_PLDM_TYPES;
-	pack_pldm_header(&header, &(msg->hdr));
 
-	return PLDM_SUCCESS;
+	return pack_pldm_header(&header, &(msg->hdr));
 }
 
 int encode_get_commands_req(uint8_t instance_id, uint8_t type, ver32_t version,
@@ -88,7 +87,11 @@
 	header.instance = instance_id;
 	header.msg_type = PLDM_REQUEST;
 	header.command = PLDM_GET_PLDM_COMMANDS;
-	pack_pldm_header(&header, &(msg->hdr));
+
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
 
 	struct pldm_get_commands_req *request =
 	    (struct pldm_get_commands_req *)msg->payload;
@@ -106,16 +109,19 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	struct pldm_get_types_resp *response =
-	    (struct pldm_get_types_resp *)msg->payload;
-
-	response->completion_code = completion_code;
 	struct pldm_header_info header = {0};
 	header.instance = instance_id;
 	header.msg_type = PLDM_RESPONSE;
 	header.command = PLDM_GET_PLDM_TYPES;
-	pack_pldm_header(&header, &(msg->hdr));
 
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
+
+	struct pldm_get_types_resp *response =
+	    (struct pldm_get_types_resp *)msg->payload;
+	response->completion_code = completion_code;
 	if (response->completion_code == PLDM_SUCCESS) {
 		if (types == NULL) {
 			return PLDM_ERROR_INVALID_DATA;
@@ -151,16 +157,18 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	struct pldm_get_commands_resp *response =
-	    (struct pldm_get_commands_resp *)msg->payload;
-	response->completion_code = completion_code;
-
 	struct pldm_header_info header = {0};
 	header.instance = instance_id;
 	header.msg_type = PLDM_RESPONSE;
 	header.command = PLDM_GET_PLDM_COMMANDS;
-	pack_pldm_header(&header, &(msg->hdr));
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
 
+	struct pldm_get_commands_resp *response =
+	    (struct pldm_get_commands_resp *)msg->payload;
+	response->completion_code = completion_code;
 	if (response->completion_code == PLDM_SUCCESS) {
 		if (commands == NULL) {
 			return PLDM_ERROR_INVALID_DATA;
@@ -225,19 +233,18 @@
 			   uint8_t transfer_opflag, uint8_t type,
 			   struct pldm_msg *msg)
 {
-	struct pldm_header_info header = {0};
-	int rc = PLDM_SUCCESS;
-
 	if (NULL == msg) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
+	struct pldm_header_info header = {0};
 	header.msg_type = PLDM_REQUEST;
 	header.instance = instance_id;
 	header.pldm_type = PLDM_BASE;
 	header.command = PLDM_GET_PLDM_VERSION;
 
-	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;
 	}
 
@@ -256,22 +263,25 @@
 			    uint8_t transfer_flag, const ver32_t *version_data,
 			    size_t version_size, struct pldm_msg *msg)
 {
+	if (NULL == msg) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
 	struct pldm_header_info header = {0};
-	int rc = PLDM_SUCCESS;
+	header.msg_type = PLDM_RESPONSE;
+	header.instance = instance_id;
+	header.pldm_type = PLDM_BASE;
+	header.command = PLDM_GET_PLDM_VERSION;
+
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
+
 	struct pldm_get_version_resp *response =
 	    (struct pldm_get_version_resp *)msg->payload;
 	response->completion_code = completion_code;
 	if (response->completion_code == PLDM_SUCCESS) {
-
-		header.msg_type = PLDM_RESPONSE;
-		header.instance = instance_id;
-		header.pldm_type = PLDM_BASE;
-		header.command = PLDM_GET_PLDM_VERSION;
-
-		if ((rc = pack_pldm_header(&header, &(msg->hdr))) >
-		    PLDM_SUCCESS) {
-			return rc;
-		}
 		response->next_transfer_handle = htole32(next_transfer_handle);
 		response->transfer_flag = transfer_flag;
 		memcpy(response->version_data, (uint8_t *)version_data,
@@ -336,9 +346,8 @@
 	header.instance = instance_id;
 	header.msg_type = PLDM_REQUEST;
 	header.command = PLDM_GET_TID;
-	pack_pldm_header(&header, &(msg->hdr));
 
-	return PLDM_SUCCESS;
+	return pack_pldm_header(&header, &(msg->hdr));
 }
 int encode_get_tid_resp(uint8_t instance_id, uint8_t completion_code,
 			uint8_t tid, struct pldm_msg *msg)
@@ -347,16 +356,19 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	struct pldm_get_tid_resp *response =
-	    (struct pldm_get_tid_resp *)msg->payload;
-
-	response->completion_code = completion_code;
 	struct pldm_header_info header = {0};
 	header.instance = instance_id;
 	header.msg_type = PLDM_RESPONSE;
 	header.command = PLDM_GET_TID;
-	pack_pldm_header(&header, &(msg->hdr));
 
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
+
+	struct pldm_get_tid_resp *response =
+	    (struct pldm_get_tid_resp *)msg->payload;
+	response->completion_code = completion_code;
 	response->tid = tid;
 
 	return PLDM_SUCCESS;
@@ -389,17 +401,17 @@
 int encode_cc_only_resp(uint8_t instance_id, uint8_t type, uint8_t command,
 			uint8_t cc, struct pldm_msg *msg)
 {
-	struct pldm_header_info header = {0};
-
 	if (msg == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
+	struct pldm_header_info header = {0};
 	header.instance = instance_id;
 	header.msg_type = PLDM_RESPONSE;
 	header.pldm_type = type;
 	header.command = command;
-	int rc = pack_pldm_header(&header, &msg->hdr);
+
+	uint8_t rc = pack_pldm_header(&header, &msg->hdr);
 	if (rc != PLDM_SUCCESS) {
 		return rc;
 	}
@@ -413,13 +425,14 @@
 			    uint8_t pldm_type, uint8_t command,
 			    struct pldm_msg *msg)
 {
-	struct pldm_header_info header = {0};
 	if (msg == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
+
+	struct pldm_header_info header = {0};
 	header.msg_type = msg_type;
 	header.instance = instance_id;
 	header.pldm_type = pldm_type;
 	header.command = command;
-	return (pack_pldm_header(&header, &(msg->hdr)));
+	return pack_pldm_header(&header, &(msg->hdr));
 }
diff --git a/libpldm/base.h b/libpldm/base.h
index 36b9d8f..451137d 100644
--- a/libpldm/base.h
+++ b/libpldm/base.h
@@ -223,8 +223,8 @@
  * @note   Caller is responsible for alloc and dealloc of msg
  *         and hdr params
  */
-int pack_pldm_header(const struct pldm_header_info *hdr,
-		     struct pldm_msg_hdr *msg);
+uint8_t pack_pldm_header(const struct pldm_header_info *hdr,
+			 struct pldm_msg_hdr *msg);
 
 /**
  * @brief Unpack the PLDM header from the PLDM message.
@@ -236,8 +236,8 @@
  * @note   Caller is responsible for alloc and dealloc of msg
  *         and hdr params
  */
-int unpack_pldm_header(const struct pldm_msg_hdr *msg,
-		       struct pldm_header_info *hdr);
+uint8_t unpack_pldm_header(const struct pldm_msg_hdr *msg,
+			   struct pldm_header_info *hdr);
 
 /* Requester */
 
diff --git a/libpldm/bios.c b/libpldm/bios.c
index 6dbc0b0..8d93a6a 100644
--- a/libpldm/bios.c
+++ b/libpldm/bios.c
@@ -6,12 +6,11 @@
 
 int encode_get_date_time_req(uint8_t instance_id, struct pldm_msg *msg)
 {
-	struct pldm_header_info header = {0};
-
 	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_BIOS;
@@ -24,25 +23,23 @@
 			      uint8_t day, uint8_t month, uint16_t year,
 			      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_BIOS;
 	header.command = PLDM_GET_DATE_TIME;
 
-	struct pldm_get_date_time_resp *response =
-	    (struct pldm_get_date_time_resp *)msg->payload;
-
-	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;
 	}
 
+	struct pldm_get_date_time_resp *response =
+	    (struct pldm_get_date_time_resp *)msg->payload;
 	response->completion_code = completion_code;
 	if (response->completion_code == PLDM_SUCCESS) {
 		response->completion_code = completion_code;
@@ -94,8 +91,6 @@
 			     uint8_t month, uint16_t year, struct pldm_msg *msg,
 			     size_t payload_length)
 {
-	struct pldm_header_info header = {0};
-
 	if (msg == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
@@ -106,11 +101,17 @@
 	if (!is_time_legal(seconds, minutes, hours, day, month, year)) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
+
+	struct pldm_header_info header = {0};
 	header.instance = instance_id;
 	header.msg_type = PLDM_REQUEST;
 	header.pldm_type = PLDM_BIOS;
 	header.command = PLDM_SET_DATE_TIME;
-	pack_pldm_header(&header, &msg->hdr);
+
+	uint8_t rc = pack_pldm_header(&header, &msg->hdr);
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
 
 	struct pldm_set_date_time_req *request =
 	    (struct pldm_set_date_time_req *)msg->payload;
@@ -156,8 +157,6 @@
 int encode_set_date_time_resp(uint8_t instance_id, uint8_t completion_code,
 			      struct pldm_msg *msg, size_t payload_length)
 {
-	struct pldm_header_info header = {0};
-
 	if (msg == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
@@ -165,11 +164,13 @@
 		return PLDM_ERROR_INVALID_LENGTH;
 	}
 
+	struct pldm_header_info header = {0};
 	header.instance = instance_id;
 	header.msg_type = PLDM_RESPONSE;
 	header.pldm_type = PLDM_BIOS;
 	header.command = PLDM_SET_DATE_TIME;
-	int rc = pack_pldm_header(&header, &msg->hdr);
+
+	uint8_t rc = pack_pldm_header(&header, &msg->hdr);
 	if (rc != PLDM_SUCCESS) {
 		return rc;
 	}
@@ -205,25 +206,24 @@
 			       uint8_t transfer_flag, uint8_t *table_data,
 			       size_t payload_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_get_bios_table_resp *response =
-	    (struct pldm_get_bios_table_resp *)msg->payload;
-
-	response->completion_code = completion_code;
+	struct pldm_header_info header = {0};
 	header.msg_type = PLDM_RESPONSE;
 	header.instance = instance_id;
 	header.pldm_type = PLDM_BIOS;
 	header.command = PLDM_GET_BIOS_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;
 	}
 
+	struct pldm_get_bios_table_resp *response =
+	    (struct pldm_get_bios_table_resp *)msg->payload;
+	response->completion_code = completion_code;
 	if (response->completion_code == PLDM_SUCCESS) {
 
 		response->next_transfer_handle = htole32(next_transfer_handle);
@@ -244,17 +244,20 @@
 			      uint8_t transfer_op_flag, uint8_t table_type,
 			      struct pldm_msg *msg)
 {
-	struct pldm_header_info header = {0};
-
 	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_BIOS;
 	header.command = PLDM_GET_BIOS_TABLE;
-	pack_pldm_header(&header, &(msg->hdr));
+
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
 
 	struct pldm_get_bios_table_req *request =
 	    (struct pldm_get_bios_table_req *)msg->payload;
@@ -325,17 +328,20 @@
     uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_op_flag,
     uint16_t attribute_handle, struct pldm_msg *msg)
 {
-	struct pldm_header_info header = {0};
-
 	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_BIOS;
 	header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
-	pack_pldm_header(&header, &(msg->hdr));
+
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
 
 	struct pldm_get_bios_attribute_current_value_by_handle_req *request =
 	    (struct pldm_get_bios_attribute_current_value_by_handle_req *)
@@ -410,25 +416,25 @@
     uint8_t transfer_flag, const uint8_t *attribute_data,
     size_t attribute_length, struct pldm_msg *msg)
 {
-	struct pldm_header_info header = {0};
-	int rc = PLDM_SUCCESS;
-
 	if (msg == NULL || attribute_data == 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_BIOS;
+	header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
+
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
+
 	struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
 	    (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
 		msg->payload;
-
 	response->completion_code = completion_code;
-	header.msg_type = PLDM_RESPONSE;
-	header.instance = instance_id;
-	header.pldm_type = PLDM_BIOS;
-	header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
-	if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
-		return rc;
-	}
 	if (response->completion_code == PLDM_SUCCESS) {
 
 		response->next_transfer_handle = htole32(next_transfer_handle);
@@ -457,7 +463,11 @@
 	header.msg_type = PLDM_REQUEST;
 	header.pldm_type = PLDM_BIOS;
 	header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
-	pack_pldm_header(&header, &msg->hdr);
+
+	uint8_t rc = pack_pldm_header(&header, &msg->hdr);
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
 
 	struct pldm_set_bios_attribute_current_value_req *request =
 	    (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
@@ -532,7 +542,7 @@
 	header.pldm_type = PLDM_BIOS;
 	header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
 
-	int rc = pack_pldm_header(&header, &msg->hdr);
+	uint8_t rc = pack_pldm_header(&header, &msg->hdr);
 	if (rc != PLDM_SUCCESS) {
 		return rc;
 	}
@@ -550,8 +560,6 @@
 			      const uint8_t *table_data, size_t table_length,
 			      struct pldm_msg *msg, size_t payload_length)
 {
-	int rc = PLDM_SUCCESS;
-
 	if (msg == NULL || table_data == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
@@ -567,7 +575,8 @@
 	header.pldm_type = PLDM_BIOS;
 	header.command = PLDM_SET_BIOS_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;
 	}
 
@@ -611,8 +620,6 @@
 			       uint32_t next_transfer_handle,
 			       struct pldm_msg *msg)
 {
-	int rc = PLDM_SUCCESS;
-
 	if (msg == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
@@ -623,7 +630,8 @@
 	header.pldm_type = PLDM_BIOS;
 	header.command = PLDM_SET_BIOS_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;
 	}
 
diff --git a/libpldm/fru.c b/libpldm/fru.c
index 3e0887d..b726139 100644
--- a/libpldm/fru.c
+++ b/libpldm/fru.c
@@ -22,12 +22,8 @@
 	header.msg_type = PLDM_REQUEST;
 	header.pldm_type = PLDM_FRU;
 	header.command = PLDM_GET_FRU_RECORD_TABLE_METADATA;
-	int rc = pack_pldm_header(&header, &(msg->hdr));
-	if (PLDM_SUCCESS != rc) {
-		return rc;
-	}
 
-	return PLDM_SUCCESS;
+	return pack_pldm_header(&header, &(msg->hdr));
 }
 
 int decode_get_fru_record_table_metadata_resp(
@@ -76,7 +72,6 @@
     uint16_t total_record_set_identifiers, uint16_t total_table_records,
     uint32_t checksum, struct pldm_msg *msg)
 {
-
 	if (msg == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
@@ -86,7 +81,8 @@
 	header.instance = instance_id;
 	header.pldm_type = PLDM_FRU;
 	header.command = PLDM_GET_FRU_RECORD_TABLE_METADATA;
-	int rc = pack_pldm_header(&header, &(msg->hdr));
+
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
 	if (PLDM_SUCCESS != rc) {
 		return rc;
 	}
@@ -138,19 +134,18 @@
 				     uint8_t transfer_flag,
 				     struct pldm_msg *msg)
 {
-	struct pldm_header_info header = {0};
-	int rc = PLDM_ERROR_INVALID_DATA;
+	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_FRU;
 	header.command = PLDM_GET_FRU_RECORD_TABLE;
 
-	if (msg == NULL) {
-		return rc;
-	}
-
-	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;
 	}
 
@@ -288,7 +283,7 @@
 	header.msg_type = PLDM_REQUEST;
 	header.pldm_type = PLDM_FRU;
 	header.command = PLDM_GET_FRU_RECORD_BY_OPTION;
-	int rc = pack_pldm_header(&header, &(msg->hdr));
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
 	if (rc != PLDM_SUCCESS) {
 		return rc;
 	}
@@ -348,7 +343,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	if (payload_length < PLDM_GET_FRU_RECORD_BY_OPTION_MIN_RESP_BYTES) {
+	if (payload_length !=
+	    PLDM_GET_FRU_RECORD_BY_OPTION_MIN_RESP_BYTES + data_size) {
 		return PLDM_ERROR_INVALID_LENGTH;
 	}
 
@@ -357,7 +353,7 @@
 	header.msg_type = PLDM_RESPONSE;
 	header.pldm_type = PLDM_FRU;
 	header.command = PLDM_GET_FRU_RECORD_BY_OPTION;
-	int rc = pack_pldm_header(&header, &(msg->hdr));
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
 	if (rc != PLDM_SUCCESS) {
 		return rc;
 	}
@@ -369,17 +365,10 @@
 	resp->next_data_transfer_handle = htole32(next_data_transfer_handle);
 	resp->transfer_flag = transfer_flag;
 
-	if (completion_code != PLDM_SUCCESS) {
-		return PLDM_SUCCESS;
+	if (completion_code == PLDM_SUCCESS) {
+		memcpy(resp->fru_structure_data, fru_structure_data, data_size);
 	}
 
-	if (payload_length !=
-	    PLDM_GET_FRU_RECORD_BY_OPTION_MIN_RESP_BYTES + data_size) {
-		return PLDM_ERROR_INVALID_LENGTH;
-	}
-
-	memcpy(resp->fru_structure_data, fru_structure_data, data_size);
-
 	return PLDM_SUCCESS;
 }
 
@@ -421,21 +410,21 @@
 				    struct pldm_msg *msg, size_t payload_length)
 
 {
-	struct pldm_header_info header = {0};
-	int rc = PLDM_ERROR_INVALID_DATA;
+	if (msg == NULL) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+	if (payload_length != sizeof(struct pldm_get_fru_record_table_req)) {
+		return PLDM_ERROR_INVALID_LENGTH;
+	}
 
+	struct pldm_header_info header = {0};
 	header.msg_type = PLDM_REQUEST;
 	header.instance = instance_id;
 	header.pldm_type = PLDM_FRU;
 	header.command = PLDM_GET_FRU_RECORD_TABLE;
 
-	if (msg == NULL) {
-		return rc;
-	}
-	if (payload_length != sizeof(struct pldm_get_fru_record_table_req)) {
-		return PLDM_ERROR_INVALID_LENGTH;
-	}
-	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/libpldm/platform.c b/libpldm/platform.c
index 135a422..812e8b7 100644
--- a/libpldm/platform.c
+++ b/libpldm/platform.c
@@ -141,19 +141,24 @@
 					  uint8_t completion_code,
 					  struct pldm_msg *msg)
 {
+	if (msg == NULL) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
 	struct pldm_header_info header = {0};
-	int rc = PLDM_SUCCESS;
-
-	msg->payload[0] = completion_code;
-
 	header.msg_type = PLDM_RESPONSE;
 	header.instance = instance_id;
 	header.pldm_type = PLDM_PLATFORM;
 	header.command = PLDM_SET_STATE_EFFECTER_STATES;
 
-	rc = pack_pldm_header(&header, &(msg->hdr));
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
 
-	return rc;
+	msg->payload[0] = completion_code;
+
+	return PLDM_SUCCESS;
 }
 
 int encode_set_state_effecter_states_req(uint8_t instance_id,
@@ -162,16 +167,8 @@
 					 set_effecter_state_field *field,
 					 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_SET_STATE_EFFECTER_STATES;
-
-	if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
-		return rc;
+	if (msg == NULL) {
+		return PLDM_ERROR_INVALID_DATA;
 	}
 
 	if (comp_effecter_count < 0x1 || comp_effecter_count > 0x8 ||
@@ -179,6 +176,17 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
+	struct pldm_header_info header = {0};
+	header.msg_type = PLDM_REQUEST;
+	header.instance = instance_id;
+	header.pldm_type = PLDM_PLATFORM;
+	header.command = PLDM_SET_STATE_EFFECTER_STATES;
+
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
+
 	struct pldm_set_state_effecter_states_req *request =
 	    (struct pldm_set_state_effecter_states_req *)msg->payload;
 	effecter_id = htole16(effecter_id);
@@ -267,25 +275,25 @@
 			uint16_t resp_cnt, const uint8_t *record_data,
 			uint8_t transfer_crc, struct pldm_msg *msg)
 {
-	struct pldm_header_info header = {0};
-	int rc = PLDM_SUCCESS;
-
 	if (msg == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
-	struct pldm_get_pdr_resp *response =
-	    (struct pldm_get_pdr_resp *)msg->payload;
 
-	response->completion_code = completion_code;
-
+	struct pldm_header_info header = {0};
 	header.msg_type = PLDM_RESPONSE;
 	header.instance = instance_id;
 	header.pldm_type = PLDM_PLATFORM;
 	header.command = PLDM_GET_PDR;
-	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;
 	}
 
+	struct pldm_get_pdr_resp *response =
+	    (struct pldm_get_pdr_resp *)msg->payload;
+	response->completion_code = completion_code;
+
 	if (response->completion_code == PLDM_SUCCESS) {
 		response->next_record_handle = htole32(next_record_hndl);
 		response->next_data_transfer_handle =
@@ -311,28 +319,27 @@
 		       uint16_t request_cnt, uint16_t record_chg_num,
 		       struct pldm_msg *msg, size_t payload_length)
 {
-	struct pldm_header_info header = {0};
-	int rc = PLDM_SUCCESS;
-
 	if (msg == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
-	struct pldm_get_pdr_req *request =
-	    (struct pldm_get_pdr_req *)msg->payload;
-
-	header.msg_type = PLDM_REQUEST;
-	header.instance = instance_id;
-	header.pldm_type = PLDM_PLATFORM;
-	header.command = PLDM_GET_PDR;
-
-	if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
-		return rc;
-	}
 
 	if (payload_length != PLDM_GET_PDR_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_PLATFORM;
+	header.command = PLDM_GET_PDR;
+
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
+
+	struct pldm_get_pdr_req *request =
+	    (struct pldm_get_pdr_req *)msg->payload;
 	request->record_handle = htole32(record_hndl);
 	request->data_transfer_handle = htole32(data_transfer_hndl);
 	request->transfer_op_flag = transfer_op_flag;
@@ -467,9 +474,6 @@
 					   struct pldm_msg *msg,
 					   size_t payload_length)
 {
-	struct pldm_header_info header = {0};
-	int rc = PLDM_SUCCESS;
-
 	if (msg == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
@@ -478,14 +482,18 @@
 		return PLDM_ERROR_INVALID_LENGTH;
 	}
 
-	msg->payload[0] = completion_code;
-
+	struct pldm_header_info header = {0};
 	header.msg_type = PLDM_RESPONSE;
 	header.instance = instance_id;
 	header.pldm_type = PLDM_PLATFORM;
 	header.command = PLDM_SET_NUMERIC_EFFECTER_VALUE;
 
-	rc = pack_pldm_header(&header, &(msg->hdr));
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
+
+	msg->payload[0] = completion_code;
 
 	return rc;
 }
@@ -494,28 +502,27 @@
     uint8_t instance_id, uint16_t effecter_id, uint8_t effecter_data_size,
     uint8_t *effecter_value, struct pldm_msg *msg, size_t payload_length)
 {
-	struct pldm_header_info header = {0};
-	int rc = PLDM_SUCCESS;
-
 	if (msg == NULL || effecter_value == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
-	struct pldm_set_numeric_effecter_value_req *request =
-	    (struct pldm_set_numeric_effecter_value_req *)msg->payload;
-
-	header.msg_type = PLDM_REQUEST;
-	header.instance = instance_id;
-	header.pldm_type = PLDM_PLATFORM;
-	header.command = PLDM_SET_NUMERIC_EFFECTER_VALUE;
-
-	if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
-		return rc;
-	}
 
 	if (effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
+	struct pldm_header_info header = {0};
+	header.msg_type = PLDM_REQUEST;
+	header.instance = instance_id;
+	header.pldm_type = PLDM_PLATFORM;
+	header.command = PLDM_SET_NUMERIC_EFFECTER_VALUE;
+
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
+
+	struct pldm_set_numeric_effecter_value_req *request =
+	    (struct pldm_set_numeric_effecter_value_req *)msg->payload;
 	if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 ||
 	    effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) {
 		if (payload_length !=
@@ -575,22 +582,25 @@
 					  get_sensor_state_field *field,
 					  struct pldm_msg *msg)
 {
-	struct pldm_header_info header = {0};
-	int rc = PLDM_SUCCESS;
+	if (msg == NULL) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
 
+	if (comp_sensor_count < 0x1 || comp_sensor_count > 0x8) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
+	struct pldm_header_info header = {0};
 	header.msg_type = PLDM_RESPONSE;
 	header.instance = instance_id;
 	header.pldm_type = PLDM_PLATFORM;
 	header.command = PLDM_GET_STATE_SENSOR_READINGS;
 
-	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;
 	}
 
-	if (comp_sensor_count < 0x1 || comp_sensor_count > 0x8) {
-		return PLDM_ERROR_INVALID_DATA;
-	}
-
 	struct pldm_get_state_sensor_readings_resp *response =
 	    (struct pldm_get_state_sensor_readings_resp *)msg->payload;
 
@@ -599,7 +609,7 @@
 	memcpy(response->field, field,
 	       (sizeof(get_sensor_state_field) * comp_sensor_count));
 
-	return rc;
+	return PLDM_SUCCESS;
 }
 
 int encode_get_state_sensor_readings_req(uint8_t instance_id,
@@ -607,19 +617,18 @@
 					 bitfield8_t sensor_rearm,
 					 uint8_t reserved, 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_PLATFORM;
 	header.command = PLDM_GET_STATE_SENSOR_READINGS;
 
-	if (msg == NULL) {
-		return PLDM_ERROR_INVALID_DATA;
-	}
-
-	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;
 	}
 
@@ -762,8 +771,6 @@
 				       uint8_t platform_event_status,
 				       struct pldm_msg *msg)
 {
-	int rc = PLDM_SUCCESS;
-
 	if (msg == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
@@ -772,20 +779,22 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	struct pldm_platform_event_message_resp *response =
-	    (struct pldm_platform_event_message_resp *)msg->payload;
-	response->completion_code = completion_code;
-	response->platform_event_status = platform_event_status;
-
 	struct pldm_header_info header = {0};
 	header.msg_type = PLDM_RESPONSE;
 	header.instance = instance_id;
 	header.pldm_type = PLDM_PLATFORM;
 	header.command = PLDM_PLATFORM_EVENT_MESSAGE;
 
-	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;
 	}
+
+	struct pldm_platform_event_message_resp *response =
+	    (struct pldm_platform_event_message_resp *)msg->payload;
+	response->completion_code = completion_code;
+	response->platform_event_status = platform_event_status;
+
 	return PLDM_SUCCESS;
 }
 
@@ -795,14 +804,6 @@
     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_PLATFORM;
-	header.command = PLDM_PLATFORM_EVENT_MESSAGE;
-
 	if (format_version != 1) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
@@ -825,7 +826,14 @@
 		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_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;
 	}
 
@@ -1019,25 +1027,23 @@
 					  uint16_t effecter_id,
 					  struct pldm_msg *msg)
 {
-	struct pldm_header_info header = {0};
-	int rc = PLDM_SUCCESS;
-
 	if (msg == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	struct pldm_get_numeric_effecter_value_req *request =
-	    (struct pldm_get_numeric_effecter_value_req *)msg->payload;
-
+	struct pldm_header_info header = {0};
 	header.msg_type = PLDM_REQUEST;
 	header.instance = instance_id;
 	header.pldm_type = PLDM_PLATFORM;
 	header.command = PLDM_GET_NUMERIC_EFFECTER_VALUE;
 
-	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;
 	}
 
+	struct pldm_get_numeric_effecter_value_req *request =
+	    (struct pldm_get_numeric_effecter_value_req *)msg->payload;
 	request->effecter_id = htole16(effecter_id);
 
 	return PLDM_SUCCESS;
@@ -1048,9 +1054,6 @@
     uint8_t effecter_oper_state, uint8_t *pending_value, uint8_t *present_value,
     struct pldm_msg *msg, size_t payload_length)
 {
-	struct pldm_header_info header = {0};
-	int rc = PLDM_SUCCESS;
-
 	if (msg == NULL || pending_value == NULL || present_value == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
@@ -1063,12 +1066,14 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
+	struct pldm_header_info header = {0};
 	header.msg_type = PLDM_RESPONSE;
 	header.instance = instance_id;
 	header.pldm_type = PLDM_PLATFORM;
 	header.command = PLDM_GET_NUMERIC_EFFECTER_VALUE;
 
-	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;
 	}
 
@@ -1348,19 +1353,18 @@
 				  uint8_t rearm_event_state,
 				  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_PLATFORM;
 	header.command = PLDM_GET_SENSOR_READING;
 
-	if (msg == NULL) {
-		return PLDM_ERROR_INVALID_DATA;
-	}
-
-	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;
 	}
 
@@ -1450,9 +1454,6 @@
     uint8_t present_state, uint8_t previous_state, uint8_t event_state,
     uint8_t *present_reading, struct pldm_msg *msg, size_t payload_length)
 {
-	struct pldm_header_info header = {0};
-	int rc = PLDM_SUCCESS;
-
 	if (msg == NULL || present_reading == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
@@ -1461,12 +1462,14 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
+	struct pldm_header_info header = {0};
 	header.msg_type = PLDM_RESPONSE;
 	header.instance = instance_id;
 	header.pldm_type = PLDM_PLATFORM;
 	header.command = PLDM_GET_SENSOR_READING;
 
-	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;
 	}
 
@@ -1540,18 +1543,22 @@
 				  uint16_t heartbeat_timer,
 				  struct pldm_msg *msg)
 {
-	struct pldm_header_info header = {0};
-	int rc = PLDM_SUCCESS;
 	if (msg == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
+	if (transport_protocol_type != PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
+	struct pldm_header_info header = {0};
 	header.msg_type = PLDM_REQUEST;
 	header.instance = instance_id;
 	header.pldm_type = PLDM_PLATFORM;
 	header.command = PLDM_SET_EVENT_RECEIVER;
 
-	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;
 	}
 
@@ -1559,9 +1566,6 @@
 	    (struct pldm_set_event_receiver_req *)msg->payload;
 	request->event_message_global_enable = event_message_global_enable;
 
-	if (transport_protocol_type != PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP) {
-		return PLDM_ERROR_INVALID_DATA;
-	}
 	request->transport_protocol_type = transport_protocol_type;
 	request->event_receiver_address_info = event_receiver_address_info;
 
@@ -1635,21 +1639,22 @@
 				   struct pldm_msg *msg)
 
 {
-	struct pldm_header_info header = {0};
-	int rc = PLDM_SUCCESS;
-
 	if (msg == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	msg->payload[0] = completion_code;
-
+	struct pldm_header_info header = {0};
 	header.instance = instance_id;
 	header.msg_type = PLDM_RESPONSE;
 	header.pldm_type = PLDM_PLATFORM;
 	header.command = PLDM_SET_EVENT_RECEIVER;
 
-	rc = pack_pldm_header(&header, &(msg->hdr));
+	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
+	if (rc != PLDM_SUCCESS) {
+		return rc;
+	}
 
-	return rc;
+	msg->payload[0] = completion_code;
+
+	return PLDM_SUCCESS;
 }
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;

 	}

 

diff --git a/pldmd/pldmd.cpp b/pldmd/pldmd.cpp
index 5c25587..9684f0b 100644
--- a/pldmd/pldmd.cpp
+++ b/pldmd/pldmd.cpp
@@ -70,8 +70,10 @@
     if (PLDM_SUCCESS != unpack_pldm_header(hdr, &hdrFields))
     {
         std::cerr << "Empty PLDM request header \n";
+        return response;
     }
-    else if (PLDM_RESPONSE != hdrFields.msg_type)
+
+    if (PLDM_RESPONSE != hdrFields.msg_type)
     {
         auto request = reinterpret_cast<const pldm_msg*>(hdr);
         size_t requestLen = requestMsg.size() - sizeof(struct pldm_msg_hdr) -
@@ -91,8 +93,7 @@
             header.instance = hdrFields.instance;
             header.pldm_type = hdrFields.pldm_type;
             header.command = hdrFields.command;
-            auto result = pack_pldm_header(&header, responseHdr);
-            if (PLDM_SUCCESS != result)
+            if (PLDM_SUCCESS != pack_pldm_header(&header, responseHdr))
             {
                 std::cerr << "Failed adding response header \n";
             }