ethernet: s2io: disable napi when start nic failed in s2io_card_up()
authorZhengchao Shao <shaozhengchao@huawei.com>
Wed, 9 Nov 2022 02:37:41 +0000 (10:37 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Nov 2022 16:35:36 +0000 (17:35 +0100)
[ Upstream commit 0348c1ab980c1d43fb37b758d4b760990c066cb5 ]

When failed to start nic or add interrupt service routine in
s2io_card_up() for opening device, napi isn't disabled. When open
s2io device next time, it will trigger a BUG_ON()in napi_enable().
Compile tested only.

Fixes: 5f490c968056 ("S2io: Fixed synchronization between scheduling of napi with card reset and close")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
Link: https://lore.kernel.org/r/20221109023741.131552-1-shaozhengchao@huawei.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/neterion/s2io.c

index a1447d7ff48b53a9cf5a3c5d5d70e982481487c2..a66f4b867e3a82375f104520a99515a456817d69 100644 (file)
@@ -7171,9 +7171,8 @@ static int s2io_card_up(struct s2io_nic *sp)
                if (ret) {
                        DBG_PRINT(ERR_DBG, "%s: Out of memory in Open\n",
                                  dev->name);
-                       s2io_reset(sp);
-                       free_rx_buffers(sp);
-                       return -ENOMEM;
+                       ret = -ENOMEM;
+                       goto err_fill_buff;
                }
                DBG_PRINT(INFO_DBG, "Buf in ring:%d is %d:\n", i,
                          ring->rx_bufs_left);
@@ -7211,18 +7210,16 @@ static int s2io_card_up(struct s2io_nic *sp)
        /* Enable Rx Traffic and interrupts on the NIC */
        if (start_nic(sp)) {
                DBG_PRINT(ERR_DBG, "%s: Starting NIC failed\n", dev->name);
-               s2io_reset(sp);
-               free_rx_buffers(sp);
-               return -ENODEV;
+               ret = -ENODEV;
+               goto err_out;
        }
 
        /* Add interrupt service routine */
        if (s2io_add_isr(sp) != 0) {
                if (sp->config.intr_type == MSI_X)
                        s2io_rem_isr(sp);
-               s2io_reset(sp);
-               free_rx_buffers(sp);
-               return -ENODEV;
+               ret = -ENODEV;
+               goto err_out;
        }
 
        S2IO_TIMER_CONF(sp->alarm_timer, s2io_alarm_handle, sp, (HZ/2));
@@ -7241,6 +7238,20 @@ static int s2io_card_up(struct s2io_nic *sp)
        }
 
        return 0;
+
+err_out:
+       if (config->napi) {
+               if (config->intr_type == MSI_X) {
+                       for (i = 0; i < sp->config.rx_ring_num; i++)
+                               napi_disable(&sp->mac_control.rings[i].napi);
+               } else {
+                       napi_disable(&sp->napi);
+               }
+       }
+err_fill_buff:
+       s2io_reset(sp);
+       free_rx_buffers(sp);
+       return ret;
 }
 
 /**