Skip to content

Commit 1b79953

Browse files
Shuo A Liuwenlingz
authored andcommitted
dm: pcidev: clean up assert() for some pci devices
Tracked-On: #3252 Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com> Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
1 parent 2b3dedf commit 1b79953

File tree

5 files changed

+45
-20
lines changed

5 files changed

+45
-20
lines changed

devicemodel/hw/pci/lpc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ lpc_uart_intr_assert(void *arg)
103103
{
104104
struct lpc_uart_vdev *lpc_uart = arg;
105105

106-
assert(lpc_uart->irq >= 0);
106+
if (lpc_uart->irq < 0) {
107+
pr_warn("%s: Invalid irq pin lpc_uart\n", __func__);
108+
return;
109+
}
107110

108111
if (lpc_bridge)
109112
vm_set_gsi_irq(lpc_bridge->vmctx,
@@ -221,7 +224,8 @@ lpc_init(struct vmctx *ctx)
221224
iop.arg = lpc_uart;
222225

223226
error = register_inout(&iop);
224-
assert(error == 0);
227+
if (error)
228+
goto init_failed;
225229
lpc_uart->enabled = 1;
226230
}
227231

devicemodel/hw/pci/virtio/virtio_coreu.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
#include <stdlib.h>
6161
#include <string.h>
6262
#include <unistd.h>
63-
#include <assert.h>
6463
#include <pthread.h>
6564
#include <sysexits.h>
6665
#include <dlfcn.h>
@@ -181,7 +180,15 @@ virtio_coreu_thread(void *param)
181180

182181
do {
183182
ret = vq_getchain(rvq, &idx, &iov, 1, NULL);
184-
assert(ret > 0);
183+
if (ret < 1) {
184+
pr_err("%s: fail to getchain!\n", __func__);
185+
return NULL;
186+
}
187+
if (ret != 1) {
188+
pr_warn("%s: invalid chain!\n", __func__);
189+
vq_relchain(rvq, idx, 0);
190+
continue;
191+
}
185192

186193
msg = (struct coreu_msg *)(iov.iov_base);
187194

devicemodel/hw/pci/virtio/virtio_hdcp.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
#include <stdlib.h>
5656
#include <string.h>
5757
#include <unistd.h>
58-
#include <assert.h>
5958
#include <pthread.h>
6059
#include <sysexits.h>
6160
#include <dlfcn.h>
@@ -312,17 +311,23 @@ virtio_hdcp_talk_to_daemon(void *param)
312311
* - avoid vring processing due to spurious wakeups
313312
* - catch missing notifications before acquiring rx_mtx
314313
*/
315-
while (!vq_has_descs(rvq)) {
316-
ret = pthread_cond_wait(&vhdcp->rx_cond, &vhdcp->rx_mtx);
317-
assert(ret == 0);
318-
}
314+
while (!vq_has_descs(rvq))
315+
pthread_cond_wait(&vhdcp->rx_cond, &vhdcp->rx_mtx);
319316

320317
vhdcp->in_progress = 1;
321318
pthread_mutex_unlock(&vhdcp->rx_mtx);
322319

323320
do {
324321
ret = vq_getchain(rvq, &idx, &iov, 1, NULL);
325-
assert(ret > 0);
322+
if (ret < 1) {
323+
pr_err("%s: fail to getchain!\n", __func__);
324+
return NULL;
325+
}
326+
if (ret > 1) {
327+
pr_warn("%s: invalid chain!\n", __func__);
328+
vq_relchain(rvq, idx, 0);
329+
continue;
330+
}
326331

327332
msg = (struct SocketData*)(iov.iov_base);
328333

devicemodel/hw/pci/virtio/virtio_ipu.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <stdlib.h>
1616
#include <string.h>
1717
#include <unistd.h>
18-
#include <assert.h>
1918
#include <pthread.h>
2019

2120
#include "dm.h"
@@ -374,8 +373,8 @@ virtio_ipu_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
374373
virtio_ipu_k_stop(ipu);
375374
virtio_ipu_k_reset(ipu);
376375
ipu->vbs_k.ipu_kstatus = VIRTIO_DEV_INITIAL;
377-
assert(ipu->vbs_k.ipu_fd >= 0);
378-
close(ipu->vbs_k.ipu_fd);
376+
if (ipu->vbs_k.ipu_fd >= 0)
377+
close(ipu->vbs_k.ipu_fd);
379378
ipu->vbs_k.ipu_fd = -1;
380379
}
381380
pthread_mutex_destroy(&ipu->mtx);

devicemodel/hw/pci/virtio/virtio_mei.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,15 @@ vmei_proc_tx(struct virtio_mei *vmei, struct virtio_vq_info *vq)
14901490
* The first one is hdr, the second is for payload.
14911491
*/
14921492
n = vq_getchain(vq, &idx, iov, VMEI_TX_SEGS, NULL);
1493-
assert(n == 2);
1493+
if (n != VMEI_TX_SEGS) {
1494+
if (n == -1 || n == 0)
1495+
pr_err("%s: fail to getchain!\n", __func__);
1496+
else {
1497+
pr_warn("%s: invalid chain, desc number %d!\n", __func__, n);
1498+
vq_relchain(vq, idx, 0);
1499+
}
1500+
return;
1501+
}
14941502

14951503
hdr = (struct mei_msg_hdr *)iov[0].iov_base;
14961504
data = (uint8_t *)iov[1].iov_base;
@@ -1629,7 +1637,6 @@ static void *vmei_tx_thread(void *param)
16291637
if (pending_cnt == 0) {
16301638
err = pthread_cond_wait(&vmei->tx_cond,
16311639
&vmei->tx_mutex);
1632-
assert(err == 0);
16331640
if (err)
16341641
goto out;
16351642
} else {
@@ -1638,7 +1645,6 @@ static void *vmei_tx_thread(void *param)
16381645
err = pthread_cond_timedwait(&vmei->tx_cond,
16391646
&vmei->tx_mutex,
16401647
&max_wait);
1641-
assert(err == 0 || err == ETIMEDOUT);
16421648
if (err && err != ETIMEDOUT)
16431649
goto out;
16441650

@@ -1777,9 +1783,15 @@ vmei_proc_vclient_rx(struct vmei_host_client *hclient,
17771783
bool complete = true;
17781784

17791785
n = vq_getchain(vq, &idx, iov, VMEI_RX_SEGS, NULL);
1780-
assert(n == VMEI_RX_SEGS);
1781-
if (n != VMEI_RX_SEGS)
1786+
if (n != VMEI_RX_SEGS) {
1787+
if (n == -1)
1788+
pr_err("%s: fail to getchain!\n", __func__);
1789+
else {
1790+
pr_warn("%s: invalid chain, desc number %d!\n", __func__, n);
1791+
vq_relchain(vq, idx, 0);
1792+
}
17821793
return;
1794+
}
17831795

17841796
len = hclient->recv_offset - hclient->recv_handled;
17851797
HCL_DBG(hclient, "RX: DM->UOS: off=%d len=%d\n",
@@ -1883,7 +1895,6 @@ static void *vmei_rx_thread(void *param)
18831895

18841896
while (vmei->status != VMEI_STST_DEINIT && !vq_ring_ready(vq)) {
18851897
err = pthread_cond_wait(&vmei->rx_cond, &vmei->rx_mutex);
1886-
assert(err == 0);
18871898
if (err)
18881899
goto out;
18891900
}
@@ -1900,7 +1911,6 @@ static void *vmei_rx_thread(void *param)
19001911

19011912
err = pthread_cond_wait(&vmei->rx_cond,
19021913
&vmei->rx_mutex);
1903-
assert(err == 0);
19041914
if (err || vmei->status == VMEI_STST_DEINIT)
19051915
goto out;
19061916
}

0 commit comments

Comments
 (0)