ionic: protect vf calls from fw reset
authorShannon Nelson <snelson@pensando.io>
Tue, 12 May 2020 00:59:29 +0000 (17:59 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 12 May 2020 19:19:30 +0000 (12:19 -0700)
When going into a firmware upgrade cycle, we set the device as
not present to keep some user commands from trying to change
the driver while we're only half there.  Unfortunately, the
ndo_vf_* calls don't check netif_device_present() so we need
to add a check in the callbacks.

Signed-off-by: Shannon Nelson <snelson@pensando.io>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/pensando/ionic/ionic_lif.c

index 0049f537ee402fbc590b5b4c613f3e779f7ea2f8..5f63c611d1fda8b12c37ddc481e58e5fe896f189 100644 (file)
@@ -1707,7 +1707,7 @@ int ionic_stop(struct net_device *netdev)
 {
        struct ionic_lif *lif = netdev_priv(netdev);
 
-       if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+       if (!netif_device_present(netdev))
                return 0;
 
        ionic_stop_queues(lif);
@@ -1724,6 +1724,9 @@ static int ionic_get_vf_config(struct net_device *netdev,
        struct ionic *ionic = lif->ionic;
        int ret = 0;
 
+       if (!netif_device_present(netdev))
+               return -EBUSY;
+
        down_read(&ionic->vf_op_lock);
 
        if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -1751,6 +1754,9 @@ static int ionic_get_vf_stats(struct net_device *netdev, int vf,
        struct ionic_lif_stats *vs;
        int ret = 0;
 
+       if (!netif_device_present(netdev))
+               return -EBUSY;
+
        down_read(&ionic->vf_op_lock);
 
        if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -1786,6 +1792,9 @@ static int ionic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
        if (!(is_zero_ether_addr(mac) || is_valid_ether_addr(mac)))
                return -EINVAL;
 
+       if (!netif_device_present(netdev))
+               return -EBUSY;
+
        down_write(&ionic->vf_op_lock);
 
        if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -1817,6 +1826,9 @@ static int ionic_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan,
        if (proto != htons(ETH_P_8021Q))
                return -EPROTONOSUPPORT;
 
+       if (!netif_device_present(netdev))
+               return -EBUSY;
+
        down_write(&ionic->vf_op_lock);
 
        if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -1843,6 +1855,9 @@ static int ionic_set_vf_rate(struct net_device *netdev, int vf,
        if (tx_min)
                return -EINVAL;
 
+       if (!netif_device_present(netdev))
+               return -EBUSY;
+
        down_write(&ionic->vf_op_lock);
 
        if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -1865,6 +1880,9 @@ static int ionic_set_vf_spoofchk(struct net_device *netdev, int vf, bool set)
        u8 data = set;  /* convert to u8 for config */
        int ret;
 
+       if (!netif_device_present(netdev))
+               return -EBUSY;
+
        down_write(&ionic->vf_op_lock);
 
        if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -1887,6 +1905,9 @@ static int ionic_set_vf_trust(struct net_device *netdev, int vf, bool set)
        u8 data = set;  /* convert to u8 for config */
        int ret;
 
+       if (!netif_device_present(netdev))
+               return -EBUSY;
+
        down_write(&ionic->vf_op_lock);
 
        if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -1923,6 +1944,9 @@ static int ionic_set_vf_link_state(struct net_device *netdev, int vf, int set)
                return -EINVAL;
        }
 
+       if (!netif_device_present(netdev))
+               return -EBUSY;
+
        down_write(&ionic->vf_op_lock);
 
        if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {