From: Andrew Lunn <andrew@lunn.ch>
To: Florian Fainelli <f.fainelli@gmail.com>,
Vivien Didelot <vivien.didelot@savoirfairelinux.com>,
netdev <netdev@vger.kernel.org>
Subject: [PATCH RFC v2 01/32] net: dsa: Move platform data allocation for OF
Date: Sun, 28 Feb 2016 17:41:09 +0100 [thread overview]
Message-ID: <1456677700-23027-2-git-send-email-andrew@lunn.ch> (raw)
In-Reply-To: <1456677700-23027-1-git-send-email-andrew@lunn.ch>
From: Florian Fainelli <f.fainelli@gmail.com>
Do not have dsa_of_probe() allocate and assign struct dsa_platform_data,
but instead do this outside of this function such that we can control
exactly the storage of that data structure.
This is a preliminary change to allow multiple callers of dsa_of_probe()
not to clobber an existing dsa_platform_data and later, control where
this data structure is coming from.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
net/dsa/dsa.c | 48 +++++++++++++++++++-----------------------------
1 file changed, 19 insertions(+), 29 deletions(-)
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index fa4daba8db55..be68c00b8cfd 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -651,13 +651,12 @@ static void dsa_of_free_platform_data(struct dsa_platform_data *pd)
kfree(pd->chip);
}
-static int dsa_of_probe(struct device *dev)
+static int dsa_of_probe(struct device *dev, struct dsa_platform_data *pd)
{
struct device_node *np = dev->of_node;
struct device_node *child, *mdio, *ethernet, *port;
struct mii_bus *mdio_bus, *mdio_bus_switch;
struct net_device *ethernet_dev;
- struct dsa_platform_data *pd;
struct dsa_chip_data *cd;
const char *port_name;
int chip_index, port_index;
@@ -666,7 +665,7 @@ static int dsa_of_probe(struct device *dev)
enum of_gpio_flags of_flags;
unsigned long flags;
u32 eeprom_len;
- int ret;
+ int ret = 0;
mdio = of_parse_phandle(np, "dsa,mii-bus", 0);
if (!mdio)
@@ -688,13 +687,6 @@ static int dsa_of_probe(struct device *dev)
goto out_put_mdio;
}
- pd = kzalloc(sizeof(*pd), GFP_KERNEL);
- if (!pd) {
- ret = -ENOMEM;
- goto out_put_ethernet;
- }
-
- dev->platform_data = pd;
pd->of_netdev = ethernet_dev;
pd->nr_chips = of_get_available_child_count(np);
if (pd->nr_chips > DSA_MAX_SWITCHES)
@@ -702,10 +694,8 @@ static int dsa_of_probe(struct device *dev)
pd->chip = kcalloc(pd->nr_chips, sizeof(struct dsa_chip_data),
GFP_KERNEL);
- if (!pd->chip) {
- ret = -ENOMEM;
- goto out_free;
- }
+ if (!pd->chip)
+ goto out_put_mdio;
chip_index = -1;
for_each_available_child_of_node(np, child) {
@@ -795,34 +785,29 @@ static int dsa_of_probe(struct device *dev)
out_free_chip:
dsa_of_free_platform_data(pd);
-out_free:
- kfree(pd);
- dev->platform_data = NULL;
-out_put_ethernet:
- put_device(ðernet_dev->dev);
+
out_put_mdio:
put_device(&mdio_bus->dev);
return ret;
}
-static void dsa_of_remove(struct device *dev)
+static void dsa_of_remove(struct device *dev, struct dsa_platform_data *pd)
{
- struct dsa_platform_data *pd = dev->platform_data;
-
if (!dev->of_node)
return;
dsa_of_free_platform_data(pd);
put_device(&pd->of_netdev->dev);
- kfree(pd);
}
#else
-static inline int dsa_of_probe(struct device *dev)
+static inline int dsa_of_probe(struct device *dev,
+ struct dsa_platform_data *pd)
{
return 0;
}
-static inline void dsa_of_remove(struct device *dev)
+static inline void dsa_of_remove(struct device *dev,
+ struct dsa_platform_data *pd)
{
}
#endif
@@ -881,11 +866,15 @@ static int dsa_probe(struct platform_device *pdev)
dsa_driver_version);
if (pdev->dev.of_node) {
- ret = dsa_of_probe(&pdev->dev);
+ pd = devm_kzalloc(&pdev->dev, sizeof(*pd), GFP_KERNEL);
+ if (!pd)
+ return -ENOMEM;
+
+ ret = dsa_of_probe(&pdev->dev, pd);
if (ret)
return ret;
- pd = pdev->dev.platform_data;
+ pdev->dev.platform_data = pd;
}
if (pd == NULL || (pd->netdev == NULL && pd->of_netdev == NULL))
@@ -926,7 +915,7 @@ static int dsa_probe(struct platform_device *pdev)
return 0;
out:
- dsa_of_remove(&pdev->dev);
+ dsa_of_remove(&pdev->dev, pd);
return ret;
}
@@ -948,9 +937,10 @@ static void dsa_remove_dst(struct dsa_switch_tree *dst)
static int dsa_remove(struct platform_device *pdev)
{
struct dsa_switch_tree *dst = platform_get_drvdata(pdev);
+ struct dsa_platform_data *pd = pdev->dev.platform_data;
dsa_remove_dst(dst);
- dsa_of_remove(&pdev->dev);
+ dsa_of_remove(&pdev->dev, pd);
return 0;
}
--
2.7.0
next prev parent reply other threads:[~2016-02-28 16:41 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-28 16:41 [PATCH RFC v2 00/32] Make DSA switches linux devices Andrew Lunn
2016-02-28 16:41 ` Andrew Lunn [this message]
2016-02-28 16:41 ` [PATCH RFC v2 02/32] dsa: Rename mv88e6123_61_65 to mv88e6123 to be consistent Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 03/32] dsa: Make setup and finish more symmetrical Andrew Lunn
2016-03-11 23:54 ` Florian Fainelli
2016-02-28 16:41 ` [PATCH RFC v2 04/32] net: dsa: Pass the dsa device to the switch drivers Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 05/32] net: dsa: Have the switch driver allocate there own private memory Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 06/32] net: dsa: Remove allocation of driver " Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 07/32] net: dsa: Keep the mii bus and address in the private structure Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 08/32] net: dsa: dsa.c: Refactor to increase symmetry Andrew Lunn
2016-03-11 23:54 ` Florian Fainelli
2016-02-28 16:41 ` [PATCH RFC v2 09/32] driver: component: Add support for empty match table Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 10/32] net: dsa: Add basic support for component master support Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 11/32] net: dsa: Keep a reference to the switch device for component matching Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 12/32] net: dsa: Add slave component matches based on a phandle to the slave Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 13/32] net: dsa: Make dsa,mii-bus optional Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 14/32] net: dsa: Add register/unregister functions for switch drivers Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 15/32] net: dsa: Rename DSA probe function Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 16/32] dsa: mv88e6xxx: Use bus in mv88e6xxx_lookup_name() Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 17/32] dsa: mv88e6xxx: Add shared code for binding/unbinding a switch driver Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 18/32] dsa: mv88e6xxx: Prepare for turning this into a library module Andrew Lunn
2016-02-29 2:40 ` Vivien Didelot
2016-02-29 14:53 ` Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 19/32] dsa: mv88e6xxx: Add macro for registering the drivers Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 20/32] dsa: Add mdio device support to Marvell switches Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 21/32] net: mdio: Add mdiodev_{read|write} helpers Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 22/32] net: dsa: Better integrate the drivers with mdio device Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 23/32] net: dsa: bcm_sf2: make it a real platform driver Andrew Lunn
2016-03-03 18:33 ` Florian Fainelli
2016-03-03 19:12 ` Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 24/32] net: dsa: Add some debug prints for error cases Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 25/32] net: dsa: Setup the switches after all have been probed Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 26/32] net: dsa: Only setup platform switches, not device switches Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 27/32] net: dsa: If a switch fails to probe, defer probing Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 28/32] Documentation: DSA: Describe how probe of DSA and switches work Andrew Lunn
2016-02-29 11:42 ` Sergei Shtylyov
2016-02-28 16:41 ` [PATCH RFC v2 29/32] dsa: slave: Don't reference NULL pointer during phy_disconnect Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 30/32] dsa: Destroy fixed link phys after the phy has been disconnected Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 31/32] dsa: dsa: Fix freeing of fixed-phys from user ports Andrew Lunn
2016-02-28 16:41 ` [PATCH RFC v2 32/32] phy: fixed: Fix removal of phys Andrew Lunn
2016-03-03 18:49 ` [PATCH RFC v2 00/32] Make DSA switches linux devices Florian Fainelli
2016-03-03 20:27 ` Andrew Lunn
2016-03-11 23:41 ` Florian Fainelli
2016-03-12 17:08 ` Andrew Lunn
2016-03-13 7:26 ` Vivien Didelot
2016-03-14 19:36 ` Florian Fainelli
2016-03-14 20:51 ` Andrew Lunn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1456677700-23027-2-git-send-email-andrew@lunn.ch \
--to=andrew@lunn.ch \
--cc=f.fainelli@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=vivien.didelot@savoirfairelinux.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).