Uninitialized ppio cannot be passed to MUSDK library routines as
application will crash.

Fix this by first checking whether ppio has been initialized.

Signed-off-by: Tomasz Duszynski <t...@semihalf.com>
---
 drivers/net/mrvl/mrvl_ethdev.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/drivers/net/mrvl/mrvl_ethdev.c b/drivers/net/mrvl/mrvl_ethdev.c
index 89eec44..92cc283 100644
--- a/drivers/net/mrvl/mrvl_ethdev.c
+++ b/drivers/net/mrvl/mrvl_ethdev.c
@@ -329,6 +329,9 @@ mrvl_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
        if (mtu < ETHER_MIN_MTU || mru > MRVL_PKT_SIZE_MAX)
                return -EINVAL;
 
+       if (!priv->ppio)
+               return -EPERM;
+
        ret = pp2_ppio_set_mru(priv->ppio, mru);
        if (ret)
                return ret;
@@ -351,6 +354,9 @@ mrvl_dev_set_link_up(struct rte_eth_dev *dev)
        struct mrvl_priv *priv = dev->data->dev_private;
        int ret;
 
+       if (!priv->ppio)
+               return -EPERM;
+
        ret = pp2_ppio_enable(priv->ppio);
        if (ret)
                return ret;
@@ -383,6 +389,9 @@ mrvl_dev_set_link_down(struct rte_eth_dev *dev)
 {
        struct mrvl_priv *priv = dev->data->dev_private;
 
+       if (!priv->ppio)
+               return -EPERM;
+
        return pp2_ppio_disable(priv->ppio);
 }
 
@@ -629,6 +638,9 @@ mrvl_link_update(struct rte_eth_dev *dev, int 
wait_to_complete __rte_unused)
        struct ifreq req;
        int ret, fd, link_up;
 
+       if (!priv->ppio)
+               return -EPERM;
+
        edata.cmd = ETHTOOL_GSET;
 
        strcpy(req.ifr_name, dev->data->name);
@@ -685,6 +697,9 @@ mrvl_promiscuous_enable(struct rte_eth_dev *dev)
        struct mrvl_priv *priv = dev->data->dev_private;
        int ret;
 
+       if (!priv->ppio)
+               return;
+
        ret = pp2_ppio_set_promisc(priv->ppio, 1);
        if (ret)
                RTE_LOG(ERR, PMD, "Failed to enable promiscuous mode\n");
@@ -702,6 +717,9 @@ mrvl_allmulticast_enable(struct rte_eth_dev *dev)
        struct mrvl_priv *priv = dev->data->dev_private;
        int ret;
 
+       if (!priv->ppio)
+               return;
+
        ret = pp2_ppio_set_mc_promisc(priv->ppio, 1);
        if (ret)
                RTE_LOG(ERR, PMD, "Failed enable all-multicast mode\n");
@@ -719,6 +737,9 @@ mrvl_promiscuous_disable(struct rte_eth_dev *dev)
        struct mrvl_priv *priv = dev->data->dev_private;
        int ret;
 
+       if (!priv->ppio)
+               return;
+
        ret = pp2_ppio_set_promisc(priv->ppio, 0);
        if (ret)
                RTE_LOG(ERR, PMD, "Failed to disable promiscuous mode\n");
@@ -736,6 +757,9 @@ mrvl_allmulticast_disable(struct rte_eth_dev *dev)
        struct mrvl_priv *priv = dev->data->dev_private;
        int ret;
 
+       if (!priv->ppio)
+               return;
+
        ret = pp2_ppio_set_mc_promisc(priv->ppio, 0);
        if (ret)
                RTE_LOG(ERR, PMD, "Failed to disable all-multicast mode\n");
@@ -756,6 +780,9 @@ mrvl_mac_addr_remove(struct rte_eth_dev *dev, uint32_t 
index)
        char buf[ETHER_ADDR_FMT_SIZE];
        int ret;
 
+       if (!priv->ppio)
+               return;
+
        ret = pp2_ppio_remove_mac_addr(priv->ppio,
                                       dev->data->mac_addrs[index].addr_bytes);
        if (ret) {
@@ -792,6 +819,9 @@ mrvl_mac_addr_add(struct rte_eth_dev *dev, struct 
ether_addr *mac_addr,
                /* For setting index 0, mrvl_mac_addr_set() should be used.*/
                return -1;
 
+       if (!priv->ppio)
+               return -EPERM;
+
        /*
         * Maximum number of uc addresses can be tuned via kernel module mvpp2x
         * parameter uc_filter_max. Maximum number of mc addresses is then
@@ -829,6 +859,9 @@ mrvl_mac_addr_set(struct rte_eth_dev *dev, struct 
ether_addr *mac_addr)
        struct mrvl_priv *priv = dev->data->dev_private;
        int ret;
 
+       if (!priv->ppio)
+               return;
+
        ret = pp2_ppio_set_mac_addr(priv->ppio, mac_addr->addr_bytes);
        if (ret) {
                char buf[ETHER_ADDR_FMT_SIZE];
@@ -856,6 +889,9 @@ mrvl_stats_get(struct rte_eth_dev *dev, struct 
rte_eth_stats *stats)
        uint64_t drop_mac = 0;
        unsigned int i, idx, ret;
 
+       if (!priv->ppio)
+               return -EPERM;
+
        for (i = 0; i < dev->data->nb_rx_queues; i++) {
                struct mrvl_rxq *rxq = dev->data->rx_queues[i];
                struct pp2_ppio_inq_statistics rx_stats;
@@ -948,6 +984,9 @@ mrvl_stats_reset(struct rte_eth_dev *dev)
        struct mrvl_priv *priv = dev->data->dev_private;
        int i;
 
+       if (!priv->ppio)
+               return;
+
        for (i = 0; i < dev->data->nb_rx_queues; i++) {
                struct mrvl_rxq *rxq = dev->data->rx_queues[i];
 
@@ -1104,6 +1143,9 @@ mrvl_vlan_filter_set(struct rte_eth_dev *dev, uint16_t 
vlan_id, int on)
 {
        struct mrvl_priv *priv = dev->data->dev_private;
 
+       if (!priv->ppio)
+               return -EPERM;
+
        return on ? pp2_ppio_add_vlan(priv->ppio, vlan_id) :
                    pp2_ppio_remove_vlan(priv->ppio, vlan_id);
 }
-- 
2.7.4

Reply via email to