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_generic.c b/tests/msgbuf_generic.c
index 32b9ed9..4ae9a2f 100644
--- a/tests/msgbuf_generic.c
+++ b/tests/msgbuf_generic.c
@@ -33,11 +33,10 @@
uint8_t buf[1] = {0xa5};
uint8_t val;
- expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) ==
- PLDM_SUCCESS);
- expect(pldm_msgbuf_extract(ctx, val) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_extract(ctx, val) == 0);
expect(val == 0xa5);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
static void test_msgbuf_extract_generic_int8(void)
@@ -47,11 +46,10 @@
int8_t buf[1] = {-1};
int8_t val;
- expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) ==
- PLDM_SUCCESS);
- expect(pldm_msgbuf_extract(ctx, val) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_extract(ctx, val) == 0);
expect(val == -1);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
static void test_msgbuf_extract_generic_uint16(void)
@@ -61,11 +59,10 @@
uint16_t buf[1] = {0x5aa5};
uint16_t val;
- expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) ==
- PLDM_SUCCESS);
- expect(pldm_msgbuf_extract(ctx, val) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_extract(ctx, val) == 0);
expect(val == 0x5aa5);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
static void test_msgbuf_extract_generic_int16(void)
@@ -75,11 +72,10 @@
int16_t buf[1] = {(int16_t)(htole16((uint16_t)INT16_MIN))};
int16_t val;
- expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) ==
- PLDM_SUCCESS);
- expect(pldm_msgbuf_extract(ctx, val) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_extract(ctx, val) == 0);
expect(val == INT16_MIN);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
static void test_msgbuf_extract_generic_uint32(void)
@@ -89,11 +85,10 @@
uint32_t buf[1] = {0x5a00ffa5};
uint32_t val;
- expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) ==
- PLDM_SUCCESS);
- expect(pldm_msgbuf_extract(ctx, val) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_extract(ctx, val) == 0);
expect(val == 0x5a00ffa5);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
static void test_msgbuf_extract_generic_int32(void)
@@ -103,11 +98,10 @@
int32_t buf[1] = {(int32_t)(htole32((uint32_t)INT32_MIN))};
int32_t val;
- expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) ==
- PLDM_SUCCESS);
- expect(pldm_msgbuf_extract(ctx, val) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_extract(ctx, val) == 0);
expect(val == INT32_MIN);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
static void test_msgbuf_extract_generic_real32(void)
@@ -123,11 +117,10 @@
buf[0] = htole32(xform);
val = 0;
- expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) ==
- PLDM_SUCCESS);
- expect(pldm_msgbuf_extract(ctx, val) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_extract(ctx, val) == 0);
expect(val == FLT_MAX);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
static void test_msgbuf_extract_array_generic_uint8(void)
@@ -137,11 +130,10 @@
uint32_t buf[1] = {0};
uint8_t arr[1];
- expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) ==
- PLDM_SUCCESS);
- expect(pldm_msgbuf_extract_array(ctx, 1, arr, 1) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, sizeof(buf), buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_extract_array(ctx, 1, arr, 1) == 0);
expect(arr[0] == 0);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
static void test_msgbuf_insert_generic_int32(void)
@@ -152,19 +144,18 @@
int32_t checkVal = 0;
uint8_t buf[sizeof(int32_t)] = {0};
- expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)) == PLDM_SUCCESS);
- expect(pldm_msgbuf_insert(ctx, src) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_insert(ctx, src) == 0);
struct pldm_msgbuf _ctxExtract;
struct pldm_msgbuf* ctxExtract = &_ctxExtract;
- expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) ==
- PLDM_SUCCESS);
- expect(pldm_msgbuf_extract(ctxExtract, checkVal) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_extract(ctxExtract, checkVal) == 0);
expect(src == checkVal);
- expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctxExtract) == 0);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
static void test_msgbuf_insert_generic_uint32(void)
@@ -175,19 +166,18 @@
uint32_t checkVal = 0;
uint8_t buf[sizeof(uint32_t)] = {0};
- expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)) == PLDM_SUCCESS);
- expect(pldm_msgbuf_insert(ctx, src) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_insert(ctx, src) == 0);
struct pldm_msgbuf _ctxExtract;
struct pldm_msgbuf* ctxExtract = &_ctxExtract;
- expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) ==
- PLDM_SUCCESS);
- expect(pldm_msgbuf_extract(ctxExtract, checkVal) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_extract(ctxExtract, checkVal) == 0);
expect(src == checkVal);
- expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctxExtract) == 0);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
static void test_msgbuf_insert_generic_uint16(void)
@@ -198,19 +188,18 @@
uint16_t checkVal = 0;
uint8_t buf[sizeof(uint16_t)] = {0};
- expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(uint16_t)) == PLDM_SUCCESS);
- expect(pldm_msgbuf_insert(ctx, src) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(uint16_t)) == 0);
+ expect(pldm_msgbuf_insert(ctx, src) == 0);
struct pldm_msgbuf _ctxExtract;
struct pldm_msgbuf* ctxExtract = &_ctxExtract;
- expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) ==
- PLDM_SUCCESS);
- expect(pldm_msgbuf_extract(ctxExtract, checkVal) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_extract(ctxExtract, checkVal) == 0);
expect(src == checkVal);
- expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctxExtract) == 0);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
static void test_msgbuf_insert_generic_int16(void)
@@ -221,19 +210,18 @@
int16_t checkVal = 0;
uint8_t buf[sizeof(int16_t)] = {0};
- expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(uint16_t)) == PLDM_SUCCESS);
- expect(pldm_msgbuf_insert(ctx, src) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(uint16_t)) == 0);
+ expect(pldm_msgbuf_insert(ctx, src) == 0);
struct pldm_msgbuf _ctxExtract;
struct pldm_msgbuf* ctxExtract = &_ctxExtract;
- expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) ==
- PLDM_SUCCESS);
- expect(pldm_msgbuf_extract(ctxExtract, checkVal) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_extract(ctxExtract, checkVal) == 0);
expect(src == checkVal);
- expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctxExtract) == 0);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
static void test_msgbuf_insert_generic_uint8(void)
@@ -244,19 +232,18 @@
uint8_t checkVal = 0;
uint8_t buf[sizeof(uint8_t)] = {0};
- expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)) == PLDM_SUCCESS);
- expect(pldm_msgbuf_insert(ctx, src) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_insert(ctx, src) == 0);
struct pldm_msgbuf _ctxExtract;
struct pldm_msgbuf* ctxExtract = &_ctxExtract;
- expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) ==
- PLDM_SUCCESS);
- expect(pldm_msgbuf_extract(ctxExtract, checkVal) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_extract(ctxExtract, checkVal) == 0);
expect(src == checkVal);
- expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctxExtract) == 0);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
static void test_msgbuf_insert_generic_int8(void)
@@ -267,19 +254,18 @@
int8_t checkVal = 0;
uint8_t buf[sizeof(int8_t)] = {0};
- expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)) == PLDM_SUCCESS);
- expect(pldm_msgbuf_insert(ctx, src) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_insert(ctx, src) == 0);
struct pldm_msgbuf _ctxExtract;
struct pldm_msgbuf* ctxExtract = &_ctxExtract;
- expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) ==
- PLDM_SUCCESS);
- expect(pldm_msgbuf_extract(ctxExtract, checkVal) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_extract(ctxExtract, checkVal) == 0);
expect(src == checkVal);
- expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctxExtract) == 0);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
static void test_msgbuf_insert_array_generic_uint8(void)
@@ -290,21 +276,19 @@
uint8_t buf[6] = {0};
uint8_t retBuff[6] = {0};
- expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)) == PLDM_SUCCESS);
- expect(pldm_msgbuf_insert_array(ctx, sizeof(src), src, sizeof(src)) ==
- PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctx, 0, buf, sizeof(buf)) == 0);
+ expect(pldm_msgbuf_insert_array(ctx, sizeof(src), src, sizeof(src)) == 0);
struct pldm_msgbuf _ctxExtract;
struct pldm_msgbuf* ctxExtract = &_ctxExtract;
- expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) ==
- PLDM_SUCCESS);
+ expect(pldm_msgbuf_init_errno(ctxExtract, 0, buf, sizeof(buf)) == 0);
expect(pldm_msgbuf_extract_array(ctxExtract, sizeof(retBuff), retBuff,
- sizeof(retBuff)) == PLDM_SUCCESS);
+ sizeof(retBuff)) == 0);
expect(memcmp(src, retBuff, sizeof(retBuff)) == 0);
- expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS);
- expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS);
+ expect(pldm_msgbuf_destroy(ctxExtract) == 0);
+ expect(pldm_msgbuf_destroy(ctx) == 0);
}
typedef void (*testfn)(void);