From: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
To: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel@savoirfairelinux.com,
"David S. Miller" <davem@davemloft.net>,
Florian Fainelli <f.fainelli@gmail.com>,
Andrew Lunn <andrew@lunn.ch>,
Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Subject: [PATCH net-next 08/11] net: dsa: use of_for_each_phandle
Date: Mon, 6 Nov 2017 16:11:50 -0500 [thread overview]
Message-ID: <20171106211153.26529-9-vivien.didelot@savoirfairelinux.com> (raw)
In-Reply-To: <20171106211153.26529-1-vivien.didelot@savoirfairelinux.com>
The OF code provides a of_for_each_phandle() helper to iterate over
phandles. Use it instead of arbitrary iterating ourselves over the list
of phandles hanging to the "link" property of the port's device node.
The of_phandle_iterator_next() helper calls of_node_put() itself on
it.node. Thus We must only do it ourselves if we break the loop.
Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
---
net/dsa/dsa2.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 0f6f8c1701f9..25ed41262ead 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -145,21 +145,18 @@ static int dsa_port_complete(struct dsa_switch_tree *dst,
struct dsa_port *port,
u32 src_port)
{
- struct device_node *link;
- int index;
+ struct device_node *dn = port->dn;
+ struct of_phandle_iterator it;
struct dsa_switch *dst_ds;
struct dsa_port *link_dp;
+ int err;
- for (index = 0;; index++) {
- link = of_parse_phandle(port->dn, "link", index);
- if (!link)
- break;
-
- link_dp = dsa_tree_find_port_by_node(dst, link);
- of_node_put(link);
-
- if (!link_dp)
+ of_for_each_phandle(&it, err, dn, "link", NULL, 0) {
+ link_dp = dsa_tree_find_port_by_node(dst, it.node);
+ if (!link_dp) {
+ of_node_put(it.node);
return 1;
+ }
dst_ds = link_dp->ds;
--
2.14.3
next prev parent reply other threads:[~2017-11-06 21:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-06 21:11 [PATCH net-next 00/11] net: dsa: setup stage Vivien Didelot
2017-11-06 21:11 ` [PATCH net-next 01/11] net: dsa: constify cpu_dp member of dsa_port Vivien Didelot
2017-11-07 1:47 ` Florian Fainelli
2017-11-06 21:11 ` [PATCH net-next 02/11] net: dsa: setup and teardown default CPU port Vivien Didelot
2017-11-06 21:11 ` [PATCH net-next 03/11] net: dsa: setup and teardown master device Vivien Didelot
2017-11-06 21:11 ` [PATCH net-next 04/11] net: dsa: setup and teardown tree Vivien Didelot
2017-11-06 21:11 ` [PATCH net-next 05/11] net: dsa: setup and teardown switches Vivien Didelot
2017-11-06 21:11 ` [PATCH net-next 06/11] net: dsa: setup and teardown ports Vivien Didelot
2017-11-06 21:11 ` [PATCH net-next 07/11] net: dsa: add find port by node helper Vivien Didelot
2017-11-06 21:11 ` Vivien Didelot [this message]
2017-11-06 21:11 ` [PATCH net-next 09/11] net: dsa: setup routing table Vivien Didelot
2017-11-06 21:11 ` [PATCH net-next 10/11] net: dsa: setup a tree when adding a switch to it Vivien Didelot
2017-11-06 21:11 ` [PATCH net-next 11/11] net: dsa: rename probe and remove switch functions Vivien Didelot
2017-11-09 0:29 ` [PATCH net-next 00/11] net: dsa: setup stage David Miller
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=20171106211153.26529-9-vivien.didelot@savoirfairelinux.com \
--to=vivien.didelot@savoirfairelinux.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=kernel@savoirfairelinux.com \
--cc=linux-kernel@vger.kernel.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
all inboxes | Powered by JetHome®