compiler: Provide LIBPLDM_CC_ALWAYS_INLINE

Using it through the code-base reduces some of the source noise, and
gives us a way to control the definition going forward.

Change-Id: I27e76cbae5c45f0efd64b01fb9a8b243a6c8e65d
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/src/compiler.h b/src/compiler.h
index e704518..3657471 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -9,12 +9,15 @@
 #include <assert.h>
 
 static struct {
+	static_assert(__has_attribute(always_inline),
+		      "`always_inline` attribute is required");
 	static_assert(__has_attribute(unused),
 		      "`unused` attribute is required");
 	int compliance;
 } pldm_required_attributes __attribute__((unused));
 
-#define LIBPLDM_CC_UNUSED __attribute__((unused))
+#define LIBPLDM_CC_ALWAYS_INLINE __attribute__((always_inline)) static inline
+#define LIBPLDM_CC_UNUSED	 __attribute__((unused))
 
 // NOLINTBEGIN(bugprone-macro-parentheses)
 /**
diff --git a/src/msgbuf.h b/src/msgbuf.h
index 16e3680..b4fd677 100644
--- a/src/msgbuf.h
+++ b/src/msgbuf.h
@@ -98,8 +98,8 @@
  *         `PLDM_MSGBUF_C_ERRNO`, or the equivalent PLDM completion code if the
  *         error mode is `PLDM_MSGBUF_PLDM_CC`.
  */
-__attribute__((always_inline)) static inline int
-pldm_msgbuf_status(struct pldm_msgbuf *ctx, unsigned int err)
+LIBPLDM_CC_ALWAYS_INLINE int pldm_msgbuf_status(struct pldm_msgbuf *ctx,
+						unsigned int err)
 {
 	int rc;
 
@@ -150,7 +150,7 @@
  * @return 0 on success, otherwise an error code appropriate for the current
  *         personality.
  */
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 // 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)
@@ -197,9 +197,9 @@
  *         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)
+LIBPLDM_CC_ALWAYS_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;
@@ -223,9 +223,9 @@
  *         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)
