msgbuf: Externalise error value conversion

We need to simplify the code to satisfy clang's analyzer, which seems
to struggle with assumptions if the code exceeds some unknown complexity
limit.

Specifically, this does away with pldm_msgbuf_init_cc() and all the
associated pldm_msgbuf_status() error translation machinery. All the
call-sites are fixed up, with some additional safety checks put in place
along the way.

I believe this change is viable because unless we're converting legacy
API implementations to use msgbuf there's no additional trickery, and
if we're converting existing implementations then care is required
regardless. The change of approach has no impact on implementation of
new APIs with msgbuf, as the current philosophy is that they should
return negative errnos anyway.

As seems to be the case with this kind of work, the parameter register
allocation seems to have been affected for a number of library APIs.
These are listed in the changelog, and the ABI dump has been updated.

Finally, for msgbuf use in the test cases, all instances have
been converted to use errnos in place of PLDM completion codes in the
expectations. Hopefully there's no more malarky with PLDM completion
code misuse in the future.

Change-Id: Id4a7366ee9f60fb991dfe84aa0bb5aadc9855fcc
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/tests/msgbuf.cpp b/tests/msgbuf.cpp
index a65f6bb..fc3c0c8 100644
--- a/tests/msgbuf.cpp
+++ b/tests/msgbuf.cpp
@@ -18,8 +18,8 @@
     struct pldm_msgbuf* ctx = &_ctx;
     uint8_t buf[1] = {};
 
-    EXPECT_NE(pldm_msgbuf_init_cc(ctx, sizeof(buf) + 1U, buf, sizeof(buf)),
-              PLDM_SUCCESS);
+    EXPECT_NE(pldm_msgbuf_init_errno(ctx, sizeof(buf) + 1U, buf, sizeof(buf)),
+              0);
 }
 
 TEST(msgbuf, init_bad_len)
@@ -28,8 +28,7 @@
     struct pldm_msgbuf* ctx = &_ctx;
     uint8_t buf[1] = {};
 
-    EXPECT_NE(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, SIZE_MAX),
-              PLDM_SUCCESS);
+    EXPECT_NE(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, SIZE_MAX), 0);
 }
 
 TEST(msgbuf, init_overflow)
@@ -39,7 +38,7 @@
     // NOLINTNEXTLINE(performance-no-int-to-ptr)
     void* buf = (void*)UINTPTR_MAX;
 
-    EXPECT_NE(pldm_msgbuf_init_cc(ctx, 0, buf, 2), PLDM_SUCCESS);
+    EXPECT_NE(pldm_msgbuf_init_errno(ctx, 0, buf, 2), 0);
 }
 
 TEST(msgbuf, init_success)
@@ -48,8 +47,7 @@
     struct pldm_msgbuf* ctx = &_ctx;
     uint8_t buf[1] = {};
 
-    EXPECT_EQ(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)),
-              PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)), 0);
 }
 
 TEST(msgbuf, destroy_none)
@@ -58,9 +56,8 @@
     struct pldm_msgbuf* ctx = &_ctx;
     uint8_t buf[1] = {};
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, destroy_exact)
@@ -70,11 +67,10 @@
     uint8_t buf[1] = {0xa5};
     uint8_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint8(ctx, val), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint8(ctx, val), 0);
     EXPECT_EQ(val, 0xa5);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, destroy_over)
@@ -84,12 +80,11 @@
     uint8_t buf[1] = {0xa5};
     uint8_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    ASSERT_EQ(pldm_msgbuf_extract_uint8(ctx, val), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)), 0);
+    ASSERT_EQ(pldm_msgbuf_extract_uint8(ctx, val), 0);
     ASSERT_EQ(val, 0xa5);
-    EXPECT_NE(pldm_msgbuf_extract_uint8(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_extract_uint8(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, destroy_under)
@@ -99,11 +94,10 @@
     uint8_t buf[2] = {0x5a, 0xa5};
     uint8_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint8(ctx, val), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint8(ctx, val), 0);
     EXPECT_EQ(val, 0x5a);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, extract_one_uint8)
@@ -113,11 +107,10 @@
     uint8_t buf[1] = {0xa5};
     uint8_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint8(ctx, val), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint8(ctx, val), 0);
     EXPECT_EQ(val, 0xa5);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, extract_over_uint8)
