Commit 34a5102c authored by Rafał Miłecki's avatar Rafał Miłecki Committed by David S. Miller

net: bgmac: allocate struct bgmac just once & don't copy it

So far were were allocating struct bgmac in 3 places: platform code,
bcma code and shared bgmac_enet_probe function. The reason for this was
bgmac_enet_probe:
1) Requiring early-filled struct bgmac
2) Calling alloc_etherdev on its own in order to use netdev_priv later

This solution got few drawbacks:
1) Was duplicating allocating code
2) Required copying early-filled struct
3) Resulted in platform/bcma code having access only to unused struct

Solve this situation by simply extracting some probe code into the new
bgmac_alloc function.
Signed-off-by: default avatarRafał Miłecki <rafal@milecki.pl>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 953046e1
...@@ -117,12 +117,11 @@ static int bgmac_probe(struct bcma_device *core) ...@@ -117,12 +117,11 @@ static int bgmac_probe(struct bcma_device *core)
u8 *mac; u8 *mac;
int err; int err;
bgmac = kzalloc(sizeof(*bgmac), GFP_KERNEL); bgmac = bgmac_alloc(&core->dev);
if (!bgmac) if (!bgmac)
return -ENOMEM; return -ENOMEM;
bgmac->bcma.core = core; bgmac->bcma.core = core;
bgmac->dev = &core->dev;
bgmac->dma_dev = core->dma_dev; bgmac->dma_dev = core->dma_dev;
bgmac->irq = core->irq; bgmac->irq = core->irq;
...@@ -307,7 +306,6 @@ static int bgmac_probe(struct bcma_device *core) ...@@ -307,7 +306,6 @@ static int bgmac_probe(struct bcma_device *core)
err1: err1:
bcma_mdio_mii_unregister(bgmac->mii_bus); bcma_mdio_mii_unregister(bgmac->mii_bus);
err: err:
kfree(bgmac);
bcma_set_drvdata(core, NULL); bcma_set_drvdata(core, NULL);
return err; return err;
......
...@@ -151,7 +151,7 @@ static int bgmac_probe(struct platform_device *pdev) ...@@ -151,7 +151,7 @@ static int bgmac_probe(struct platform_device *pdev)
struct resource *regs; struct resource *regs;
const u8 *mac_addr; const u8 *mac_addr;
bgmac = devm_kzalloc(&pdev->dev, sizeof(*bgmac), GFP_KERNEL); bgmac = bgmac_alloc(&pdev->dev);
if (!bgmac) if (!bgmac)
return -ENOMEM; return -ENOMEM;
......
...@@ -1446,22 +1446,32 @@ int bgmac_phy_connect_direct(struct bgmac *bgmac) ...@@ -1446,22 +1446,32 @@ int bgmac_phy_connect_direct(struct bgmac *bgmac)
} }
EXPORT_SYMBOL_GPL(bgmac_phy_connect_direct); EXPORT_SYMBOL_GPL(bgmac_phy_connect_direct);
int bgmac_enet_probe(struct bgmac *info) struct bgmac *bgmac_alloc(struct device *dev)
{ {
struct net_device *net_dev; struct net_device *net_dev;
struct bgmac *bgmac; struct bgmac *bgmac;
int err;
/* Allocation and references */ /* Allocation and references */
net_dev = alloc_etherdev(sizeof(*bgmac)); net_dev = devm_alloc_etherdev(dev, sizeof(*bgmac));
if (!net_dev) if (!net_dev)
return -ENOMEM; return NULL;
net_dev->netdev_ops = &bgmac_netdev_ops; net_dev->netdev_ops = &bgmac_netdev_ops;
net_dev->ethtool_ops = &bgmac_ethtool_ops; net_dev->ethtool_ops = &bgmac_ethtool_ops;
bgmac = netdev_priv(net_dev); bgmac = netdev_priv(net_dev);
memcpy(bgmac, info, sizeof(*bgmac)); bgmac->dev = dev;
bgmac->net_dev = net_dev; bgmac->net_dev = net_dev;
return bgmac;
}
EXPORT_SYMBOL_GPL(bgmac_alloc);
int bgmac_enet_probe(struct bgmac *bgmac)
{
struct net_device *net_dev = bgmac->net_dev;
int err;
net_dev->irq = bgmac->irq; net_dev->irq = bgmac->irq;
SET_NETDEV_DEV(net_dev, bgmac->dev); SET_NETDEV_DEV(net_dev, bgmac->dev);
...@@ -1488,7 +1498,7 @@ int bgmac_enet_probe(struct bgmac *info) ...@@ -1488,7 +1498,7 @@ int bgmac_enet_probe(struct bgmac *info)
err = bgmac_dma_alloc(bgmac); err = bgmac_dma_alloc(bgmac);
if (err) { if (err) {
dev_err(bgmac->dev, "Unable to alloc memory for DMA\n"); dev_err(bgmac->dev, "Unable to alloc memory for DMA\n");
goto err_netdev_free; goto err_out;
} }
bgmac->int_mask = BGMAC_IS_ERRMASK | BGMAC_IS_RX | BGMAC_IS_TX_MASK; bgmac->int_mask = BGMAC_IS_ERRMASK | BGMAC_IS_RX | BGMAC_IS_TX_MASK;
...@@ -1521,8 +1531,7 @@ int bgmac_enet_probe(struct bgmac *info) ...@@ -1521,8 +1531,7 @@ int bgmac_enet_probe(struct bgmac *info)
phy_disconnect(net_dev->phydev); phy_disconnect(net_dev->phydev);
err_dma_free: err_dma_free:
bgmac_dma_free(bgmac); bgmac_dma_free(bgmac);
err_netdev_free: err_out:
free_netdev(net_dev);
return err; return err;
} }
......
...@@ -517,7 +517,8 @@ struct bgmac { ...@@ -517,7 +517,8 @@ struct bgmac {
int (*phy_connect)(struct bgmac *bgmac); int (*phy_connect)(struct bgmac *bgmac);
}; };
int bgmac_enet_probe(struct bgmac *info); struct bgmac *bgmac_alloc(struct device *dev);
int bgmac_enet_probe(struct bgmac *bgmac);
void bgmac_enet_remove(struct bgmac *bgmac); void bgmac_enet_remove(struct bgmac *bgmac);
void bgmac_adjust_link(struct net_device *net_dev); void bgmac_adjust_link(struct net_device *net_dev);
int bgmac_phy_connect_direct(struct bgmac *bgmac); int bgmac_phy_connect_direct(struct bgmac *bgmac);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment