sky2: handle network device allocation failure
authorshemminger@linux-foundation.org <shemminger@linux-foundation.org>
Fri, 26 Jan 2007 19:38:36 +0000 (11:38 -0800)
committerJeff Garzik <jeff@garzik.org>
Mon, 5 Feb 2007 21:58:49 +0000 (16:58 -0500)
If alloc_etherdev() failed, then sky2_init_netdev will return NULL,
and sky2_probe would end up returning 0 instead of -ENOMEM.

Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
drivers/net/sky2.c

index 947439167493472d5125d55d978c56cb3e2702ba..bf1abf034d8a3fcf825b8e4ea0c7e7b714c18969 100644 (file)
@@ -3339,7 +3339,7 @@ static int __devinit sky2_test_msi(struct sky2_hw *hw)
 static int __devinit sky2_probe(struct pci_dev *pdev,
                                const struct pci_device_id *ent)
 {
 static int __devinit sky2_probe(struct pci_dev *pdev,
                                const struct pci_device_id *ent)
 {
-       struct net_device *dev, *dev1 = NULL;
+       struct net_device *dev;
        struct sky2_hw *hw;
        int err, using_dac = 0;
 
        struct sky2_hw *hw;
        int err, using_dac = 0;
 
@@ -3423,8 +3423,10 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
               hw->chip_id, hw->chip_rev);
 
        dev = sky2_init_netdev(hw, 0, using_dac);
               hw->chip_id, hw->chip_rev);
 
        dev = sky2_init_netdev(hw, 0, using_dac);
-       if (!dev)
+       if (!dev) {
+               err = -ENOMEM;
                goto err_out_free_pci;
                goto err_out_free_pci;
+       }
 
        if (!disable_msi && pci_enable_msi(pdev) == 0) {
                err = sky2_test_msi(hw);
 
        if (!disable_msi && pci_enable_msi(pdev) == 0) {
                err = sky2_test_msi(hw);
@@ -3452,13 +3454,19 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
 
        sky2_show_addr(dev);
 
 
        sky2_show_addr(dev);
 
-       if (hw->ports > 1 && (dev1 = sky2_init_netdev(hw, 1, using_dac))) {
-               if (register_netdev(dev1) == 0)
+       if (hw->ports > 1) {
+               struct net_device *dev1;
+
+               dev1 = sky2_init_netdev(hw, 1, using_dac);
+               if (!dev1) {
+                       printk(KERN_WARNING PFX
+                              "allocation of second port failed\n");
+               }
+               else if (!(err = register_netdev(dev1)))
                        sky2_show_addr(dev1);
                else {
                        sky2_show_addr(dev1);
                else {
-                       /* Failure to register second port need not be fatal */
                        printk(KERN_WARNING PFX
                        printk(KERN_WARNING PFX
-                              "register of second port failed\n");
+                              "register of second port failed (%d)\n", err);
                        hw->dev[1] = NULL;
                        free_netdev(dev1);
                }
                        hw->dev[1] = NULL;
                        free_netdev(dev1);
                }