From 42025e551a8cef8333ea6cdfe4b08600ccb0ee99 Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Fri, 18 Feb 2022 15:30:49 +0100 Subject: [PATCH] ipc: Added const specifier to protect IPC message content in sending functions. Added the const specifier to protect the message passed to ipc_platform_send_msg and ipc_prepare_to_send functions. The deletion of the message from the list has been moved to ipc_send_queued_msg function. Signed-off-by: Adrian Warecki --- src/drivers/amd/renoir/ipc.c | 4 ++-- src/drivers/imx/ipc.c | 4 ++-- src/drivers/intel/baytrail/ipc.c | 4 ++-- src/drivers/intel/cavs/ipc.c | 3 +-- src/drivers/intel/cavs/sue-ipc.c | 4 ++-- src/drivers/intel/haswell/ipc.c | 4 ++-- src/drivers/mediatek/mt8186/ipc.c | 4 ++-- src/drivers/mediatek/mt8195/ipc.c | 4 ++-- src/include/sof/ipc/common.h | 2 +- src/include/sof/ipc/driver.h | 2 +- src/ipc/ipc-common.c | 5 +++-- src/ipc/ipc3/handler.c | 2 +- src/ipc/ipc4/handler.c | 2 +- src/platform/library/include/platform/platform.h | 2 +- test/cmocka/src/common_mocks.c | 2 +- 15 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/drivers/amd/renoir/ipc.c b/src/drivers/amd/renoir/ipc.c index 5a7a301bb..c869b11ea 100644 --- a/src/drivers/amd/renoir/ipc.c +++ b/src/drivers/amd/renoir/ipc.c @@ -166,7 +166,7 @@ void ipc_platform_complete_cmd(struct ipc *ipc) } } -int ipc_platform_send_msg(struct ipc_msg *msg) +int ipc_platform_send_msg(const struct ipc_msg *msg) { int ret = 0; acp_sw_intr_trig_t sw_intr_trig; @@ -198,7 +198,7 @@ int ipc_platform_send_msg(struct ipc_msg *msg) goto out; /* Write new message in the mailbox */ mailbox_dspbox_write(0, msg->tx_data, msg->tx_size); - list_item_del(&msg->list); + /* Need to set DSP message flag */ sof_ipc_dsp_msg_set(); /* now interrupt host to tell it we have sent a message */ diff --git a/src/drivers/imx/ipc.c b/src/drivers/imx/ipc.c index 17859d6e5..8b77ec414 100644 --- a/src/drivers/imx/ipc.c +++ b/src/drivers/imx/ipc.c @@ -123,7 +123,7 @@ void ipc_platform_complete_cmd(struct ipc *ipc) } } -int ipc_platform_send_msg(struct ipc_msg *msg) +int ipc_platform_send_msg(const struct ipc_msg *msg) { struct ipc *ipc = ipc_get(); int ret = 0; @@ -137,7 +137,7 @@ int ipc_platform_send_msg(struct ipc_msg *msg) /* now send the message */ mailbox_dspbox_write(0, msg->tx_data, msg->tx_size); - list_item_del(&msg->list); + tr_dbg(&ipc_tr, "ipc: msg tx -> 0x%x", msg->header); ipc->is_notification_pending = true; diff --git a/src/drivers/intel/baytrail/ipc.c b/src/drivers/intel/baytrail/ipc.c index a66da6f39..eed1e9ba5 100644 --- a/src/drivers/intel/baytrail/ipc.c +++ b/src/drivers/intel/baytrail/ipc.c @@ -111,7 +111,7 @@ void ipc_platform_complete_cmd(struct ipc *ipc) shim_write(SHIM_IMRD, shim_read(SHIM_IMRD) & ~SHIM_IMRD_BUSY); } -int ipc_platform_send_msg(struct ipc_msg *msg) +int ipc_platform_send_msg(const struct ipc_msg *msg) { struct ipc *ipc = ipc_get(); int ret = 0; @@ -125,7 +125,7 @@ int ipc_platform_send_msg(struct ipc_msg *msg) /* now send the message */ mailbox_dspbox_write(0, msg->tx_data, msg->tx_size); - list_item_del(&msg->list); + tr_dbg(&ipc_tr, "ipc: msg tx -> 0x%x", msg->header); ipc->is_notification_pending = true; diff --git a/src/drivers/intel/cavs/ipc.c b/src/drivers/intel/cavs/ipc.c index 8176fbdef..860264867 100644 --- a/src/drivers/intel/cavs/ipc.c +++ b/src/drivers/intel/cavs/ipc.c @@ -214,7 +214,7 @@ void ipc_platform_complete_cmd(struct ipc *ipc) ipc_write(IPC_DIPCCTL, ipc_read(IPC_DIPCCTL) | IPC_DIPCCTL_IPCTBIE); } -int ipc_platform_send_msg(struct ipc_msg *msg) +int ipc_platform_send_msg(const struct ipc_msg *msg) { struct ipc *ipc = ipc_get(); ipc_cmd_hdr *hdr; @@ -231,7 +231,6 @@ int ipc_platform_send_msg(struct ipc_msg *msg) goto out; } - list_item_del(&msg->list); tr_dbg(&ipc_tr, "ipc: msg tx -> 0x%x", msg->header); ipc->is_notification_pending = true; diff --git a/src/drivers/intel/cavs/sue-ipc.c b/src/drivers/intel/cavs/sue-ipc.c index 2bcaf31a0..45d2a16a9 100644 --- a/src/drivers/intel/cavs/sue-ipc.c +++ b/src/drivers/intel/cavs/sue-ipc.c @@ -65,11 +65,11 @@ void ipc_platform_complete_cmd(struct ipc *ipc) { } -int ipc_platform_send_msg(struct ipc_msg *msg) +int ipc_platform_send_msg(const struct ipc_msg *msg) { /* now send the message */ mailbox_dspbox_write(0, msg->tx_data, msg->tx_size); - list_item_del(&msg->list); + tr_dbg(&ipc_tr, "ipc: msg tx -> 0x%x", msg->header); /* now interrupt host to tell it we have message sent */ diff --git a/src/drivers/intel/haswell/ipc.c b/src/drivers/intel/haswell/ipc.c index a12141cf7..e78ff6dbf 100644 --- a/src/drivers/intel/haswell/ipc.c +++ b/src/drivers/intel/haswell/ipc.c @@ -113,7 +113,7 @@ void ipc_platform_complete_cmd(struct ipc *ipc) } -int ipc_platform_send_msg(struct ipc_msg *msg) +int ipc_platform_send_msg(const struct ipc_msg *msg) { struct ipc *ipc = ipc_get(); int ret = 0; @@ -127,7 +127,7 @@ int ipc_platform_send_msg(struct ipc_msg *msg) /* now send the message */ mailbox_dspbox_write(0, msg->tx_data, msg->tx_size); - list_item_del(&msg->list); + tr_dbg(&ipc_tr, "ipc: msg tx -> 0x%x", msg->header); ipc->is_notification_pending = true; diff --git a/src/drivers/mediatek/mt8186/ipc.c b/src/drivers/mediatek/mt8186/ipc.c index 9f6acbd52..7240ef0fd 100644 --- a/src/drivers/mediatek/mt8186/ipc.c +++ b/src/drivers/mediatek/mt8186/ipc.c @@ -89,7 +89,7 @@ void ipc_platform_complete_cmd(struct ipc *ipc) wait_for_interrupt(0); } -int ipc_platform_send_msg(struct ipc_msg *msg) +int ipc_platform_send_msg(const struct ipc_msg *msg) { struct ipc *ipc = ipc_get(); @@ -98,7 +98,7 @@ int ipc_platform_send_msg(struct ipc_msg *msg) /* now send the message */ mailbox_dspbox_write(0, msg->tx_data, msg->tx_size); - list_item_del(&msg->list); + ipc->is_notification_pending = true; /* now interrupt host to tell it we have sent a message */ diff --git a/src/drivers/mediatek/mt8195/ipc.c b/src/drivers/mediatek/mt8195/ipc.c index fcc7da275..d23e23a18 100644 --- a/src/drivers/mediatek/mt8195/ipc.c +++ b/src/drivers/mediatek/mt8195/ipc.c @@ -88,7 +88,7 @@ void ipc_platform_complete_cmd(struct ipc *ipc) wait_for_interrupt(0); } -int ipc_platform_send_msg(struct ipc_msg *msg) +int ipc_platform_send_msg(const struct ipc_msg *msg) { struct ipc *ipc = ipc_get(); @@ -97,7 +97,7 @@ int ipc_platform_send_msg(struct ipc_msg *msg) /* now send the message */ mailbox_dspbox_write(0, msg->tx_data, msg->tx_size); - list_item_del(&msg->list); + ipc->is_notification_pending = true; /* now interrupt host to tell it we have sent a message */ diff --git a/src/include/sof/ipc/common.h b/src/include/sof/ipc/common.h index d798681d6..0f891362b 100644 --- a/src/include/sof/ipc/common.h +++ b/src/include/sof/ipc/common.h @@ -178,7 +178,7 @@ int ipc_compact_write_msg(ipc_cmd_hdr *hdr); * @param[in] msg The ipc msg. * @return pointer to raw header or NULL. */ -ipc_cmd_hdr *ipc_prepare_to_send(struct ipc_msg *msg); +ipc_cmd_hdr *ipc_prepare_to_send(const struct ipc_msg *msg); /** * \brief Validate mailbox contents for valid IPC header. diff --git a/src/include/sof/ipc/driver.h b/src/include/sof/ipc/driver.h index 63e82ceed..42b388077 100644 --- a/src/include/sof/ipc/driver.h +++ b/src/include/sof/ipc/driver.h @@ -50,7 +50,7 @@ void ipc_platform_complete_cmd(struct ipc *ipc); * @param msg The IPC message to send to host. * @return 0 on success. */ -int ipc_platform_send_msg(struct ipc_msg *msg); +int ipc_platform_send_msg(const struct ipc_msg *msg); /** * \brief Retrieves the ipc_data_host_buffer allocated by the platform ipc. diff --git a/src/ipc/ipc-common.c b/src/ipc/ipc-common.c index 72ffe5cb8..9af51fb6c 100644 --- a/src/ipc/ipc-common.c +++ b/src/ipc/ipc-common.c @@ -187,8 +187,9 @@ void ipc_send_queued_msg(void) msg = list_first_item(&ipc->msg_list, struct ipc_msg, list); - ipc_platform_send_msg(msg); - + if (ipc_platform_send_msg(msg) == 0) + /* Remove the message from the list if it has been successfully sent. */ + list_item_del(&msg->list); out: k_spin_unlock(&ipc->lock, key); } diff --git a/src/ipc/ipc3/handler.c b/src/ipc/ipc3/handler.c index 41c6988e5..6202ad0bc 100644 --- a/src/ipc/ipc3/handler.c +++ b/src/ipc/ipc3/handler.c @@ -1538,7 +1538,7 @@ ipc_cmd_hdr *ipc_compact_read_msg(void) #endif /* prepare the message using ABI major layout */ -ipc_cmd_hdr *ipc_prepare_to_send(struct ipc_msg *msg) +ipc_cmd_hdr *ipc_prepare_to_send(const struct ipc_msg *msg) { static uint32_t hdr[2]; diff --git a/src/ipc/ipc4/handler.c b/src/ipc/ipc4/handler.c index 31265c6a0..1b3a345c0 100644 --- a/src/ipc/ipc4/handler.c +++ b/src/ipc/ipc4/handler.c @@ -828,7 +828,7 @@ ipc_cmd_hdr *ipc_compact_read_msg(void) return ipc_to_hdr(msg_data.msg_in); } -ipc_cmd_hdr *ipc_prepare_to_send(struct ipc_msg *msg) +ipc_cmd_hdr *ipc_prepare_to_send(const struct ipc_msg *msg) { uint32_t size; diff --git a/src/platform/library/include/platform/platform.h b/src/platform/library/include/platform/platform.h index a76f226ec..0a95bd850 100644 --- a/src/platform/library/include/platform/platform.h +++ b/src/platform/library/include/platform/platform.h @@ -68,7 +68,7 @@ static inline void platform_wait_for_interrupt(int level) arch_wait_for_interrupt(level); } -static inline int ipc_platform_send_msg(struct ipc_msg *msg) { return 0; } +static inline int ipc_platform_send_msg(const struct ipc_msg *msg) { return 0; } #endif /* __PLATFORM_PLATFORM_H__ */ diff --git a/test/cmocka/src/common_mocks.c b/test/cmocka/src/common_mocks.c index b69af0180..bf5c55a6d 100644 --- a/test/cmocka/src/common_mocks.c +++ b/test/cmocka/src/common_mocks.c @@ -219,7 +219,7 @@ void WEAK ipc_platform_complete_cmd(struct ipc *ipc) } #if !CONFIG_LIBRARY -int WEAK ipc_platform_send_msg(struct ipc_msg *msg) +int WEAK ipc_platform_send_msg(const struct ipc_msg *msg) { return 0; }