All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: netdev@vger.kernel.org
Cc: Florian Fainelli <f.fainelli@gmail.com>,
	andrew@lunn.ch, vivien.didelot@savoirfairelinux.com,
	cphealy@gmail.com, davem@davemloft.net,
	nikita.yoush@cogentembedded.com
Subject: [PATCH net-next 5/8] net: dsa: Add helper function to obtain PHY device of a given port
Date: Wed, 25 Apr 2018 12:12:51 -0700	[thread overview]
Message-ID: <20180425191254.3467-6-f.fainelli@gmail.com> (raw)
In-Reply-To: <20180425191254.3467-1-f.fainelli@gmail.com>

In preparation for having more call sites attempting to obtain a
reference against a PHY device corresponding to a particular port,
introduce a helper function for that purpose.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 net/dsa/port.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/net/dsa/port.c b/net/dsa/port.c
index 7acc1169d75e..5e2a88720a9a 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -273,25 +273,38 @@ int dsa_port_vlan_del(struct dsa_port *dp,
 	return 0;
 }
 
-static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable)
+static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp)
 {
-	struct device_node *port_dn = dp->dn;
 	struct device_node *phy_dn;
-	struct dsa_switch *ds = dp->ds;
 	struct phy_device *phydev;
-	int port = dp->index;
-	int err = 0;
 
-	phy_dn = of_parse_phandle(port_dn, "phy-handle", 0);
+	phy_dn = of_parse_phandle(dp->dn, "phy-handle", 0);
 	if (!phy_dn)
-		return 0;
+		return NULL;
 
 	phydev = of_phy_find_device(phy_dn);
 	if (!phydev) {
-		err = -EPROBE_DEFER;
-		goto err_put_of;
+		of_node_put(phy_dn);
+		return ERR_PTR(-EPROBE_DEFER);
 	}
 
+	return phydev;
+}
+
+static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable)
+{
+	struct dsa_switch *ds = dp->ds;
+	struct phy_device *phydev;
+	int port = dp->index;
+	int err = 0;
+
+	phydev = dsa_port_get_phy_device(dp);
+	if (!phydev)
+		return 0;
+
+	if (IS_ERR(phydev))
+		return PTR_ERR(phydev);
+
 	if (enable) {
 		err = genphy_config_init(phydev);
 		if (err < 0)
@@ -317,8 +330,6 @@ static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable)
 
 err_put_dev:
 	put_device(&phydev->mdio.dev);
-err_put_of:
-	of_node_put(phy_dn);
 	return err;
 }
 
-- 
2.14.1

  parent reply	other threads:[~2018-04-25 19:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-25 19:12 [PATCH net-next 0/8] net: Extend availability of PHY statistics Florian Fainelli
2018-04-25 19:12 ` [PATCH net-next 1/8] net: Move PHY statistics code into PHY library helpers Florian Fainelli
2018-04-25 19:12 ` [PATCH net-next 2/8] net: Allow network devices to have PHY statistics Florian Fainelli
2018-04-25 19:12 ` [PATCH net-next 3/8] net: dsa: Do not check for ethtool_ops validity Florian Fainelli
2018-04-25 19:12 ` [PATCH net-next 4/8] net: dsa: Pass stringset to ethtool operations Florian Fainelli
2018-04-25 19:12 ` Florian Fainelli [this message]
2018-04-25 19:12 ` [PATCH net-next 6/8] net: dsa: Allow providing PHY statistics from CPU port Florian Fainelli
2018-04-25 19:12 ` [PATCH net-next 7/8] net: dsa: b53: Add support for reading PHY statistics Florian Fainelli
2018-04-25 19:12 ` [PATCH net-next 8/8] net: dsa: loop: Hook " Florian Fainelli
2018-04-26 15:22 ` [PATCH net-next 0/8] net: Extend availability of " Nikita Yushchenko
2018-04-27 16:00 ` David Miller
2018-04-27 16:10   ` David Miller
2018-04-27 17:13     ` David Miller
2018-04-27 17:19       ` Florian Fainelli
2018-04-27 17:27         ` Florian Fainelli
2018-04-27 17:33           ` David Miller
2018-04-27 17:15     ` Florian Fainelli

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=20180425191254.3467-6-f.fainelli@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=cphealy@gmail.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=nikita.yoush@cogentembedded.com \
    --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 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.