This issue was reported by PVS studio, described as:
https://pvs-studio.com/en/docs/warnings/v522/

Signed-off-by: Rong Qian <qi...@yunsilicon.com>
Signed-off-by: Renyong Wan <wa...@yunsilicon.com>
---
 drivers/net/xsc/xsc_ethdev.c | 15 +++++++++++++--
 drivers/net/xsc/xsc_rx.c     |  5 +++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index d04fe78d3f..44d861e484 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -137,8 +137,8 @@ xsc_ethdev_enable(struct rte_eth_dev *dev)
        int pcie_logic_port = 0;
        int qp_set_id;
        int repr_id;
-       struct xsc_rxq_data *rxq = xsc_rxq_get(priv, 0);
-       uint16_t rx_qpn = (uint16_t)rxq->qpn;
+       struct xsc_rxq_data *rxq;
+       uint16_t rx_qpn;
        int i, vld;
        struct xsc_txq_data *txq;
        struct xsc_repr_port *repr;
@@ -147,6 +147,11 @@ xsc_ethdev_enable(struct rte_eth_dev *dev)
        if (priv->funcid_type != XSC_PHYPORT_MAC_FUNCID)
                return -ENODEV;
 
+       rxq = xsc_rxq_get(priv, 0);
+       if (rxq == NULL)
+               return -EINVAL;
+
+       rx_qpn = (uint16_t)rxq->qpn;
        hwinfo = &priv->xdev->hwinfo;
        repr_id = priv->representor_id;
        repr = &priv->xdev->repr_ports[repr_id];
@@ -162,6 +167,8 @@ xsc_ethdev_enable(struct rte_eth_dev *dev)
 
        for (i = 0; i < priv->num_sq; i++) {
                txq = xsc_txq_get(priv, i);
+               if (txq == NULL)
+                       return -EINVAL;
                xsc_dev_modify_qp_status(priv->xdev, txq->qpn, 1, 
XSC_CMD_OP_RTR2RTS_QP);
                xsc_dev_modify_qp_qostree(priv->xdev, txq->qpn);
                xsc_dev_set_qpsetid(priv->xdev, txq->qpn, qp_set_id);
@@ -229,6 +236,8 @@ xsc_txq_start(struct xsc_ethdev_priv *priv)
 
        for (i = 0; i != priv->num_sq; ++i) {
                txq_data = xsc_txq_get(priv, i);
+               if (txq_data == NULL)
+                       goto error;
                xsc_txq_elts_alloc(txq_data);
                ret = xsc_txq_obj_new(priv->xdev, txq_data, offloads, i);
                if (ret < 0)
@@ -270,6 +279,8 @@ xsc_rxq_start(struct xsc_ethdev_priv *priv)
 
        for (i = 0; i != priv->num_rq; ++i) {
                rxq_data = xsc_rxq_get(priv, i);
+               if (rxq_data == NULL)
+                       goto error;
                if (dev->data->rx_queue_state[i] != 
RTE_ETH_QUEUE_STATE_STARTED) {
                        ret = xsc_rxq_elts_alloc(rxq_data);
                        if (ret != 0)
diff --git a/drivers/net/xsc/xsc_rx.c b/drivers/net/xsc/xsc_rx.c
index 3230710656..140d7728d6 100644
--- a/drivers/net/xsc/xsc_rx.c
+++ b/drivers/net/xsc/xsc_rx.c
@@ -280,6 +280,9 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int port_id)
        char name[RTE_ETH_NAME_MAX_LEN] = { 0 };
 
        rxq_data = xsc_rxq_get(priv, 0);
+       if (rxq_data == NULL)
+               return -EINVAL;
+
        log_ele = rte_log2_u32(sizeof(struct xsc_wqe_data_seg));
        wqe_n = rxq_data->wqe_s;
        log_rq_sz = rte_log2_u32(wqe_n * hwinfo->recv_seg_num);
@@ -385,6 +388,8 @@ xsc_rxq_rss_obj_new(struct xsc_ethdev_priv *priv, uint16_t 
port_id)
        /* Create CQ */
        for (i = 0; i < priv->num_rq; ++i) {
                rxq_data = xsc_rxq_get(priv, i);
+               if (rxq_data == NULL)
+                       return -EINVAL;
 
                memset(&cq_params, 0, sizeof(cq_params));
                memset(&cq_info, 0, sizeof(cq_info));
-- 
2.25.1

Reply via email to