@@ -127,9 +120,9 @@
     uint8_t buf[1] = {};
     uint8_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
-    EXPECT_NE(pldm_msgbuf_extract_uint8(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
+    EXPECT_NE(pldm_msgbuf_extract_uint8(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_under_uint8)
@@ -140,10 +133,10 @@
     uint8_t buf[1] = {};
     uint8_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN;
-    EXPECT_NE(pldm_msgbuf_extract_uint8(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_extract_uint8(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_one_int8)
@@ -153,11 +146,10 @@
     int8_t buf[1] = {-1};
     int8_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_int8(ctx, val), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_int8(ctx, val), 0);
     EXPECT_EQ(val, -1);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, extract_over_int8)
@@ -167,9 +159,9 @@
     int8_t buf[1] = {};
     int8_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
-    EXPECT_NE(pldm_msgbuf_extract_int8(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
+    EXPECT_NE(pldm_msgbuf_extract_int8(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_under_int8)
@@ -180,10 +172,10 @@
     uint8_t buf[1] = {};
     int8_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN;
-    EXPECT_NE(pldm_msgbuf_extract_int8(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_extract_int8(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_one_uint16)
@@ -193,11 +185,10 @@
     uint16_t buf[1] = {htole16(0x5aa5)};
     uint16_t val = {};
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint16(ctx, val), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint16(ctx, val), 0);
     EXPECT_EQ(val, 0x5aa5);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, extract_under_uint16)
@@ -208,10 +199,10 @@
     uint16_t buf[1] = {};
     uint16_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN + sizeof(val) - 1;
-    EXPECT_NE(pldm_msgbuf_extract_uint16(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_extract_uint16(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_over_uint16)
@@ -221,9 +212,9 @@
     uint16_t buf[1] = {};
     uint16_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
-    EXPECT_NE(pldm_msgbuf_extract_uint16(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
+    EXPECT_NE(pldm_msgbuf_extract_uint16(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_one_int16)
@@ -233,11 +224,10 @@
     int16_t buf[1] = {(int16_t)(htole16((uint16_t)INT16_MIN))};
     int16_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_int16(ctx, val), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_int16(ctx, val), 0);
     EXPECT_EQ(val, INT16_MIN);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, extract_over_int16)
@@ -247,9 +237,9 @@
     int16_t buf[1] = {};
     int16_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
-    EXPECT_NE(pldm_msgbuf_extract_int16(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
+    EXPECT_NE(pldm_msgbuf_extract_int16(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_under_int16)
@@ -260,10 +250,10 @@
     int16_t buf[1] = {};
     int16_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN + sizeof(val) - 1;
-    EXPECT_NE(pldm_msgbuf_extract_int16(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_extract_int16(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_one_uint32)
@@ -273,11 +263,10 @@
     uint32_t buf[1] = {htole32(0x5a00ffa5)};
     uint32_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint32(ctx, val), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint32(ctx, val), 0);
     EXPECT_EQ(val, 0x5a00ffa5);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, extract_over_uint32)
@@ -287,9 +276,9 @@
     uint32_t buf[1] = {};
     uint32_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
-    EXPECT_NE(pldm_msgbuf_extract_uint32(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
+    EXPECT_NE(pldm_msgbuf_extract_uint32(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_under_uint32)
@@ -300,10 +289,10 @@
     uint32_t buf[1] = {};
     uint32_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN + sizeof(val) - 1;
-    EXPECT_NE(pldm_msgbuf_extract_uint32(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_extract_uint32(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_one_int32)
@@ -313,11 +302,10 @@
     int32_t buf[1] = {(int32_t)(htole32((uint32_t)(INT32_MIN)))};
     int32_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_int32(ctx, val), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_int32(ctx, val), 0);
     EXPECT_EQ(val, INT32_MIN);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, extract_over_int32)
@@ -327,9 +315,9 @@
     int32_t buf[1] = {};
     int32_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
-    EXPECT_NE(pldm_msgbuf_extract_int32(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
+    EXPECT_NE(pldm_msgbuf_extract_int32(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_under_int32)
@@ -340,10 +328,10 @@
     int32_t buf[1] = {};
     int32_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN + sizeof(val) - 1;
-    EXPECT_NE(pldm_msgbuf_extract_int32(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_extract_int32(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_one_real32)
@@ -359,11 +347,10 @@
     buf[0] = htole32(xform);
     val = 0;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_real32(ctx, val), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_real32(ctx, val), 0);
     EXPECT_EQ(val, FLT_MAX);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, extract_over_real32)
@@ -373,9 +360,9 @@
     real32_t buf[1] = {};
     real32_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
-    EXPECT_NE(pldm_msgbuf_extract_real32(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
+    EXPECT_NE(pldm_msgbuf_extract_real32(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_under_real32)
@@ -386,10 +373,10 @@
     real32_t buf[1] = {};
     real32_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN + sizeof(val) - 1;
-    EXPECT_NE(pldm_msgbuf_extract_real32(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_extract_real32(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_array_uint8_buf0_req0)
@@ -399,9 +386,9 @@
     uint8_t buf[1] = {};
     uint8_t arr[1];
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_array_uint8(ctx, 0, arr, 0), PLDM_SUCCESS);
-    ASSERT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_array_uint8(ctx, 0, arr, 0), 0);
+    ASSERT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, extract_array_uint8_buf1_req1)
@@ -411,12 +398,11 @@
     uint8_t buf[1] = {};
     uint8_t arr[1];
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
     EXPECT_EQ(
-        pldm_msgbuf_extract_array_uint8(ctx, sizeof(arr), arr, sizeof(arr)),
-        PLDM_SUCCESS);
+        pldm_msgbuf_extract_array_uint8(ctx, sizeof(arr), arr, sizeof(arr)), 0);
     EXPECT_EQ(arr[0], 0);
-    ASSERT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, extract_array_uint8_buf1_req2)
@@ -426,11 +412,10 @@
     uint8_t buf[1] = {};
     uint8_t arr[2];
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
     EXPECT_NE(
-        pldm_msgbuf_extract_array_uint8(ctx, sizeof(arr), arr, sizeof(arr)),
-        PLDM_SUCCESS);
-    ASSERT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+        pldm_msgbuf_extract_array_uint8(ctx, sizeof(arr), arr, sizeof(arr)), 0);
+    ASSERT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_under_array_uint8)
@@ -440,10 +425,10 @@
     uint8_t buf[1] = {};
     uint8_t arr[1];
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN;
-    EXPECT_NE(pldm_msgbuf_extract_array_uint8(ctx, 1, arr, 1), PLDM_SUCCESS);
-    ASSERT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_extract_array_uint8(ctx, 1, arr, 1), 0);
+    ASSERT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, extract_array_char_buf0_req0)
@@ -504,8 +489,8 @@
     struct pldm_msgbuf* ctx = &_ctx;
     uint8_t buf[1] = {};
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy_consumed(ctx), PLDM_ERROR_INVALID_LENGTH);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy_consumed(ctx), -EBADMSG);
 }
 
 TEST(msgbuf, consumed_exact)
@@ -515,9 +500,9 @@
     uint8_t buf[1] = {};
     uint8_t val;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint8(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy_consumed(ctx), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint8(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy_consumed(ctx), 0);
 }
 
 TEST(msgbuf, consumed_over)
@@ -528,10 +513,10 @@
     uint8_t valid;
     uint8_t invalid;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint8(ctx, valid), PLDM_SUCCESS);
-    EXPECT_NE(pldm_msgbuf_extract_uint8(ctx, invalid), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy_consumed(ctx), PLDM_ERROR_INVALID_LENGTH);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint8(ctx, valid), 0);
+    EXPECT_NE(pldm_msgbuf_extract_uint8(ctx, invalid), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy_consumed(ctx), -EBADMSG);
 }
 
 TEST(msgbuf, pldm_msgbuf_insert_int32_good)
@@ -542,19 +527,18 @@
     int32_t checkVal = 0;
     uint8_t buf[sizeof(int32_t)] = {};
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_insert_int32(ctx, src), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_insert_int32(ctx, src), 0);
 
     struct pldm_msgbuf _ctxExtract;
     struct pldm_msgbuf* ctxExtract = &_ctxExtract;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_int32(ctxExtract, checkVal), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_int32(ctxExtract, checkVal), 0);
 
     EXPECT_EQ(src, checkVal);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, insert_under_int32)
@@ -565,10 +549,10 @@
     int32_t buf[1] = {};
     int32_t val = 0;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN + sizeof(val) - 1;
-    EXPECT_NE(pldm_msgbuf_insert_int32(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_insert_int32(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, pldm_msgbuf_insert_uint32_good)
@@ -579,19 +563,18 @@
     uint32_t checkVal = 0;
     uint8_t buf[sizeof(uint32_t)] = {};
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_insert_uint32(ctx, src), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_insert_uint32(ctx, src), 0);
 
     struct pldm_msgbuf _ctxExtract;
     struct pldm_msgbuf* ctxExtract = &_ctxExtract;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint32(ctxExtract, checkVal), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint32(ctxExtract, checkVal), 0);
 
     EXPECT_EQ(src, checkVal);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, insert_under_uint32)
@@ -602,10 +585,10 @@
     uint32_t buf[1] = {};
     uint32_t val = 0;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN + sizeof(val) - 1;
-    EXPECT_NE(pldm_msgbuf_insert_uint32(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_insert_uint32(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, pldm_msgbuf_insert_uint16_good)
@@ -616,19 +599,18 @@
     uint16_t checkVal = 0;
     uint8_t buf[sizeof(uint16_t)] = {};
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(uint16_t)), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_insert_uint16(ctx, src), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(uint16_t)), 0);
+    EXPECT_EQ(pldm_msgbuf_insert_uint16(ctx, src), 0);
 
     struct pldm_msgbuf _ctxExtract;
     struct pldm_msgbuf* ctxExtract = &_ctxExtract;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint16(ctxExtract, checkVal), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint16(ctxExtract, checkVal), 0);
 
     EXPECT_EQ(src, checkVal);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, insert_under_uint16)
@@ -639,10 +621,10 @@
     uint16_t buf[1] = {};
     uint16_t val = 0;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN + sizeof(val) - 1;
-    EXPECT_NE(pldm_msgbuf_insert_uint16(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_insert_uint16(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, pldm_msgbuf_insert_int16_good)
@@ -653,19 +635,18 @@
     int16_t checkVal = 0;
     uint8_t buf[sizeof(int16_t)] = {};
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(uint16_t)), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_insert_int16(ctx, src), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(uint16_t)), 0);
+    EXPECT_EQ(pldm_msgbuf_insert_int16(ctx, src), 0);
 
     struct pldm_msgbuf _ctxExtract;
     struct pldm_msgbuf* ctxExtract = &_ctxExtract;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_int16(ctxExtract, checkVal), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_int16(ctxExtract, checkVal), 0);
 
     EXPECT_EQ(src, checkVal);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, insert_under_int16)
