net: liquidio: release resources when liquidio driver open failed
authorZhengchao Shao <shaozhengchao@huawei.com>
Thu, 10 Nov 2022 10:30:37 +0000 (18:30 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 26 Nov 2022 08:24:39 +0000 (09:24 +0100)
[ Upstream commit 8979f428a4afc215e390006e5ea19fd4e22c7ca9 ]

When liquidio driver open failed, it doesn't release resources. Compile
tested only.

Fixes: 5b07aee11227 ("liquidio: MSIX support for CN23XX")
Fixes: dbc97bfd3918 ("net: liquidio: Add missing null pointer checks")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/cavium/liquidio/lio_main.c

index 2907e13..7bd97d9 100644 (file)
@@ -1798,13 +1798,10 @@ static int liquidio_open(struct net_device *netdev)
 
        ifstate_set(lio, LIO_IFSTATE_RUNNING);
 
-       if (OCTEON_CN23XX_PF(oct)) {
-               if (!oct->msix_on)
-                       if (setup_tx_poll_fn(netdev))
-                               return -1;
-       } else {
-               if (setup_tx_poll_fn(netdev))
-                       return -1;
+       if (!OCTEON_CN23XX_PF(oct) || (OCTEON_CN23XX_PF(oct) && !oct->msix_on)) {
+               ret = setup_tx_poll_fn(netdev);
+               if (ret)
+                       goto err_poll;
        }
 
        netif_tx_start_all_queues(netdev);
@@ -1817,7 +1814,7 @@ static int liquidio_open(struct net_device *netdev)
        /* tell Octeon to start forwarding packets to host */
        ret = send_rx_ctrl_cmd(lio, 1);
        if (ret)
-               return ret;
+               goto err_rx_ctrl;
 
        /* start periodical statistics fetch */
        INIT_DELAYED_WORK(&lio->stats_wk.work, lio_fetch_stats);
@@ -1828,6 +1825,27 @@ static int liquidio_open(struct net_device *netdev)
        dev_info(&oct->pci_dev->dev, "%s interface is opened\n",
                 netdev->name);
 
+       return 0;
+
+err_rx_ctrl:
+       if (!OCTEON_CN23XX_PF(oct) || (OCTEON_CN23XX_PF(oct) && !oct->msix_on))
+               cleanup_tx_poll_fn(netdev);
+err_poll:
+       if (lio->ptp_clock) {
+               ptp_clock_unregister(lio->ptp_clock);
+               lio->ptp_clock = NULL;
+       }
+
+       if (oct->props[lio->ifidx].napi_enabled == 1) {
+               list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
+                       napi_disable(napi);
+
+               oct->props[lio->ifidx].napi_enabled = 0;
+
+               if (OCTEON_CN23XX_PF(oct))
+                       oct->droq[0]->ops.poll_mode = 0;
+       }
+
        return ret;
 }