From 1b7995387d864a3520a302b13cf47b6f554ba05d Mon Sep 17 00:00:00 2001 From: Shuo A Liu Date: Tue, 18 Jun 2019 13:59:56 +0800 Subject: [PATCH] dm: pcidev: clean up assert() for some pci devices Tracked-On: #3252 Signed-off-by: Shuo A Liu Reviewed-by: Yonghua Huang --- devicemodel/hw/pci/lpc.c | 8 ++++++-- devicemodel/hw/pci/virtio/virtio_coreu.c | 11 +++++++++-- devicemodel/hw/pci/virtio/virtio_hdcp.c | 17 +++++++++++------ devicemodel/hw/pci/virtio/virtio_ipu.c | 5 ++--- devicemodel/hw/pci/virtio/virtio_mei.c | 24 +++++++++++++++++------- 5 files changed, 45 insertions(+), 20 deletions(-) diff --git a/devicemodel/hw/pci/lpc.c b/devicemodel/hw/pci/lpc.c index 3d42498c8..46b074302 100644 --- a/devicemodel/hw/pci/lpc.c +++ b/devicemodel/hw/pci/lpc.c @@ -103,7 +103,10 @@ lpc_uart_intr_assert(void *arg) { struct lpc_uart_vdev *lpc_uart = arg; - assert(lpc_uart->irq >= 0); + if (lpc_uart->irq < 0) { + pr_warn("%s: Invalid irq pin lpc_uart\n", __func__); + return; + } if (lpc_bridge) vm_set_gsi_irq(lpc_bridge->vmctx, @@ -221,7 +224,8 @@ lpc_init(struct vmctx *ctx) iop.arg = lpc_uart; error = register_inout(&iop); - assert(error == 0); + if (error) + goto init_failed; lpc_uart->enabled = 1; } diff --git a/devicemodel/hw/pci/virtio/virtio_coreu.c b/devicemodel/hw/pci/virtio/virtio_coreu.c index b28b27b13..6437621e3 100644 --- a/devicemodel/hw/pci/virtio/virtio_coreu.c +++ b/devicemodel/hw/pci/virtio/virtio_coreu.c @@ -60,7 +60,6 @@ #include #include #include -#include #include #include #include @@ -181,7 +180,15 @@ virtio_coreu_thread(void *param) do { ret = vq_getchain(rvq, &idx, &iov, 1, NULL); - assert(ret > 0); + if (ret < 1) { + pr_err("%s: fail to getchain!\n", __func__); + return NULL; + } + if (ret != 1) { + pr_warn("%s: invalid chain!\n", __func__); + vq_relchain(rvq, idx, 0); + continue; + } msg = (struct coreu_msg *)(iov.iov_base); diff --git a/devicemodel/hw/pci/virtio/virtio_hdcp.c b/devicemodel/hw/pci/virtio/virtio_hdcp.c index 871af541d..cade5c6fb 100644 --- a/devicemodel/hw/pci/virtio/virtio_hdcp.c +++ b/devicemodel/hw/pci/virtio/virtio_hdcp.c @@ -55,7 +55,6 @@ #include #include #include -#include #include #include #include @@ -312,17 +311,23 @@ virtio_hdcp_talk_to_daemon(void *param) * - avoid vring processing due to spurious wakeups * - catch missing notifications before acquiring rx_mtx */ - while (!vq_has_descs(rvq)) { - ret = pthread_cond_wait(&vhdcp->rx_cond, &vhdcp->rx_mtx); - assert(ret == 0); - } + while (!vq_has_descs(rvq)) + pthread_cond_wait(&vhdcp->rx_cond, &vhdcp->rx_mtx); vhdcp->in_progress = 1; pthread_mutex_unlock(&vhdcp->rx_mtx); do { ret = vq_getchain(rvq, &idx, &iov, 1, NULL); - assert(ret > 0); + if (ret < 1) { + pr_err("%s: fail to getchain!\n", __func__); + return NULL; + } + if (ret > 1) { + pr_warn("%s: invalid chain!\n", __func__); + vq_relchain(rvq, idx, 0); + continue; + } msg = (struct SocketData*)(iov.iov_base); diff --git a/devicemodel/hw/pci/virtio/virtio_ipu.c b/devicemodel/hw/pci/virtio/virtio_ipu.c index 127986cb1..fd9efe36e 100644 --- a/devicemodel/hw/pci/virtio/virtio_ipu.c +++ b/devicemodel/hw/pci/virtio/virtio_ipu.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include "dm.h" @@ -374,8 +373,8 @@ virtio_ipu_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts) virtio_ipu_k_stop(ipu); virtio_ipu_k_reset(ipu); ipu->vbs_k.ipu_kstatus = VIRTIO_DEV_INITIAL; - assert(ipu->vbs_k.ipu_fd >= 0); - close(ipu->vbs_k.ipu_fd); + if (ipu->vbs_k.ipu_fd >= 0) + close(ipu->vbs_k.ipu_fd); ipu->vbs_k.ipu_fd = -1; } pthread_mutex_destroy(&ipu->mtx); diff --git a/devicemodel/hw/pci/virtio/virtio_mei.c b/devicemodel/hw/pci/virtio/virtio_mei.c index f9ffb5c75..e22a83655 100644 --- a/devicemodel/hw/pci/virtio/virtio_mei.c +++ b/devicemodel/hw/pci/virtio/virtio_mei.c @@ -1490,7 +1490,15 @@ vmei_proc_tx(struct virtio_mei *vmei, struct virtio_vq_info *vq) * The first one is hdr, the second is for payload. */ n = vq_getchain(vq, &idx, iov, VMEI_TX_SEGS, NULL); - assert(n == 2); + if (n != VMEI_TX_SEGS) { + if (n == -1 || n == 0) + pr_err("%s: fail to getchain!\n", __func__); + else { + pr_warn("%s: invalid chain, desc number %d!\n", __func__, n); + vq_relchain(vq, idx, 0); + } + return; + } hdr = (struct mei_msg_hdr *)iov[0].iov_base; data = (uint8_t *)iov[1].iov_base; @@ -1629,7 +1637,6 @@ static void *vmei_tx_thread(void *param) if (pending_cnt == 0) { err = pthread_cond_wait(&vmei->tx_cond, &vmei->tx_mutex); - assert(err == 0); if (err) goto out; } else { @@ -1638,7 +1645,6 @@ static void *vmei_tx_thread(void *param) err = pthread_cond_timedwait(&vmei->tx_cond, &vmei->tx_mutex, &max_wait); - assert(err == 0 || err == ETIMEDOUT); if (err && err != ETIMEDOUT) goto out; @@ -1777,9 +1783,15 @@ vmei_proc_vclient_rx(struct vmei_host_client *hclient, bool complete = true; n = vq_getchain(vq, &idx, iov, VMEI_RX_SEGS, NULL); - assert(n == VMEI_RX_SEGS); - if (n != VMEI_RX_SEGS) + if (n != VMEI_RX_SEGS) { + if (n == -1) + pr_err("%s: fail to getchain!\n", __func__); + else { + pr_warn("%s: invalid chain, desc number %d!\n", __func__, n); + vq_relchain(vq, idx, 0); + } return; + } len = hclient->recv_offset - hclient->recv_handled; HCL_DBG(hclient, "RX: DM->UOS: off=%d len=%d\n", @@ -1883,7 +1895,6 @@ static void *vmei_rx_thread(void *param) while (vmei->status != VMEI_STST_DEINIT && !vq_ring_ready(vq)) { err = pthread_cond_wait(&vmei->rx_cond, &vmei->rx_mutex); - assert(err == 0); if (err) goto out; } @@ -1900,7 +1911,6 @@ static void *vmei_rx_thread(void *param) err = pthread_cond_wait(&vmei->rx_cond, &vmei->rx_mutex); - assert(err == 0); if (err || vmei->status == VMEI_STST_DEINIT) goto out; }