/* Send control message over ICMsg with mutex locked. Mutex must be locked because ICMsg may return error on concurrent invocations even when there is enough space in queue.  */
static int send_control_message(struct backend_data *dev_data, enum msg_type msg_type, uint8_t ept_addr, uint8_t block_index)
/* Send control message over ICMsg with mutex locked. Mutex must be locked because ICMsg may return error on concurrent invocations even when there is enough space in queue.  */
static int send_control_message(struct backend_data *dev_data, enum msg_type msg_type, uint8_t ept_addr, uint8_t block_index)
{
	const struct icbmsg_config *conf = dev_data->conf;
	const struct control_message message = {
		.msg_type = (uint8_t)msg_type,
		.ept_addr = ept_addr,
		.block_index = block_index,
	};
	int r;
	k_mutex_lock(&dev_data->mutex, K_FOREVER);
	r = icmsg_send(&conf->control_config, &dev_data->control_data, &message,
		       sizeof(message));
	k_mutex_unlock(&dev_data->mutex);
	if (r < 0) {
		LOG_ERR("Cannot send over ICMsg, err %d", r);
	}
	return r;
}