Break down buggy assert(!memcpy_s(...)) into two statements

assert() semantics are very clear: because asserts are optional, the
argument should never have side-effect, period. assert arguments should
be treated exactly the same as logging arguments. So
`assert(!memcpy_s())` is an obvious bug. Use variable to break that down
into two statements.

Fixes commit 0b7fd030b3 ("demux: return config on COMP_CMD_GET_DATA")

Fixes commit 385586a5f6 ("zephyr: implement IDC using P4WQ")

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
This commit is contained in:
Marc Herbert 2022-04-29 17:45:56 +00:00 committed by Liam Girdwood
parent 8ab452a338
commit dba3c4f63d
2 changed files with 16 additions and 7 deletions

View File

@ -300,8 +300,10 @@ static int mux_ctrl_get_cmd(struct comp_dev *dev,
sizeof(struct mux_stream_data);
/* copy back to user space */
assert(!memcpy_s(cdata->data->data, ((struct sof_abi_hdr *)
(cdata->data))->size, cfg, reply_size));
const int mux_memcpy_err __unused =
memcpy_s(cdata->data->data, ((struct sof_abi_hdr *)
(cdata->data))->size, cfg, reply_size);
assert(!mux_memcpy_err);
cdata->data->abi = SOF_ABI_VERSION;
cdata->data->size = reply_size;

View File

@ -63,8 +63,11 @@ static void idc_handler(struct k_p4wq_work *work)
SOC_DCACHE_INVALIDATE(msg, sizeof(*msg));
if (msg->size == sizeof(int))
assert(!memcpy_s(&payload, sizeof(payload), msg->payload, msg->size));
if (msg->size == sizeof(int)) {
const int idc_handler_memcpy_err __unused =
memcpy_s(&payload, sizeof(payload), msg->payload, msg->size);
assert(!idc_handler_memcpy_err);
}
idc->received_msg.core = msg->core;
idc->received_msg.header = msg->header;
@ -103,8 +106,10 @@ int idc_send_msg(struct idc_msg *msg, uint32_t mode)
struct idc_msg *msg_cp = &zmsg->msg;
struct k_p4wq_work *work = &zmsg->work;
int ret;
int idc_send_memcpy_err __unused;
assert(!memcpy_s(msg_cp, sizeof(*msg_cp), msg, sizeof(*msg)));
idc_send_memcpy_err = memcpy_s(msg_cp, sizeof(*msg_cp), msg, sizeof(*msg));
assert(!idc_send_memcpy_err);
/* TODO: verify .priority and .deadline */
work->priority = K_HIGHEST_THREAD_PRIO + 1;
work->deadline = 0;
@ -112,8 +117,10 @@ int idc_send_msg(struct idc_msg *msg, uint32_t mode)
work->sync = mode == IDC_BLOCKING;
if (msg->payload) {
assert(!memcpy_s(payload->data, sizeof(payload->data),
msg->payload, msg->size));
idc_send_memcpy_err = memcpy_s(payload->data, sizeof(payload->data),
msg->payload, msg->size);
assert(!idc_send_memcpy_err);
SOC_DCACHE_FLUSH(payload->data, MIN(sizeof(payload->data), msg->size));
}