@@ -676,10 +657,10 @@
     int16_t buf[1] = {};
     int16_t val = 0;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN + sizeof(val) - 1;
-    EXPECT_NE(pldm_msgbuf_insert_int16(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_insert_int16(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, pldm_msgbuf_insert_uint8_good)
@@ -690,19 +671,18 @@
     uint8_t checkVal = 0;
     uint8_t buf[sizeof(uint8_t)] = {};
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_insert_uint8(ctx, src), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_insert_uint8(ctx, src), 0);
 
     struct pldm_msgbuf _ctxExtract;
     struct pldm_msgbuf* ctxExtract = &_ctxExtract;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint8(ctxExtract, checkVal), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint8(ctxExtract, checkVal), 0);
 
     EXPECT_EQ(src, checkVal);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, insert_under_uint8)
@@ -713,10 +693,10 @@
     uint8_t buf[1] = {};
     uint8_t val = 0;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN + sizeof(val) - 1;
-    EXPECT_NE(pldm_msgbuf_insert_uint8(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_insert_uint8(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, pldm_msgbuf_insert_int8_good)
@@ -727,19 +707,18 @@
     int8_t checkVal = 0;
     uint8_t buf[sizeof(int8_t)] = {};
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_insert_int8(ctx, src), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_insert_int8(ctx, src), 0);
 
     struct pldm_msgbuf _ctxExtract;
     struct pldm_msgbuf* ctxExtract = &_ctxExtract;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_int8(ctxExtract, checkVal), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_int8(ctxExtract, checkVal), 0);
 
     EXPECT_EQ(src, checkVal);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, insert_under_int8)
