1 From 34a5102c3235c470a6c77fba16cb971964d9c136 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Tue, 31 Jan 2017 19:37:54 +0100
4 Subject: [PATCH 1/3] net: bgmac: allocate struct bgmac just once & don't copy
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 So far were were allocating struct bgmac in 3 places: platform code,
11 bcma code and shared bgmac_enet_probe function. The reason for this was
13 1) Requiring early-filled struct bgmac
14 2) Calling alloc_etherdev on its own in order to use netdev_priv later
16 This solution got few drawbacks:
17 1) Was duplicating allocating code
18 2) Required copying early-filled struct
19 3) Resulted in platform/bcma code having access only to unused struct
21 Solve this situation by simply extracting some probe code into the new
24 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
25 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
26 Signed-off-by: David S. Miller <davem@davemloft.net>
28 drivers/net/ethernet/broadcom/bgmac-bcma.c | 4 +---
29 drivers/net/ethernet/broadcom/bgmac-platform.c | 2 +-
30 drivers/net/ethernet/broadcom/bgmac.c | 25 +++++++++++++++++--------
31 drivers/net/ethernet/broadcom/bgmac.h | 3 ++-
32 4 files changed, 21 insertions(+), 13 deletions(-)
34 --- a/drivers/net/ethernet/broadcom/bgmac-bcma.c
35 +++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c
36 @@ -99,12 +99,11 @@ static int bgmac_probe(struct bcma_devic
40 - bgmac = kzalloc(sizeof(*bgmac), GFP_KERNEL);
41 + bgmac = bgmac_alloc(&core->dev);
45 bgmac->bcma.core = core;
46 - bgmac->dev = &core->dev;
47 bgmac->dma_dev = core->dma_dev;
48 bgmac->irq = core->irq;
50 @@ -285,7 +284,6 @@ static int bgmac_probe(struct bcma_devic
52 bcma_mdio_mii_unregister(bgmac->mii_bus);
55 bcma_set_drvdata(core, NULL);
58 --- a/drivers/net/ethernet/broadcom/bgmac-platform.c
59 +++ b/drivers/net/ethernet/broadcom/bgmac-platform.c
60 @@ -93,7 +93,7 @@ static int bgmac_probe(struct platform_d
61 struct resource *regs;
64 - bgmac = devm_kzalloc(&pdev->dev, sizeof(*bgmac), GFP_KERNEL);
65 + bgmac = bgmac_alloc(&pdev->dev);
69 --- a/drivers/net/ethernet/broadcom/bgmac.c
70 +++ b/drivers/net/ethernet/broadcom/bgmac.c
71 @@ -1475,22 +1475,32 @@ static int bgmac_phy_connect(struct bgma
75 -int bgmac_enet_probe(struct bgmac *info)
76 +struct bgmac *bgmac_alloc(struct device *dev)
78 struct net_device *net_dev;
82 /* Allocation and references */
83 - net_dev = alloc_etherdev(sizeof(*bgmac));
84 + net_dev = devm_alloc_etherdev(dev, sizeof(*bgmac));
89 net_dev->netdev_ops = &bgmac_netdev_ops;
90 net_dev->ethtool_ops = &bgmac_ethtool_ops;
92 bgmac = netdev_priv(net_dev);
93 - memcpy(bgmac, info, sizeof(*bgmac));
95 bgmac->net_dev = net_dev;
99 +EXPORT_SYMBOL_GPL(bgmac_alloc);
101 +int bgmac_enet_probe(struct bgmac *bgmac)
103 + struct net_device *net_dev = bgmac->net_dev;
106 net_dev->irq = bgmac->irq;
107 SET_NETDEV_DEV(net_dev, bgmac->dev);
109 @@ -1517,7 +1527,7 @@ int bgmac_enet_probe(struct bgmac *info)
110 err = bgmac_dma_alloc(bgmac);
112 dev_err(bgmac->dev, "Unable to alloc memory for DMA\n");
113 - goto err_netdev_free;
117 bgmac->int_mask = BGMAC_IS_ERRMASK | BGMAC_IS_RX | BGMAC_IS_TX_MASK;
118 @@ -1553,8 +1563,7 @@ err_phy_disconnect:
119 phy_disconnect(net_dev->phydev);
121 bgmac_dma_free(bgmac);
123 - free_netdev(net_dev);
128 --- a/drivers/net/ethernet/broadcom/bgmac.h
129 +++ b/drivers/net/ethernet/broadcom/bgmac.h
130 @@ -515,7 +515,8 @@ struct bgmac {
134 -int bgmac_enet_probe(struct bgmac *info);
135 +struct bgmac *bgmac_alloc(struct device *dev);
136 +int bgmac_enet_probe(struct bgmac *bgmac);
137 void bgmac_enet_remove(struct bgmac *bgmac);
139 struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr);