stmmac: handle allocation errors in setup functions
authorDan Carpenter <error27@gmail.com>
Thu, 22 Jul 2010 01:16:48 +0000 (01:16 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 22 Jul 2010 21:14:48 +0000 (14:14 -0700)
If the allocations fail in either dwmac1000_setup() or dwmac100_setup()
then return NULL.  These are called from stmmac_mac_device_setup().  The
check for NULL returns in stmmac_mac_device_setup() needed to be moved
forward a couple lines.

Signed-off-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/stmmac/dwmac1000_core.c
drivers/net/stmmac/dwmac100_core.c
drivers/net/stmmac/stmmac_main.c

index 917b4e16923b800b550fee4502fae7239d67657b..2b2f5c8caf1c52ea010843789417bfb40768366b 100644 (file)
@@ -220,6 +220,8 @@ struct mac_device_info *dwmac1000_setup(unsigned long ioaddr)
                ((uid & 0x0000ff00) >> 8), (uid & 0x000000ff));
 
        mac = kzalloc(sizeof(const struct mac_device_info), GFP_KERNEL);
+       if (!mac)
+               return NULL;
 
        mac->mac = &dwmac1000_ops;
        mac->dma = &dwmac1000_dma_ops;
index 6f270a0e151afa8974356920ea72584293354e5a..2fb165fa2ba075b256533a7d1058ea00c36f2b33 100644 (file)
@@ -179,6 +179,8 @@ struct mac_device_info *dwmac100_setup(unsigned long ioaddr)
        struct mac_device_info *mac;
 
        mac = kzalloc(sizeof(const struct mac_device_info), GFP_KERNEL);
+       if (!mac)
+               return NULL;
 
        pr_info("\tDWMAC100\n");
 
index acf06168694035253c91d584c48c45bde654138f..0bdd3326c94a5fbf06848c0827288fe88bd7e57a 100644 (file)
@@ -1558,15 +1558,15 @@ static int stmmac_mac_device_setup(struct net_device *dev)
        else
                device = dwmac100_setup(ioaddr);
 
+       if (!device)
+               return -ENOMEM;
+
        if (priv->enh_desc) {
                device->desc = &enh_desc_ops;
                pr_info("\tEnhanced descriptor structure\n");
        } else
                device->desc = &ndesc_ops;
 
-       if (!device)
-               return -ENOMEM;
-
        priv->hw = device;
 
        priv->wolenabled = priv->hw->pmt;       /* PMT supported */