msgbuf: Add error code personalities

libpldm is in a bit of a transitional period with respect to returned
error codes. A historical choice was to return PLDM completion codes
from the library API to indicate errors. This is unfortunate because
we're now constrained to errors that are specified by the PLDM protocol,
which is much less expressive than the set of errors that might be
produced by a run-time environment for the library.

The choice going forward is to return C's errno codes. However at this
point we step on another rake in the libpldm design, which is that some
internal data structures are very much the wire format of corresponding
PLDM messages (such as the PDR repository implementation). Working with
wire-format buffers is most safely done via the msgbuf APIs, however we
then hit the conflict of different error code styles in various parts of
the API surface.

Do a bit of surgery to provide different error code personalities for
msgbuf, such that the caller can pick the style of error code they need
it to return to maintain consistency.

Note that like the previous patch marking all msgbuf APIs as
__attribute__((always_inline)), the rework here makes another small
impact on the argument register allocation of several stable APIs. The
ABI dump is updated accordingly.

Change-Id: Id59c39c5c822f514f546dab88575317071a97c96
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/src/firmware_update.c b/src/firmware_update.c
index 4aafadc..9ebb970 100644
--- a/src/firmware_update.c
+++ b/src/firmware_update.c
@@ -903,8 +903,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_OPTIONAL_COMMAND_RESP_MIN_LEN,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_OPTIONAL_COMMAND_RESP_MIN_LEN,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -968,8 +968,9 @@
 		return rc;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_QUERY_DOWNSTREAM_IDENTIFIERS_REQ_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf,
+				 PLDM_QUERY_DOWNSTREAM_IDENTIFIERS_REQ_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -996,8 +997,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_OPTIONAL_COMMAND_RESP_MIN_LEN,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_OPTIONAL_COMMAND_RESP_MIN_LEN,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
diff --git a/src/msgbuf.h b/src/msgbuf.h
index 5036211..f69c428 100644
--- a/src/msgbuf.h
+++ b/src/msgbuf.h
@@ -46,6 +46,7 @@
 
 #include <assert.h>
 #include <endian.h>
+#include <errno.h>
 #include <limits.h>
 #include <stdbool.h>
 #include <stdint.h>
@@ -64,14 +65,62 @@
 		"Extraction and insertion value comparisons may be broken");
 	static_assert(INTMAX_MIN + INTMAX_MAX <= 0,
 		      "Extraction and insertion arithmetic may be broken");
+	static_assert(PLDM_SUCCESS == 0, "Error handling is broken");
 	int compliance;
 } build_assertions __attribute__((unused));
 
+enum pldm_msgbuf_error_mode {
+	PLDM_MSGBUF_PLDM_CC = 0x5a,
+	PLDM_MSGBUF_C_ERRNO = 0xa5,
+};
+
 struct pldm_msgbuf {
 	uint8_t *cursor;
 	intmax_t remaining;
+	enum pldm_msgbuf_error_mode mode;
 };
 
+__attribute__((always_inline)) static inline int
+pldm_msgbuf_status(struct pldm_msgbuf *ctx, unsigned int err)
+{
+	int rc;
+
+	assert(err != 0);
+	assert(err <= INT_MAX);
+
+	if (ctx->mode == PLDM_MSGBUF_C_ERRNO) {
+		if (err > INT_MAX) {
+			return -EINVAL;
+		}
+
+		static_assert(INT_MIN + INT_MAX < 0,
+			      "Arithmetic assumption failure");
+		return -((int)err);
+	}
+
+	if (err > INT_MAX) {
+		return PLDM_ERROR;
+	}
+
+	assert(ctx->mode == PLDM_MSGBUF_PLDM_CC);
+	switch (err) {
+	case EINVAL:
+		rc = PLDM_ERROR_INVALID_DATA;
+		break;
+	case EBADMSG:
+	case EOVERFLOW:
+		rc = PLDM_ERROR_INVALID_LENGTH;
+		break;
+	default:
+		assert(false);
+		rc = PLDM_ERROR;
+		break;
+	}
+
+	assert(rc > 0);
+	return rc;
+}
+
 /**
  * @brief Initialize pldm buf struct for buf extractor
  *
@@ -80,36 +129,92 @@
  * @param[in] buf - buffer to be extracted
  * @param[in] len - size of buffer
  *
- * @return PLDM_SUCCESS if all buffer accesses were in-bounds,
- * PLDM_ERROR_INVALID_DATA if pointer parameters are invalid, or
- * PLDM_ERROR_INVALID_LENGTH if length constraints are violated.
+ * @return 0 on success, otherwise an error code appropriate for the current
+ *         personality.
  */
 __attribute__((always_inline)) static inline int
-pldm_msgbuf_init(struct pldm_msgbuf *ctx, size_t minsize, const void *buf,
-		 size_t len)
+// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
+pldm__msgbuf_init(struct pldm_msgbuf *ctx, size_t minsize, const void *buf,
+		  size_t len)
 {
-	if (!ctx || !buf) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+	assert(ctx->mode == PLDM_MSGBUF_PLDM_CC ||
+	       ctx->mode == PLDM_MSGBUF_C_ERRNO);
+
+	if (!buf) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	if ((minsize > len)) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 #if INTMAX_MAX < SIZE_MAX
 	if (len > INTMAX_MAX) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 #endif
 
 	if ((uintptr_t)buf + len < len) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	ctx->cursor = (uint8_t *)buf;
 	ctx->remaining = (intmax_t)len;
 
-	return PLDM_SUCCESS;
+	return 0;
+}
+
+/**
+ * @brief Initialise a msgbuf instance to return errors as PLDM completion codes
+ *
+ * @see pldm__msgbuf_init
+ *
+ * @param[out] ctx - pldm_msgbuf context for extractor
+ * @param[in] minsize - The minimum required length of buffer `buf`
+ * @param[in] buf - buffer to be extracted
+ * @param[in] len - size of buffer
+ *
+ * @return PLDM_SUCCESS if the provided buffer region is sensible,
+ *         otherwise PLDM_ERROR_INVALID_DATA if pointer parameters are invalid,
+ *         or PLDM_ERROR_INVALID_LENGTH if length constraints are violated.
+ */
+__attribute__((always_inline)) static inline int
+pldm_msgbuf_init_cc(struct pldm_msgbuf *ctx, size_t minsize, const void *buf,
+		    size_t len)
+{
+	if (!ctx) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
+	ctx->mode = PLDM_MSGBUF_PLDM_CC;
+	return pldm__msgbuf_init(ctx, minsize, buf, len);
+}
+
+/**
+ * @brief Initialise a msgbuf instance to return errors as negative errno values
+ *
+ * @see pldm__msgbuf_init
+ *
+ * @param[out] ctx - pldm_msgbuf context for extractor
+ * @param[in] minsize - The minimum required length of buffer `buf`
+ * @param[in] buf - buffer to be extracted
+ * @param[in] len - size of buffer
+ *
+ * @return 0 if the provided buffer region is sensible, otherwise -EINVAL if
+ *         pointer parameters are invalid, or -EOVERFLOW if length constraints
+ *         are violated.
+ */
+__attribute__((always_inline)) static inline int
+pldm_msgbuf_init_errno(struct pldm_msgbuf *ctx, size_t minsize, const void *buf,
+		       size_t len)
+{
+	if (!ctx) {
+		return -EINVAL;
+	}
+
+	ctx->mode = PLDM_MSGBUF_C_ERRNO;
+	return pldm__msgbuf_init(ctx, minsize, buf, len);
 }
 
 /**
@@ -126,11 +231,12 @@
 __attribute__((always_inline)) static inline int
 pldm_msgbuf_validate(struct pldm_msgbuf *ctx)
 {
-	if (!ctx) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+	if (ctx->remaining < 0) {
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
-	return ctx->remaining >= 0 ? PLDM_SUCCESS : PLDM_ERROR_INVALID_LENGTH;
+	return 0;
 }
 
 /**
@@ -147,11 +253,12 @@
 __attribute__((always_inline)) static inline int
 pldm_msgbuf_consumed(struct pldm_msgbuf *ctx)
 {
-	if (!ctx) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+	if (ctx->remaining != 0) {
+		return pldm_msgbuf_status(ctx, EBADMSG);
 	}
 
-	return ctx->remaining == 0 ? PLDM_SUCCESS : PLDM_ERROR_INVALID_LENGTH;
+	return 0;
 }
 
 /**
@@ -169,10 +276,7 @@
 {
 	int valid;
 
-	if (!ctx) {
-		return PLDM_ERROR_INVALID_DATA;
-	}
-
+	assert(ctx);
 	valid = pldm_msgbuf_validate(ctx);
 
 	ctx->cursor = NULL;
@@ -197,10 +301,7 @@
 {
 	int consumed;
 
-	if (!ctx) {
-		return PLDM_ERROR_INVALID_DATA;
-	}
-
+	assert(ctx);
 	consumed = pldm_msgbuf_consumed(ctx);
 
 	ctx->cursor = NULL;
@@ -313,24 +414,26 @@
 // NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
 pldm__msgbuf_extract_uint8(struct pldm_msgbuf *ctx, void *dst)
 {
-	if (!ctx || !ctx->cursor || !dst) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor || !dst) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	if (ctx->remaining == INTMAX_MIN) {
 		assert(ctx->remaining < 0);
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= sizeof(uint8_t);
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	memcpy(dst, ctx->cursor, sizeof(uint8_t));
 
 	ctx->cursor++;
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 #define pldm_msgbuf_extract_int8(ctx, dst)                                     \
@@ -340,23 +443,25 @@
 // NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
 pldm__msgbuf_extract_int8(struct pldm_msgbuf *ctx, void *dst)
 {
-	if (!ctx || !ctx->cursor || !dst) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor || !dst) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	if (ctx->remaining == INTMAX_MIN) {
 		assert(ctx->remaining < 0);
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= sizeof(int8_t);
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	memcpy(dst, ctx->cursor, sizeof(int8_t));
 	ctx->cursor++;
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 #define pldm_msgbuf_extract_uint16(ctx, dst)                                   \
@@ -368,8 +473,10 @@
 {
 	uint16_t ldst;
 
-	if (!ctx || !ctx->cursor || !dst) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor || !dst) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	// Check for underflow while tracking the magnitude of the buffer overflow
@@ -379,7 +486,7 @@
 		"The following addition may not uphold the runtime assertion");
 	if (ctx->remaining < INTMAX_MIN + (intmax_t)sizeof(ldst)) {
 		assert(ctx->remaining < 0);
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	// Check for buffer overflow. If we overflow, account for the request as
@@ -392,7 +499,7 @@
 	// -DNDEBUG by explicitly testing that the access is valid.
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	// Use memcpy() to have the compiler deal with any alignment
@@ -407,7 +514,7 @@
 
 	ctx->cursor += sizeof(ldst);
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 #define pldm_msgbuf_extract_int16(ctx, dst)                                    \
@@ -419,8 +526,10 @@
 {
 	int16_t ldst;
 
-	if (!ctx || !ctx->cursor || !dst) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor || !dst) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	static_assert(
@@ -429,12 +538,12 @@
 		"The following addition may not uphold the runtime assertion");
 	if (ctx->remaining < INTMAX_MIN + (intmax_t)sizeof(ldst)) {
 		assert(ctx->remaining < 0);
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= sizeof(ldst);
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	memcpy(&ldst, ctx->cursor, sizeof(ldst));
@@ -443,7 +552,7 @@
 	memcpy(dst, &ldst, sizeof(ldst));
 	ctx->cursor += sizeof(ldst);
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 #define pldm_msgbuf_extract_uint32(ctx, dst)                                   \
@@ -455,8 +564,10 @@
 {
 	uint32_t ldst;
 
-	if (!ctx || !ctx->cursor || !dst) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor || !dst) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	static_assert(
@@ -465,21 +576,20 @@
 		"The following addition may not uphold the runtime assertion");
 	if (ctx->remaining < INTMAX_MIN + (intmax_t)sizeof(ldst)) {
 		assert(ctx->remaining < 0);
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= sizeof(ldst);
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	memcpy(&ldst, ctx->cursor, sizeof(ldst));
-
 	ldst = le32toh(ldst);
 	memcpy(dst, &ldst, sizeof(ldst));
 	ctx->cursor += sizeof(ldst);
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 #define pldm_msgbuf_extract_int32(ctx, dst)                                    \
@@ -491,8 +601,10 @@
 {
 	int32_t ldst;
 
-	if (!ctx || !ctx->cursor || !dst) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor || !dst) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	static_assert(
@@ -501,16 +613,15 @@
 		"The following addition may not uphold the runtime assertion");
 	if (ctx->remaining < INTMAX_MIN + (intmax_t)sizeof(ldst)) {
 		assert(ctx->remaining < 0);
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= sizeof(ldst);
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	memcpy(&ldst, ctx->cursor, sizeof(ldst));
-
 	ldst = le32toh(ldst);
 	memcpy(dst, &ldst, sizeof(ldst));
 	ctx->cursor += sizeof(ldst);
@@ -527,11 +638,13 @@
 {
 	uint32_t ldst;
 
-	_Static_assert(sizeof(real32_t) == sizeof(ldst),
-		       "Mismatched type sizes for dst and ldst");
+	static_assert(sizeof(real32_t) == sizeof(ldst),
+		      "Mismatched type sizes for dst and ldst");
 
-	if (!ctx || !ctx->cursor || !dst) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor || !dst) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	static_assert(
@@ -540,12 +653,12 @@
 		"The following addition may not uphold the runtime assertion");
 	if (ctx->remaining < INTMAX_MIN + (intmax_t)sizeof(ldst)) {
 		assert(ctx->remaining < 0);
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= sizeof(ldst);
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	memcpy(&ldst, ctx->cursor, sizeof(ldst));
@@ -553,7 +666,7 @@
 	memcpy(dst, &ldst, sizeof(ldst));
 	ctx->cursor += sizeof(ldst);
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 /**
@@ -598,33 +711,35 @@
 pldm_msgbuf_extract_array_uint8(struct pldm_msgbuf *ctx, uint8_t *dst,
 				size_t count)
 {
-	if (!ctx || !ctx->cursor || !dst) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor || !dst) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	if (!count) {
-		return PLDM_SUCCESS;
+		return 0;
 	}
 
 #if INTMAX_MAX < SIZE_MAX
 	if (count > INTMAX_MAX) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 #endif
 
 	if (ctx->remaining < INTMAX_MIN + (intmax_t)count) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= (intmax_t)count;
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	memcpy(dst, ctx->cursor, count);
 	ctx->cursor += count;
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 #define pldm_msgbuf_extract_array(ctx, dst, count)                             \
@@ -636,8 +751,10 @@
 {
 	uint32_t val = htole32(src);
 
-	if (!ctx || !ctx->cursor) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	static_assert(
@@ -646,18 +763,18 @@
 		"The following addition may not uphold the runtime assertion");
 	if (ctx->remaining < INTMAX_MIN + (intmax_t)sizeof(src)) {
 		assert(ctx->remaining < 0);
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= sizeof(src);
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	memcpy(ctx->cursor, &val, sizeof(val));
 	ctx->cursor += sizeof(src);
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 __attribute__((always_inline)) static inline int
@@ -665,8 +782,10 @@
 {
 	uint16_t val = htole16(src);
 
-	if (!ctx || !ctx->cursor) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	static_assert(
@@ -675,25 +794,27 @@
 		"The following addition may not uphold the runtime assertion");
 	if (ctx->remaining < INTMAX_MIN + (intmax_t)sizeof(src)) {
 		assert(ctx->remaining < 0);
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= sizeof(src);
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	memcpy(ctx->cursor, &val, sizeof(val));
 	ctx->cursor += sizeof(src);
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 __attribute__((always_inline)) static inline int
 pldm_msgbuf_insert_uint8(struct pldm_msgbuf *ctx, const uint8_t src)
 {
-	if (!ctx || !ctx->cursor) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	static_assert(
@@ -702,18 +823,18 @@
 		"The following addition may not uphold the runtime assertion");
 	if (ctx->remaining < INTMAX_MIN + (intmax_t)sizeof(src)) {
 		assert(ctx->remaining < 0);
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= sizeof(src);
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	memcpy(ctx->cursor, &src, sizeof(src));
 	ctx->cursor += sizeof(src);
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 __attribute__((always_inline)) static inline int
@@ -721,8 +842,10 @@
 {
 	int32_t val = htole32(src);
 
-	if (!ctx || !ctx->cursor) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	static_assert(
@@ -731,18 +854,18 @@
 		"The following addition may not uphold the runtime assertion");
 	if (ctx->remaining < INTMAX_MIN + (intmax_t)sizeof(src)) {
 		assert(ctx->remaining < 0);
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= sizeof(src);
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	memcpy(ctx->cursor, &val, sizeof(val));
 	ctx->cursor += sizeof(src);
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 __attribute__((always_inline)) static inline int
@@ -750,8 +873,10 @@
 {
 	int16_t val = htole16(src);
 
-	if (!ctx || !ctx->cursor) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	static_assert(
@@ -760,25 +885,27 @@
 		"The following addition may not uphold the runtime assertion");
 	if (ctx->remaining < INTMAX_MIN + (intmax_t)sizeof(src)) {
 		assert(ctx->remaining < 0);
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= sizeof(src);
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	memcpy(ctx->cursor, &val, sizeof(val));
 	ctx->cursor += sizeof(src);
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 __attribute__((always_inline)) static inline int
 pldm_msgbuf_insert_int8(struct pldm_msgbuf *ctx, const int8_t src)
 {
-	if (!ctx || !ctx->cursor) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	static_assert(
@@ -787,18 +914,18 @@
 		"The following addition may not uphold the runtime assertion");
 	if (ctx->remaining < INTMAX_MIN + (intmax_t)sizeof(src)) {
 		assert(ctx->remaining < 0);
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= sizeof(src);
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	memcpy(ctx->cursor, &src, sizeof(src));
 	ctx->cursor += sizeof(src);
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 #define pldm_msgbuf_insert(dst, src)                                           \
@@ -814,33 +941,35 @@
 pldm_msgbuf_insert_array_uint8(struct pldm_msgbuf *ctx, const uint8_t *src,
 			       size_t count)
 {
-	if (!ctx || !ctx->cursor || !src) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor || !src) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	if (!count) {
-		return PLDM_SUCCESS;
+		return 0;
 	}
 
 #if INTMAX_MAX < SIZE_MAX
 	if (count > INTMAX_MAX) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 #endif
 
 	if (ctx->remaining < INTMAX_MIN + (intmax_t)count) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= (intmax_t)count;
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	memcpy(ctx->cursor, src, count);
 	ctx->cursor += count;
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 #define pldm_msgbuf_insert_array(dst, src, count)                              \
@@ -851,41 +980,45 @@
 pldm_msgbuf_span_required(struct pldm_msgbuf *ctx, size_t required,
 			  void **cursor)
 {
-	if (!ctx || !ctx->cursor || !cursor || *cursor) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor || !cursor || *cursor) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 #if INTMAX_MAX < SIZE_MAX
 	if (required > INTMAX_MAX) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 #endif
 
 	if (ctx->remaining < INTMAX_MIN + (intmax_t)required) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 	ctx->remaining -= (intmax_t)required;
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	*cursor = ctx->cursor;
 	ctx->cursor += required;
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 __attribute__((always_inline)) static inline int
 pldm_msgbuf_span_remaining(struct pldm_msgbuf *ctx, void **cursor, size_t *len)
 {
-	if (!ctx || !ctx->cursor || !cursor || *cursor || !len) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(ctx);
+
+	if (!ctx->cursor || !cursor || *cursor || !len) {
+		return pldm_msgbuf_status(ctx, EINVAL);
 	}
 
 	assert(ctx->remaining >= 0);
 	if (ctx->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(ctx, EOVERFLOW);
 	}
 
 	*cursor = ctx->cursor;
@@ -893,7 +1026,7 @@
 	*len = ctx->remaining;
 	ctx->remaining = 0;
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 /**
@@ -915,42 +1048,47 @@
 pldm__msgbuf_copy(struct pldm_msgbuf *dst, struct pldm_msgbuf *src, size_t size,
 		  const char *description)
 {
-	if (!src || !src->cursor || !dst || !dst->cursor || !description) {
-		return PLDM_ERROR_INVALID_DATA;
+	assert(src);
+	assert(dst);
+	assert(src->mode == dst->mode);
+
+	if (!src->cursor || !dst->cursor || !description) {
+		return pldm_msgbuf_status(dst, EINVAL);
 	}
 
 #if INTMAX_MAX < SIZE_MAX
 	if (size > INTMAX_MAX) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(dst, EOVERFLOW);
 	}
 #endif
 
 	if (src->remaining < INTMAX_MIN + (intmax_t)size) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(dst, EOVERFLOW);
 	}
 
 	if (dst->remaining < INTMAX_MIN + (intmax_t)size) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(dst, EOVERFLOW);
 	}
 
 	src->remaining -= (intmax_t)size;
 	assert(src->remaining >= 0);
 	if (src->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(dst, EOVERFLOW);
 	}
 
 	dst->remaining -= (intmax_t)size;
 	assert(dst->remaining >= 0);
 	if (dst->remaining < 0) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return pldm_msgbuf_status(dst, EOVERFLOW);
 	}
 
 	memcpy(dst->cursor, src->cursor, size);
 	src->cursor += size;
 	dst->cursor += size;
 
-	return PLDM_SUCCESS;
+	return 0;
 }
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/oem/meta/file_io.c b/src/oem/meta/file_io.c
index 0495ac5..073c446 100644
--- a/src/oem/meta/file_io.c
+++ b/src/oem/meta/file_io.c
@@ -19,9 +19,9 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	int rc = pldm_msgbuf_init(buf,
-				  PLDM_OEM_META_DECODE_WRITE_FILE_IO_MIN_SIZE,
-				  msg->payload, payload_length);
+	int rc = pldm_msgbuf_init_cc(
+		buf, PLDM_OEM_META_DECODE_WRITE_FILE_IO_MIN_SIZE, msg->payload,
+		payload_length);
 	if (rc) {
 		return rc;
 	}
diff --git a/src/platform.c b/src/platform.c
index 7db81b2..79f7c1e 100644
--- a/src/platform.c
+++ b/src/platform.c
@@ -270,8 +270,8 @@
 		return PLDM_ERROR_INVALID_LENGTH;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_SET_STATE_EFFECTER_STATES_MIN_SIZE,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_SET_STATE_EFFECTER_STATES_MIN_SIZE,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -311,8 +311,8 @@
 		return PLDM_ERROR_INVALID_LENGTH;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_GET_PDR_REQ_BYTES, msg->payload,
-			      payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_GET_PDR_REQ_BYTES, msg->payload,
+				 payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -439,8 +439,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -519,8 +519,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_GET_PDR_MIN_RESP_BYTES, msg->payload,
-			      payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_GET_PDR_MIN_RESP_BYTES, msg->payload,
+				 payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -568,9 +568,9 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf,
-			      PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf,
+				 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -789,9 +789,9 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf,
-			      PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf,
+				 PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -839,8 +839,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -904,8 +904,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -933,9 +933,9 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf,
-			      PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf,
+				 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -1026,7 +1026,7 @@
 		return rc;
 	}
 
-	rc = pldm_msgbuf_init(
+	rc = pldm_msgbuf_init_cc(
 		buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
 		msg->payload, payload_length);
 	if (rc) {
@@ -1130,8 +1130,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -1196,8 +1196,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -1268,8 +1268,9 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf,
+				 PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -1324,8 +1325,8 @@
 	struct pldm_msgbuf *buf = &_buf;
 	int rc;
 
-	rc = pldm_msgbuf_init(buf, PLDM_SENSOR_EVENT_DATA_MIN_LENGTH,
-			      event_data, event_data_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_SENSOR_EVENT_DATA_MIN_LENGTH,
+				 event_data, event_data_length);
 	if (rc) {
 		return rc;
 	}
@@ -1378,9 +1379,9 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf,
-			      PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH,
-			      sensor_data, sensor_data_length);
+	rc = pldm_msgbuf_init_cc(buf,
+				 PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH,
+				 sensor_data, sensor_data_length);
 	if (rc) {
 		return rc;
 	}
@@ -1406,9 +1407,9 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf,
-			      PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH,
-			      sensor_data, sensor_data_length);
+	rc = pldm_msgbuf_init_cc(
+		buf, PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH,
+		sensor_data, sensor_data_length);
 	if (rc) {
 		return rc;
 	}
@@ -1441,7 +1442,7 @@
 		return PLDM_ERROR_INVALID_LENGTH;
 	}
 
-	rc = pldm_msgbuf_init(
+	rc = pldm_msgbuf_init_cc(
 		buf, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MIN_DATA_LENGTH,
 		sensor_data, sensor_data_length);
 	if (rc) {
@@ -1519,8 +1520,8 @@
 	struct pldm_msgbuf *buf = &_buf;
 	int rc;
 
-	rc = pldm_msgbuf_init(buf, PLDM_PDR_NUMERIC_SENSOR_PDR_MIN_LENGTH,
-			      pdr_data, pdr_data_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_PDR_NUMERIC_SENSOR_PDR_MIN_LENGTH,
+				 pdr_data, pdr_data_length);
 	if (rc) {
 		return rc;
 	}
@@ -1732,8 +1733,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -1762,9 +1763,9 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf,
-			      PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf,
+				 PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -1884,8 +1885,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH,
-			      event_data, event_data_size);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH,
+				 event_data, event_data_size);
 	if (rc) {
 		return rc;
 	}
@@ -1915,8 +1916,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_MSG_POLL_EVENT_LENGTH, event_data,
-			      event_data_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_MSG_POLL_EVENT_LENGTH, event_data,
+				 event_data_length);
 	if (rc) {
 		return rc;
 	}
@@ -1955,8 +1956,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_MSG_POLL_EVENT_LENGTH, event_data,
-			      event_data_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_MSG_POLL_EVENT_LENGTH, event_data,
+				 event_data_length);
 	if (rc) {
 		return rc;
 	}
@@ -1982,8 +1983,9 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH,
-			      change_record_data, change_record_data_size);
+	rc = pldm_msgbuf_init_cc(buf,
+				 PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH,
+				 change_record_data, change_record_data_size);
 	if (rc) {
 		return rc;
 	}
@@ -2046,8 +2048,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_GET_SENSOR_READING_MIN_RESP_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_GET_SENSOR_READING_MIN_RESP_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -2166,8 +2168,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_GET_SENSOR_READING_REQ_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_GET_SENSOR_READING_REQ_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -2236,8 +2238,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_SET_EVENT_RECEIVER_RESP_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_SET_EVENT_RECEIVER_RESP_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -2266,8 +2268,8 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_SET_EVENT_RECEIVER_REQ_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_SET_EVENT_RECEIVER_REQ_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -2344,7 +2346,7 @@
 		return rc;
 	}
 
-	rc = pldm_msgbuf_init(
+	rc = pldm_msgbuf_init_cc(
 		buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
 		msg->payload, payload_length);
 	if (rc) {
@@ -2379,7 +2381,7 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(
+	rc = pldm_msgbuf_init_cc(
 		buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
 		msg->payload, payload_length);
 	if (rc) {
@@ -2440,8 +2442,8 @@
 	struct pldm_value_pdr_hdr hdr;
 	int rc;
 
-	rc = pldm_msgbuf_init(buf, PLDM_PDR_NUMERIC_EFFECTER_PDR_MIN_LENGTH,
-			      pdr_data, pdr_data_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_PDR_NUMERIC_EFFECTER_PDR_MIN_LENGTH,
+				 pdr_data, pdr_data_length);
 	if (rc) {
 		return rc;
 	}
@@ -2546,8 +2548,8 @@
 		return rc;
 	}
 
-	rc = pldm_msgbuf_init(buf, PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf, PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -2570,9 +2572,9 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf,
-			      PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf,
+				 PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -2597,9 +2599,9 @@
 		return PLDM_ERROR_INVALID_DATA;
 	}
 
-	rc = pldm_msgbuf_init(buf,
-			      PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf,
+				 PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}
@@ -2668,9 +2670,9 @@
 		return rc;
 	}
 
-	rc = pldm_msgbuf_init(buf,
-			      PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES,
-			      msg->payload, payload_length);
+	rc = pldm_msgbuf_init_cc(buf,
+				 PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES,
+				 msg->payload, payload_length);
 	if (rc) {
 		return rc;
 	}