@@ -750,10 +729,10 @@
     int8_t buf[1] = {};
     int8_t val = 0;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN + sizeof(val) - 1;
-    EXPECT_NE(pldm_msgbuf_insert_int8(ctx, val), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_insert_int8(ctx, val), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, pldm_msgbuf_insert_array_uint8_good)
@@ -764,23 +743,21 @@
     uint8_t buf[6] = {};
     uint8_t retBuff[6] = {};
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
     EXPECT_EQ(
-        pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)),
-        PLDM_SUCCESS);
+        pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)), 0);
 
     struct pldm_msgbuf _ctxExtract;
     struct pldm_msgbuf* ctxExtract = &_ctxExtract;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)),
-              PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)), 0);
     EXPECT_EQ(pldm_msgbuf_extract_array_uint8(ctxExtract, sizeof(retBuff),
                                               retBuff, sizeof(retBuff)),
-              PLDM_SUCCESS);
+              0);
 
     EXPECT_EQ(memcmp(src, retBuff, sizeof(retBuff)), 0);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, insert_under_array_uint8)
@@ -791,12 +768,11 @@
     uint8_t buf[1] = {};
     uint8_t val[1] = {0};
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN + sizeof(val) - 1;
     EXPECT_NE(
-        pldm_msgbuf_insert_array_uint8(ctx, sizeof(val), val, sizeof(val)),
-        PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+        pldm_msgbuf_insert_array_uint8(ctx, sizeof(val), val, sizeof(val)), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, pldm_msgbuf_insert_array_char_good)
@@ -849,23 +825,21 @@
     uint16_t testVal;
     uint8_t* retBuff = NULL;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
     EXPECT_EQ(
-        pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)),
-        PLDM_SUCCESS);
+        pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)), 0);
 
     struct pldm_msgbuf _ctxExtract;
     struct pldm_msgbuf* ctxExtract = &_ctxExtract;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint16(ctxExtract, testVal), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint16(ctxExtract, testVal), 0);
     EXPECT_EQ(pldm_msgbuf_span_required(ctxExtract, required, (void**)&retBuff),
-              PLDM_SUCCESS);
+              0);
 
     EXPECT_EQ(memcmp(expectData, retBuff, required), 0);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, pldm_msgbuf_span_required_bad)
