From: Andrew Lunn <andrew@lunn.ch>
To: netdev <netdev@vger.kernel.org>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
Guenter Roeck <linux@roeck-us.net>,
mathieu@codeaurora.org, Andrew Lunn <andrew@lunn.ch>
Subject: [PATCH RFC 1/3] net: dsa: Refactor DT probing of a switch port
Date: Fri, 29 May 2015 21:13:32 +0200 [thread overview]
Message-ID: <1432926814-22648-2-git-send-email-andrew@lunn.ch> (raw)
In-Reply-To: <1432926814-22648-1-git-send-email-andrew@lunn.ch>
Move the DT probing of a switch port into a function of its own, since
it is about to get more complex. Add better error handling as well.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
net/dsa/dsa.c | 77 ++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 44 insertions(+), 33 deletions(-)
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index e6f6cc3a1bcf..b7b72d398d00 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -570,17 +570,54 @@ static void dsa_of_free_platform_data(struct dsa_platform_data *pd)
kfree(pd->chip);
}
+static int dsa_of_probe_port(struct dsa_platform_data *pd,
+ struct dsa_chip_data *cd,
+ int chip_index,
+ struct device_node *port)
+{
+ const unsigned int *port_reg;
+ const char *port_name;
+ struct device_node *link;
+ int port_index, ret;
+
+ port_reg = of_get_property(port, "reg", NULL);
+ if (!port_reg)
+ return -EINVAL;
+
+ port_index = be32_to_cpup(port_reg);
+
+ port_name = of_get_property(port, "label", NULL);
+ if (!port_name)
+ return -EINVAL;
+
+ cd->port_dn[port_index] = port;
+
+ cd->port_names[port_index] = kstrdup(port_name, GFP_KERNEL);
+ if (!cd->port_names[port_index])
+ return -ENOMEM;
+
+ link = of_parse_phandle(port, "link", 0);
+
+ if (!strcmp(port_name, "dsa") && link && pd->nr_chips > 1) {
+ ret = dsa_of_setup_routing_table(pd, cd,
+ chip_index, port_index, link);
+ if (ret)
+ return ret;
+ }
+
+ return port_index;
+}
+
static int dsa_of_probe(struct device *dev)
{
struct device_node *np = dev->of_node;
- struct device_node *child, *mdio, *ethernet, *port, *link;
+ struct device_node *child, *mdio, *ethernet, *port;
struct mii_bus *mdio_bus;
struct net_device *ethernet_dev;
struct dsa_platform_data *pd;
struct dsa_chip_data *cd;
- const char *port_name;
- int chip_index, port_index;
- const unsigned int *sw_addr, *port_reg;
+ int chip_index;
+ const unsigned int *sw_addr;
u32 eeprom_len;
int ret;
@@ -637,36 +674,10 @@ static int dsa_of_probe(struct device *dev)
cd->eeprom_len = eeprom_len;
for_each_available_child_of_node(child, port) {
- port_reg = of_get_property(port, "reg", NULL);
- if (!port_reg)
- continue;
-
- port_index = be32_to_cpup(port_reg);
-
- port_name = of_get_property(port, "label", NULL);
- if (!port_name)
- continue;
-
- cd->port_dn[port_index] = port;
-
- cd->port_names[port_index] = kstrdup(port_name,
- GFP_KERNEL);
- if (!cd->port_names[port_index]) {
- ret = -ENOMEM;
+ ret = dsa_of_probe_port(pd, cd, chip_index, port);
+ if (ret < 0)
goto out_free_chip;
- }
-
- link = of_parse_phandle(port, "link", 0);
-
- if (!strcmp(port_name, "dsa") && link &&
- pd->nr_chips > 1) {
- ret = dsa_of_setup_routing_table(pd, cd,
- chip_index, port_index, link);
- if (ret)
- goto out_free_chip;
- }
-
- if (port_index == DSA_MAX_PORTS)
+ if (ret == DSA_MAX_PORTS)
break;
}
}
--
2.1.4
next prev parent reply other threads:[~2015-05-29 19:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-29 19:13 [PATCH RFC 0/3] DSA: Support multiple CPU ports Andrew Lunn
2015-05-29 19:13 ` Andrew Lunn [this message]
2015-05-29 19:13 ` [PATCH RFC 2/3] dsa: Add support for multiple cpu ports Andrew Lunn
2015-05-30 12:09 ` Bjørn Mork
2015-05-31 0:05 ` Sergey Ryazanov
2015-06-01 0:51 ` Andrew Lunn
2015-06-01 7:23 ` Bjørn Mork
2015-05-29 19:13 ` [PATCH RFC 3/3] kirkwood: dir665: Enable the second Ethernet to the Switch 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=1432926814-22648-2-git-send-email-andrew@lunn.ch \
--to=andrew@lunn.ch \
--cc=f.fainelli@gmail.com \
--cc=linux@roeck-us.net \
--cc=mathieu@codeaurora.org \
--cc=netdev@vger.kernel.org \
/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).