msgbuf: Define a separate msgbuf structure for encode/decode function

Define separate msgbuf structures to avoid casting away const-qualifiers
in the msgbuf constructor function:

* pldm_msgbuf_rw: for encode functions with non const-qualified buffer
* pldm_msgbuf_ro: for decode functions with const-qualified buffer

Further, use _Generic() to keep the API ergonomic while still yielding a
compile error when wrong msgbuf type is passed.

Change-Id: I71dbcb7996e9fb402b49870fce539a939c1497e5
Signed-off-by: John Chung <john.chung@arm.com>
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/src/dsp/file.c b/src/dsp/file.c
index 07a283c..f22e977 100644
--- a/src/dsp/file.c
+++ b/src/dsp/file.c
@@ -18,7 +18,7 @@
 				 const struct pldm_file_df_open_req *req,
 				 struct pldm_msg *msg, size_t *payload_length)
 {
-	PLDM_MSGBUF_DEFINE_P(buf);
+	PLDM_MSGBUF_RW_DEFINE_P(buf);
 	int rc;
 
 	if (req == NULL || msg == NULL) {
@@ -53,7 +53,7 @@
 				 size_t payload_length,
 				 struct pldm_file_df_open_req *req)
 {
-	PLDM_MSGBUF_DEFINE_P(buf);
+	PLDM_MSGBUF_RO_DEFINE_P(buf);
 	int rc;
 
 	if (!msg || !req) {
@@ -77,7 +77,7 @@
 				  const struct pldm_file_df_open_resp *resp,
 				  struct pldm_msg *msg, size_t *payload_length)
 {
-	PLDM_MSGBUF_DEFINE_P(buf);
+	PLDM_MSGBUF_RW_DEFINE_P(buf);
 	int rc;
 
 	if (!msg || !resp) {
@@ -114,7 +114,7 @@
 				  size_t payload_length,
 				  struct pldm_file_df_open_resp *resp)
 {
-	PLDM_MSGBUF_DEFINE_P(buf);
+	PLDM_MSGBUF_RO_DEFINE_P(buf);
 	int rc;
 
 	if (!msg || !resp) {
@@ -149,7 +149,7 @@
 				  const struct pldm_file_df_close_req *req,
 				  struct pldm_msg *msg, size_t *payload_length)
 {
-	PLDM_MSGBUF_DEFINE_P(buf);
+	PLDM_MSGBUF_RW_DEFINE_P(buf);
 	int rc;
 
 	if (!req || !msg) {
@@ -184,7 +184,7 @@
 				  size_t payload_length,
 				  struct pldm_file_df_close_req *req)
 {
-	PLDM_MSGBUF_DEFINE_P(buf);
+	PLDM_MSGBUF_RO_DEFINE_P(buf);
 	int rc;
 
 	if (!msg || !req) {
@@ -208,7 +208,7 @@
 				   const struct pldm_file_df_close_resp *resp,
 				   struct pldm_msg *msg, size_t *payload_length)
 {
-	PLDM_MSGBUF_DEFINE_P(buf);
+	PLDM_MSGBUF_RW_DEFINE_P(buf);
 	int rc;
 
 	if (!msg || !resp) {
@@ -256,7 +256,7 @@
 	uint8_t instance_id, const struct pldm_file_df_heartbeat_req *req,
 	struct pldm_msg *msg, size_t *payload_length)
 {
-	PLDM_MSGBUF_DEFINE_P(buf);
+	PLDM_MSGBUF_RW_DEFINE_P(buf);
 	int rc;
 
 	if (!req || !msg) {
@@ -291,7 +291,7 @@
 				       size_t payload_length,
 				       struct pldm_file_df_heartbeat_resp *resp)
 {
-	PLDM_MSGBUF_DEFINE_P(buf);
+	PLDM_MSGBUF_RO_DEFINE_P(buf);
 	int rc;
 
 	if (!msg || !resp) {