@@ -878,22 +852,19 @@
     uint16_t testVal;
     [[maybe_unused]] uint8_t* retBuff = NULL;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
     EXPECT_EQ(
-        pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)),
-        PLDM_SUCCESS);
+        pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)), 0);
 
     struct pldm_msgbuf _ctxExtract;
     struct pldm_msgbuf* ctxExtract = &_ctxExtract;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint16(ctxExtract, testVal), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_span_required(ctxExtract, required, NULL),
-              PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint16(ctxExtract, testVal), 0);
+    EXPECT_EQ(pldm_msgbuf_span_required(ctxExtract, required, NULL), 0);
 
-    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, span_required_under)
@@ -904,10 +875,10 @@
     uint8_t buf[1] = {};
     void* cursor = nullptr;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, 0), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, 0), 0);
     ctx->remaining = INTMAX_MIN;
-    EXPECT_NE(pldm_msgbuf_span_required(ctx, 1, &cursor), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_NE(pldm_msgbuf_span_required(ctx, 1, &cursor), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), -EOVERFLOW);
 }
 
 TEST(msgbuf, pldm_msgbuf_span_string_ascii_good)
@@ -1236,25 +1207,23 @@
     size_t remaining;
     uint8_t* retBuff = NULL;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
     EXPECT_EQ(
-        pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)),
-        PLDM_SUCCESS);
+        pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)), 0);
 
     struct pldm_msgbuf _ctxExtract;
     struct pldm_msgbuf* ctxExtract = &_ctxExtract;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint16(ctxExtract, testVal), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint16(ctxExtract, testVal), 0);
     EXPECT_EQ(
         pldm_msgbuf_span_remaining(ctxExtract, (void**)&retBuff, &remaining),
-        PLDM_SUCCESS);
+        0);
 
     EXPECT_EQ(remaining, sizeof(expectData));
     EXPECT_EQ(memcmp(expectData, retBuff, remaining), 0);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, pldm_msgbuf_span_remaining_bad)
