All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 20/33] net: bgmac: allocate struct bgmac just once & don't copy it
@ 2017-04-04  6:17 Amit Pundir
  2017-04-04  6:18 ` [PATCH 21/33] net: bgmac: drop struct bcma_mdio we don't need anymore Amit Pundir
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Amit Pundir @ 2017-04-04  6:17 UTC (permalink / raw)
  To: gregkh; +Cc: stable, Rafał Miłecki, David S . Miller

From: Rafał Miłecki <rafal@milecki.pl>

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: Rafał Miłecki <rafal@milecki.pl>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 34a5102c3235c470a6c77fba16cb971964d9c136)
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
---
 drivers/net/ethernet/broadcom/bgmac-bcma.c     |  4 +---
 drivers/net/ethernet/broadcom/bgmac-platform.c |  2 +-
 drivers/net/ethernet/broadcom/bgmac.c          | 25 +++++++++++++++++--------
 drivers/net/ethernet/broadcom/bgmac.h          |  3 ++-
 4 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bgmac-bcma.c b/drivers/net/ethernet/broadcom/bgmac-bcma.c
index c16ec3a..5b0c7a7 100644
--- a/drivers/net/ethernet/broadcom/bgmac-bcma.c
+++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c
@@ -99,12 +99,11 @@ static int bgmac_probe(struct bcma_device *core)
 	u8 *mac;
 	int err;
 
-	bgmac = kzalloc(sizeof(*bgmac), GFP_KERNEL);
+	bgmac = bgmac_alloc(&core->dev);
 	if (!bgmac)
 		return -ENOMEM;
 
 	bgmac->bcma.core = core;
-	bgmac->dev = &core->dev;
 	bgmac->dma_dev = core->dma_dev;
 	bgmac->irq = core->irq;
 
@@ -285,7 +284,6 @@ static int bgmac_probe(struct bcma_device *core)
 err1:
 	bcma_mdio_mii_unregister(bgmac->mii_bus);
 err:
-	kfree(bgmac);
 	bcma_set_drvdata(core, NULL);
 
 	return err;
diff --git a/drivers/net/ethernet/broadcom/bgmac-platform.c b/drivers/net/ethernet/broadcom/bgmac-platform.c
index be52f27..020f487 100644
--- a/drivers/net/ethernet/broadcom/bgmac-platform.c
+++ b/drivers/net/ethernet/broadcom/bgmac-platform.c
@@ -93,7 +93,7 @@ static int bgmac_probe(struct platform_device *pdev)
 	struct resource *regs;
 	const u8 *mac_addr;
 
-	bgmac = devm_kzalloc(&pdev->dev, sizeof(*bgmac), GFP_KERNEL);
+	bgmac = bgmac_alloc(&pdev->dev);
 	if (!bgmac)
 		return -ENOMEM;
 
diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
index 49f4cafe..537b00b 100644
--- a/drivers/net/ethernet/broadcom/bgmac.c
+++ b/drivers/net/ethernet/broadcom/bgmac.c
@@ -1459,22 +1459,32 @@ static int bgmac_phy_connect(struct bgmac *bgmac)
 	return 0;
 }
 
-int bgmac_enet_probe(struct bgmac *info)
+struct bgmac *bgmac_alloc(struct device *dev)
 {
 	struct net_device *net_dev;
 	struct bgmac *bgmac;
-	int err;
 
 	/* Allocation and references */
-	net_dev = alloc_etherdev(sizeof(*bgmac));
+	net_dev = devm_alloc_etherdev(dev, sizeof(*bgmac));
 	if (!net_dev)
-		return -ENOMEM;
+		return NULL;
 
 	net_dev->netdev_ops = &bgmac_netdev_ops;
 	net_dev->ethtool_ops = &bgmac_ethtool_ops;
+
 	bgmac = netdev_priv(net_dev);
-	memcpy(bgmac, info, sizeof(*bgmac));
+	bgmac->dev = 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;
 	SET_NETDEV_DEV(net_dev, bgmac->dev);
 
@@ -1501,7 +1511,7 @@ int bgmac_enet_probe(struct bgmac *info)
 	err = bgmac_dma_alloc(bgmac);
 	if (err) {
 		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;
@@ -1537,8 +1547,7 @@ int bgmac_enet_probe(struct bgmac *info)
 	phy_disconnect(net_dev->phydev);
 err_dma_free:
 	bgmac_dma_free(bgmac);
-err_netdev_free:
-	free_netdev(net_dev);
+err_out:
 
 	return err;
 }
diff --git a/drivers/net/ethernet/broadcom/bgmac.h b/drivers/net/ethernet/broadcom/bgmac.h
index 80836b4..69d478a 100644
--- a/drivers/net/ethernet/broadcom/bgmac.h
+++ b/drivers/net/ethernet/broadcom/bgmac.h
@@ -515,7 +515,8 @@ struct bgmac {
 			      u32 set);
 };
 
-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);
 
 struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-04-04  6:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-04  6:17 [PATCH 20/33] net: bgmac: allocate struct bgmac just once & don't copy it Amit Pundir
2017-04-04  6:18 ` [PATCH 21/33] net: bgmac: drop struct bcma_mdio we don't need anymore Amit Pundir
2017-04-04  6:18 ` [PATCH 22/33] of: Add check to of_scan_flat_dt() before accessing initial_boot_params Amit Pundir
2017-04-04  6:18 ` [PATCH 23/33] rt2500usb: don't mark register accesses as inline Amit Pundir
2017-04-04  6:18 ` [PATCH 24/33] brcmfmac: check brcmf_bus_get_memdump result for error Amit Pundir
2017-04-04  6:18 ` [PATCH 25/33] brcmfmac: be more verbose when PSM's watchdog fires Amit Pundir
2017-04-04  6:18 ` [PATCH 26/33] brcmfmac: merge two brcmf_err macros into one Amit Pundir
2017-04-04  6:18 ` [PATCH 27/33] brcmfmac: switch to C function (__brcmf_err) for printing errors Amit Pundir
2017-04-04  6:18 ` [PATCH 28/33] brcmfmac: merge two remaining brcmf_err macros Amit Pundir
2017-04-04  6:18 ` [PATCH 29/33] rt2x00usb: do not anchor rx and tx urb's Amit Pundir

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.