: Fix race conditions when calling register_netdev().
Subsystems (2)
PATCH 4/20 : Fix race conditions when calling register_netdev().
[BNX2]: Fix race conditions when calling register_netdev().
Hot-plug scripts can call bnx2_open() as soon as register_netdev() is called in bnx2_init_one(). We need to call pci_set_drvdata() and setup everything before calling register_netdev(). netif_carrier_off() also needs to be moved to bnx2_open() to avoid race conditions with the irq.
drivers/net/bnx2.c +14 -14
@@ -4350,6 +4350,8 @@ bnx2_open(struct net_device *dev)struct bnx2 *bp =netdev_priv (dev);int rc; +netif_carrier_off (dev); +bnx2_set_power_state (bp,PCI_D0 );bnx2_disable_int (bp);
@@ -6195,6 +6197,18 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) dev->poll_controller = poll_bnx2;#endif +pci_set_drvdata (pdev, dev); + +memcpy (dev->dev_addr, bp->mac_addr,6 ); +memcpy (dev->perm_addr, bp->mac_addr,6 ); + bp->name = board_info[ent->driver_data].name; + + dev->features |=NETIF_F_IP_CSUM |NETIF_F_SG ; +#ifdef BCM_VLAN + dev->features |=NETIF_F_HW_VLAN_TX |NETIF_F_HW_VLAN_RX ; +#endif + dev->features |=NETIF_F_TSO |NETIF_F_TSO_ECN ; +if ((rc =register_netdev (dev))) {dev_err (&pdev->dev,"Cannot register net device\n" );if (bp->regview)
@@ -6206,11 +6220,6 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)return rc; } -pci_set_drvdata (pdev, dev); - -memcpy (dev->dev_addr, bp->mac_addr,6 ); -memcpy (dev->perm_addr, bp->mac_addr,6 ); - bp->name = board_info[ent->driver_data].name, printk(KERN_INFO "%s: %s (%c%d) PCI%s %s %dMHz found at mem %lx, " "IRQ %d, ", dev->name,
@@ -6228,15 +6237,6 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)printk ("%2.2x" , dev->dev_addr[i]);printk ("\n" ); - dev->features |=NETIF_F_SG ; - dev->features |=NETIF_F_IP_CSUM ; -#ifdef BCM_VLAN - dev->features |=NETIF_F_HW_VLAN_TX |NETIF_F_HW_VLAN_RX ; -#endif - dev->features |=NETIF_F_TSO |NETIF_F_TSO_ECN ; - -netif_carrier_off (bp->dev); -return 0 ; }
Quoted 43 lines · Michael Chan
[BNX2]: Fix race conditions when calling
register_netdev().Hot-plug scripts can call
bnx2_open()as soon asregister_netdev()is called inbnx2_init_one(). We need to callpci_set_drvdata()and setup everything before callingregister_netdev().netif_carrier_off()also needs to be moved tobnx2_open()to avoid race conditions with the irq.Signed-off-by Michael Chan <[email protected]>drivers/net/bnx2.c +14
-0@@ -4350,6 +4350,8 @@ bnx2_open(struct net_device *dev)struct bnx2 *bp =netdev_priv (dev);int rc; +netif_carrier_off (dev); +bnx2_set_power_state (bp,PCI_D0 );bnx2_disable_int (bp);@@ -6195,6 +6197,18 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) dev->poll_controller = poll_bnx2;#endif +pci_set_drvdata (pdev, dev); + +memcpy (dev->dev_addr, bp->mac_addr,6 ); +memcpy (dev->perm_addr, bp->mac_addr,6 ); + bp->name = board_info[ent->driver_data].name; + + dev->features |=NETIF_F_IP_CSUM |NETIF_F_SG ; +#ifdef BCM_VLAN + dev->features |=NETIF_F_HW_VLAN_TX |NETIF_F_HW_VLAN_RX ; +#endif + dev->features |=NETIF_F_TSO |NETIF_F_TSO_ECN ; +if ((rc =register_netdev (dev))) {dev_err (&pdev->dev,"Cannot register net device\n" );if (bp->regview)
drivers/net/bnx2.c bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 6213
Quoted 8 lines
drivers/net/bnx2.c +0
-5@@ -6206,11 +6220,6 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)return rc; } -pci_set_drvdata (pdev, dev); - -memcpy (dev->dev_addr, bp->mac_addr,6 ); -memcpy (dev->perm_addr, bp->mac_addr,6 ); - bp->name = board_info[ent->driver_data].name,
NAK. Since you move the pci_set_drvdata() call, you must now add a call to pci_set_drvdata(pdev, NULL) on error.
ACK, once fixed.
Quoted 25 lines · Jeff Garzik
Quoted 24 lines · Michael Chan
drivers/net/bnx2.c +12
-0@@ -6195,6 +6197,18 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) dev->poll_controller = poll_bnx2;#endif +pci_set_drvdata (pdev, dev); + +memcpy (dev->dev_addr, bp->mac_addr,6 ); +memcpy (dev->perm_addr, bp->mac_addr,6 ); + bp->name = board_info[ent->driver_data].name; + + dev->features |=NETIF_F_IP_CSUM |NETIF_F_SG ; +#ifdef BCM_VLAN + dev->features |=NETIF_F_HW_VLAN_TX |NETIF_F_HW_VLAN_RX ; +#endif + dev->features |=NETIF_F_TSO |NETIF_F_TSO_ECN ; +if ((rc =register_netdev (dev))) {dev_err (&pdev->dev,"Cannot register net device\n" );if (bp->regview)@@ -6206,11 +6220,6 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)return rc; }
Quoted 8 lines
drivers/net/bnx2.c bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 6213
Quoted 5 lines
drivers/net/bnx2.c +0
-5-pci_set_drvdata (pdev, dev); - -memcpy (dev->dev_addr, bp->mac_addr,6 ); -memcpy (dev->perm_addr, bp->mac_addr,6 ); - bp->name = board_info[ent->driver_data].name,NAK. Since you move the
pci_set_drvdata()call, you must now add a call topci_set_drvdata(pdev, NULL)on error.
It is not obvious in the patch, but it already (unnecessarily) calls pci_set_drvdata(pdev, NULL) if register_netdev() fails in the driver today.