@@ -1265,20 +1234,18 @@
     uint8_t buf[8] = {0};
     uint16_t testVal;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)), 0);
     EXPECT_EQ(
-        pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)),
-        PLDM_SUCCESS);
+        pldm_msgbuf_insert_array_uint8(ctx, sizeof(src), src, sizeof(src)), 0);
 
     struct pldm_msgbuf _ctxExtract;
     struct pldm_msgbuf* ctxExtract = &_ctxExtract;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint16(ctxExtract, testVal), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint16(ctxExtract, testVal), 0);
 
-    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(ctx), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctxExtract), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(ctx), 0);
 }
 
 TEST(msgbuf, pldm_msgbuf_copy_good)
@@ -1287,24 +1254,21 @@
     struct pldm_msgbuf* src = &_src;
     uint16_t buf[1] = {htole16(0x5aa5)};
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(src, sizeof(buf), buf, sizeof(buf)),
-              PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(src, sizeof(buf), buf, sizeof(buf)), 0);
 
     struct pldm_msgbuf _dst;
     struct pldm_msgbuf* dst = &_dst;
     uint16_t checkVal = 0;
     uint8_t buf1[sizeof(buf)] = {};
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(dst, sizeof(buf1), buf1, sizeof(buf1)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_copy(dst, src, buf[0], name), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(dst, sizeof(buf1), buf1, sizeof(buf1)), 0);
+    EXPECT_EQ(pldm_msgbuf_copy(dst, src, buf[0], name), 0);
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(dst, sizeof(buf1), buf1, sizeof(buf1)),
-              PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_extract_uint16(dst, checkVal), PLDM_SUCCESS);
+    ASSERT_EQ(pldm_msgbuf_init_errno(dst, sizeof(buf1), buf1, sizeof(buf1)), 0);
+    EXPECT_EQ(pldm_msgbuf_extract_uint16(dst, checkVal), 0);
 
-    EXPECT_EQ(pldm_msgbuf_destroy(src), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_destroy(dst), PLDM_SUCCESS);
+    EXPECT_EQ(pldm_msgbuf_destroy(src), 0);
+    EXPECT_EQ(pldm_msgbuf_destroy(dst), 0);
 
     EXPECT_EQ(buf[0], checkVal);
 }
@@ -1319,15 +1283,13 @@
     uint8_t buf1[1] = {sizeof(uint16_t)};
     uint16_t value = 8;
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(src, 0, buf, sizeof(buf)), PLDM_SUCCESS);
-    ASSERT_EQ(pldm_msgbuf_init_cc(dst, 0, buf1, sizeof(buf1)), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_copy(dst, src, value, name),
-              PLDM_ERROR_INVALID_LENGTH);
+    ASSERT_EQ(pldm_msgbuf_init_errno(src, 0, buf, sizeof(buf)), 0);
+    ASSERT_EQ(pldm_msgbuf_init_errno(dst, 0, buf1, sizeof(buf1)), 0);
+    EXPECT_EQ(pldm_msgbuf_copy(dst, src, value, name), -EOVERFLOW);
 
-    ASSERT_EQ(pldm_msgbuf_init_cc(src, 0, buf1, sizeof(buf1)), PLDM_SUCCESS);
-    ASSERT_EQ(pldm_msgbuf_init_cc(dst, 0, buf, sizeof(buf)), PLDM_SUCCESS);
-    EXPECT_EQ(pldm_msgbuf_copy(dst, src, value, name),
-              PLDM_ERROR_INVALID_LENGTH);
+    ASSERT_EQ(pldm_msgbuf_init_errno(src, 0, buf1, sizeof(buf1)), 0);
+    ASSERT_EQ(pldm_msgbuf_init_errno(dst, 0, buf, sizeof(buf)), 0);
+    EXPECT_EQ(pldm_msgbuf_copy(dst, src, value, name), -EOVERFLOW);
 }
 
 TEST(msgbuf, pldm_msgbuf_copy_string_ascii_exact)