+LIBPLDM_CC_ALWAYS_INLINE int pldm_msgbuf_init_errno(struct pldm_msgbuf *ctx,
+						    size_t minsize,
+						    const void *buf, size_t len)
 {
 	if (!ctx) {
 		return -EINVAL;
@@ -246,8 +246,7 @@
  * PLDM_ERROR_INVALID_DATA indicates that the provided context was not a valid
  * pointer.
  */
-__attribute__((always_inline)) static inline int
-pldm_msgbuf_validate(struct pldm_msgbuf *ctx)
+LIBPLDM_CC_ALWAYS_INLINE int pldm_msgbuf_validate(struct pldm_msgbuf *ctx)
 {
 	assert(ctx);
 	if (ctx->remaining < 0) {
@@ -268,8 +267,7 @@
  * PLDM_ERROR_INVALID_DATA indicates that the provided context was not a valid
  * pointer.
  */
-__attribute__((always_inline)) static inline int
-pldm_msgbuf_consumed(struct pldm_msgbuf *ctx)
+LIBPLDM_CC_ALWAYS_INLINE int pldm_msgbuf_consumed(struct pldm_msgbuf *ctx)
 {
 	assert(ctx);
 	if (ctx->remaining != 0) {
@@ -289,8 +287,7 @@
  * PLDM_ERROR_INVALID_LENGTH if prior accesses would have occurred beyond the
  * bounds of the buffer.
  */
-__attribute__((always_inline)) static inline int
-pldm_msgbuf_destroy(struct pldm_msgbuf *ctx)
+LIBPLDM_CC_ALWAYS_INLINE int pldm_msgbuf_destroy(struct pldm_msgbuf *ctx)
 {
 	int valid;
 
@@ -314,7 +311,7 @@
  * parameter is invalid, or PLDM_ERROR_INVALID_LENGTH if prior accesses would
  * have occurred byond the bounds of the buffer
  */
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 pldm_msgbuf_destroy_consumed(struct pldm_msgbuf *ctx)
 {
 	int consumed;
@@ -428,7 +425,7 @@
 #define pldm_msgbuf_extract_uint8(ctx, dst)                                    \
 	pldm_msgbuf_extract_typecheck(uint8_t, pldm__msgbuf_extract_uint8,     \
 				      dst, ctx, dst)
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 // NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
 pldm__msgbuf_extract_uint8(struct pldm_msgbuf *ctx, void *dst)
 {
@@ -457,7 +454,7 @@
 #define pldm_msgbuf_extract_int8(ctx, dst)                                     \
 	pldm_msgbuf_extract_typecheck(int8_t, pldm__msgbuf_extract_int8, dst,  \
 				      ctx, dst)
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 // NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
 pldm__msgbuf_extract_int8(struct pldm_msgbuf *ctx, void *dst)
 {
@@ -485,7 +482,7 @@
 #define pldm_msgbuf_extract_uint16(ctx, dst)                                   \
 	pldm_msgbuf_extract_typecheck(uint16_t, pldm__msgbuf_extract_uint16,   \
 				      dst, ctx, dst)
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 // NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
 pldm__msgbuf_extract_uint16(struct pldm_msgbuf *ctx, void *dst)
 {
@@ -538,7 +535,7 @@
 #define pldm_msgbuf_extract_int16(ctx, dst)                                    \
 	pldm_msgbuf_extract_typecheck(int16_t, pldm__msgbuf_extract_int16,     \
 				      dst, ctx, dst)
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 // NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
 pldm__msgbuf_extract_int16(struct pldm_msgbuf *ctx, void *dst)
 {
@@ -576,7 +573,7 @@
 #define pldm_msgbuf_extract_uint32(ctx, dst)                                   \
 	pldm_msgbuf_extract_typecheck(uint32_t, pldm__msgbuf_extract_uint32,   \
 				      dst, ctx, dst)
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 // NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
 pldm__msgbuf_extract_uint32(struct pldm_msgbuf *ctx, void *dst)
 {
@@ -613,7 +610,7 @@
 #define pldm_msgbuf_extract_int32(ctx, dst)                                    \
 	pldm_msgbuf_extract_typecheck(int32_t, pldm__msgbuf_extract_int32,     \
 				      dst, ctx, dst)
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 // NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
 pldm__msgbuf_extract_int32(struct pldm_msgbuf *ctx, void *dst)
 {
@@ -650,7 +647,7 @@
 #define pldm_msgbuf_extract_real32(ctx, dst)                                   \
 	pldm_msgbuf_extract_typecheck(real32_t, pldm__msgbuf_extract_real32,   \
 				      dst, ctx, dst)
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 // NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
 pldm__msgbuf_extract_real32(struct pldm_msgbuf *ctx, void *dst)
 {
@@ -725,7 +722,7 @@
 		int32_t *: pldm__msgbuf_extract_int32,                         \
 		real32_t *: pldm__msgbuf_extract_real32)(ctx, dst)
 
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 // NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
 pldm__msgbuf_extract_array_void(struct pldm_msgbuf *ctx, void *dst,
 				size_t count)
@@ -761,13 +758,13 @@
 	return 0;
 }
 
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 pldm_msgbuf_extract_array_char(struct pldm_msgbuf *ctx, char *dst, size_t count)
 {
 	return pldm__msgbuf_extract_array_void(ctx, dst, count);
 }
 
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 pldm_msgbuf_extract_array_uint8(struct pldm_msgbuf *ctx, uint8_t *dst,
 				size_t count)
 {
@@ -779,8 +776,8 @@
 		uint8_t: pldm_msgbuf_extract_array_uint8,                      \
 		char: pldm_msgbuf_extract_array_char)(ctx, dst, count)
 
-__attribute__((always_inline)) static inline int
-pldm_msgbuf_insert_uint32(struct pldm_msgbuf *ctx, const uint32_t src)
+LIBPLDM_CC_ALWAYS_INLINE int pldm_msgbuf_insert_uint32(struct pldm_msgbuf *ctx,
+						       const uint32_t src)
 {
 	uint32_t val = htole32(src);
 
@@ -810,8 +807,8 @@
 	return 0;
 }
 
-__attribute__((always_inline)) static inline int
-pldm_msgbuf_insert_uint16(struct pldm_msgbuf *ctx, const uint16_t src)
+LIBPLDM_CC_ALWAYS_INLINE int pldm_msgbuf_insert_uint16(struct pldm_msgbuf *ctx,
+						       const uint16_t src)
 {
 	uint16_t val = htole16(src);
 
@@ -841,8 +838,8 @@
 	return 0;
 }
 
-__attribute__((always_inline)) static inline int
-pldm_msgbuf_insert_uint8(struct pldm_msgbuf *ctx, const uint8_t src)
+LIBPLDM_CC_ALWAYS_INLINE int pldm_msgbuf_insert_uint8(struct pldm_msgbuf *ctx,
+						      const uint8_t src)
 {
 	assert(ctx);
 
@@ -870,8 +867,8 @@
 	return 0;
 }
 
-__attribute__((always_inline)) static inline int
-pldm_msgbuf_insert_int32(struct pldm_msgbuf *ctx, const int32_t src)
+LIBPLDM_CC_ALWAYS_INLINE int pldm_msgbuf_insert_int32(struct pldm_msgbuf *ctx,
+						      const int32_t src)
 {
 	int32_t val = htole32(src);
 
@@ -901,8 +898,8 @@
 	return 0;
 }
 
-__attribute__((always_inline)) static inline int
-pldm_msgbuf_insert_int16(struct pldm_msgbuf *ctx, const int16_t src)
+LIBPLDM_CC_ALWAYS_INLINE int pldm_msgbuf_insert_int16(struct pldm_msgbuf *ctx,
+						      const int16_t src)
 {
 	int16_t val = htole16(src);
 
@@ -932,8 +929,8 @@
 	return 0;
 }
 
-__attribute__((always_inline)) static inline int
-pldm_msgbuf_insert_int8(struct pldm_msgbuf *ctx, const int8_t src)
+LIBPLDM_CC_ALWAYS_INLINE int pldm_msgbuf_insert_int8(struct pldm_msgbuf *ctx,
+						     const int8_t src)
 {
 	assert(ctx);
 
@@ -970,7 +967,7 @@
 		uint32_t: pldm_msgbuf_insert_uint32,                           \
 		int32_t: pldm_msgbuf_insert_int32)(dst, src)
 
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 // NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
 pldm__msgbuf_insert_array_void(struct pldm_msgbuf *ctx, const void *src,
 			       size_t count)
@@ -1006,14 +1003,14 @@
 	return 0;
 }
 
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 pldm_msgbuf_insert_array_char(struct pldm_msgbuf *ctx, const char *src,
 			      size_t count)
 {
 	return pldm__msgbuf_insert_array_void(ctx, src, count);
 }
 
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 pldm_msgbuf_insert_array_uint8(struct pldm_msgbuf *ctx, const uint8_t *src,
 			       size_t count)
 {
@@ -1025,9 +1022,9 @@
 		uint8_t: pldm_msgbuf_insert_array_uint8,                       \
 		char: pldm_msgbuf_insert_array_char)(dst, src, count)
 
-__attribute__((always_inline)) static inline int
-pldm_msgbuf_span_required(struct pldm_msgbuf *ctx, size_t required,
-			  void **cursor)
+LIBPLDM_CC_ALWAYS_INLINE int pldm_msgbuf_span_required(struct pldm_msgbuf *ctx,
+						       size_t required,
+						       void **cursor)
 {
 	assert(ctx);
 
@@ -1056,7 +1053,7 @@
 	return 0;
 }
 
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 pldm_msgbuf_span_string_ascii(struct pldm_msgbuf *ctx, void **cursor,
 			      size_t *length)
 {
@@ -1111,7 +1108,7 @@
 	return 0;
 }
 
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 pldm_msgbuf_span_string_utf16(struct pldm_msgbuf *ctx, void **cursor,
 			      size_t *length)
 {
@@ -1192,7 +1189,7 @@
 	return 0;
 }
 
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 pldm_msgbuf_span_remaining(struct pldm_msgbuf *ctx, void **cursor, size_t *len)
 {
 	assert(ctx);
@@ -1228,7 +1225,7 @@
  */
 #define pldm_msgbuf_copy(dst, src, type, name)                                 \
 	pldm__msgbuf_copy(dst, src, sizeof(type), #name)
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 // NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
 pldm__msgbuf_copy(struct pldm_msgbuf *dst, struct pldm_msgbuf *src, size_t size,
 		  const char *description)
@@ -1274,7 +1271,7 @@
 	return 0;
 }
 
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 pldm_msgbuf_copy_string_ascii(struct pldm_msgbuf *dst, struct pldm_msgbuf *src)
 {
 	void *ascii = NULL;
@@ -1289,7 +1286,7 @@
 	return pldm__msgbuf_insert_array_void(dst, ascii, len);
 }
 
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 pldm_msgbuf_copy_string_utf16(struct pldm_msgbuf *dst, struct pldm_msgbuf *src)
 {
 	void *utf16 = NULL;
diff --git a/src/msgbuf/platform.h b/src/msgbuf/platform.h
index c52a66d..11f0900 100644
--- a/src/msgbuf/platform.h
+++ b/src/msgbuf/platform.h
@@ -2,6 +2,7 @@
 #ifndef PLDM_MSGBUF_PLATFORM_H
 #define PLDM_MSGBUF_PLATFORM_H
 
+#include "../compiler.h"
 #include "../msgbuf.h"
 #include <libpldm/base.h>
 #include <libpldm/platform.h>
@@ -19,14 +20,7 @@
 	return pldm_msgbuf_validate(ctx);
 }
 
-/*
- * We use __attribute__((always_inline)) below so the compiler has visibility of
- * the switch() at the call site. It is often the case that the size of multiple
- * fields depends on the tag. Inlining thus gives the compiler visibility to
- * hoist one tag-based code-path condition to cover all invocations.
- */
-
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 pldm_msgbuf_extract_sensor_data(struct pldm_msgbuf *ctx,
 				enum pldm_sensor_readings_data_type tag,
 				union_sensor_data_size *dst)
@@ -54,7 +48,7 @@
  * have used the approach used by callers of pldm_msgbuf_extract_sensor_data()
  * above
  */
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 pldm_msgbuf_extract_sensor_value(struct pldm_msgbuf *ctx,
 				 enum pldm_sensor_readings_data_type tag,
 				 void *val)
@@ -81,10 +75,8 @@
 	pldm_msgbuf_extract_typecheck(union_range_field_format,                \
 				      pldm__msgbuf_extract_range_field_format, \
 				      dst, ctx, tag, (void *)&(dst))
-__attribute__((always_inline)) static inline int
-pldm__msgbuf_extract_range_field_format(struct pldm_msgbuf *ctx,
-					enum pldm_range_field_format tag,
-					void *rff)
+LIBPLDM_CC_ALWAYS_INLINE int pldm__msgbuf_extract_range_field_format(
+	struct pldm_msgbuf *ctx, enum pldm_range_field_format tag, void *rff)
 {
 	switch (tag) {
 	case PLDM_RANGE_FIELD_FORMAT_UINT8:
@@ -121,7 +113,7 @@
 }
 
 /* This API is bad, but it's because the caller's APIs are also bad */
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 pldm_msgbuf_extract_effecter_value(struct pldm_msgbuf *ctx,
 				   enum pldm_effecter_data_size tag, void *dst)
 {
@@ -147,7 +139,7 @@
 	pldm_msgbuf_extract_typecheck(union_effecter_data_size,                \
 				      pldm__msgbuf_extract_range_field_format, \
 				      dst, ctx, tag, (void *)&(dst))
-__attribute__((always_inline)) static inline int
+LIBPLDM_CC_ALWAYS_INLINE int
 pldm__msgbuf_extract_effecter_data(struct pldm_msgbuf *ctx,
 				   enum pldm_effecter_data_size tag, void *ed)
 {