summaryrefslogtreecommitdiffstats
path: root/src/vnet/devices/virtio
diff options
context:
space:
mode:
authorSteven Luong <sluong@cisco.com>2022-01-19 09:08:27 -0800
committerBeno�t Ganne <bganne@cisco.com>2022-02-01 16:33:26 +0000
commitc4a48f2c397e6ec219ed64be65a1cc23847f595a (patch)
treeb98e96bb1925263c7fcad239bcb61499d7a40481 /src/vnet/devices/virtio
parent0a214804f873747548d022d44d21e5a43ad997b3 (diff)
virtio: coverity woes -- divide by zero
Coverity complains the expression, j % vif->num_txq, may encounter divide by zero. While there is little chance that vif->num_txq is zero, it is easy to prevent divide by zero if vif->num_txq is ever zero. Type: fix Fixes: I337ec63d0868f665329d68eadf1744e080b73a0d Signed-off-by: Steven Luong <sluong@cisco.com> Change-Id: I2e91f296737ce266ab70fffc1f442cc600724fa2
Diffstat (limited to 'src/vnet/devices/virtio')
-rw-r--r--src/vnet/devices/virtio/virtio.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/vnet/devices/virtio/virtio.c b/src/vnet/devices/virtio/virtio.c
index 2d1edfecb67..bbca81c2d02 100644
--- a/src/vnet/devices/virtio/virtio.c
+++ b/src/vnet/devices/virtio/virtio.c
@@ -295,6 +295,13 @@ virtio_vring_set_tx_queues (vlib_main_t *vm, virtio_if_t *vif)
vnm, vif->hw_if_index, TX_QUEUE_ACCESS (vring->queue_id));
}
+ if (vif->num_txqs == 0)
+ {
+ virtio_log_error (vif, "Interface %U has 0 txq",
+ format_vnet_hw_if_index_name, vnm, vif->hw_if_index);
+ return;
+ }
+
for (u32 j = 0; j < vlib_get_n_threads (); j++)
{
u32 qi = vif->txq_vrings[j % vif->num_txqs].queue_index;