netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, computersforpeace@gmail.com,
	andrey.volkov@nexvision.fr,
	Florian Fainelli <f.fainelli@gmail.com>
Subject: [PATCH net 2/2] net: dsa: propagate error code from dsa_slave_phy_setup
Date: Thu, 11 Dec 2014 12:49:16 -0800	[thread overview]
Message-ID: <1418330956-17151-3-git-send-email-f.fainelli@gmail.com> (raw)
In-Reply-To: <1418330956-17151-1-git-send-email-f.fainelli@gmail.com>

In case we cannot attach to our slave netdevice PHY, error out and
propagate that error up to the caller: dsa_slave_create().

Fixes: 0d8bcdd383b8 ("net: dsa: allow for more complex PHY setups")
Signed-off-by: Andrey Volkov <andrey.volkov@nexvision.fr>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 net/dsa/slave.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 0efaab1e408b..646c24ce4501 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -448,7 +448,7 @@ static int dsa_slave_fixed_link_update(struct net_device *dev,
 }
 
 /* slave device setup *******************************************************/
-static void dsa_slave_phy_setup(struct dsa_slave_priv *p,
+static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
 				struct net_device *slave_dev)
 {
 	struct dsa_switch *ds = p->parent;
@@ -469,7 +469,7 @@ static void dsa_slave_phy_setup(struct dsa_slave_priv *p,
 		ret = of_phy_register_fixed_link(port_dn);
 		if (ret) {
 			pr_err("failed to register fixed PHY\n");
-			return;
+			return ret;
 		}
 		phy_is_fixed = true;
 		phy_dn = port_dn;
@@ -492,7 +492,7 @@ static void dsa_slave_phy_setup(struct dsa_slave_priv *p,
 	if (!p->phy) {
 		p->phy = ds->slave_mii_bus->phy_map[p->port];
 		if (!p->phy)
-			return;
+			return -ENODEV;
 
 		phy_connect_direct(slave_dev, p->phy, dsa_slave_adjust_link,
 				   p->phy_interface);
@@ -500,6 +500,8 @@ static void dsa_slave_phy_setup(struct dsa_slave_priv *p,
 		pr_info("attached PHY at address %d [%s]\n",
 			p->phy->addr, p->phy->drv->name);
 	}
+
+	return 0;
 }
 
 int dsa_slave_suspend(struct net_device *slave_dev)
@@ -592,12 +594,17 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent,
 	p->old_link = -1;
 	p->old_duplex = -1;
 
-	dsa_slave_phy_setup(p, slave_dev);
+	ret = dsa_slave_phy_setup(p, slave_dev);
+	if (ret) {
+		free_netdev(slave_dev);
+		return NULL;
+	}
 
 	ret = register_netdev(slave_dev);
 	if (ret) {
 		printk(KERN_ERR "%s: error %d registering interface %s\n",
 				master->name, ret, slave_dev->name);
+		phy_disconnect(p->phy);
 		free_netdev(slave_dev);
 		return NULL;
 	}
-- 
2.1.0

  parent reply	other threads:[~2014-12-11 20:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-11 20:49 [PATCH net 0/2] net: dsa: two small bug fixes Florian Fainelli
2014-12-11 20:49 ` [PATCH net 1/2] net: dsa: handle non-existing PHYs on switch internal bus Florian Fainelli
2014-12-16 10:24   ` Andrew Lunn
2014-12-11 20:49 ` Florian Fainelli [this message]
2014-12-12  2:00 ` [PATCH net 0/2] net: dsa: two small bug fixes 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=1418330956-17151-3-git-send-email-f.fainelli@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=andrey.volkov@nexvision.fr \
    --cc=computersforpeace@gmail.com \
    --cc=davem@davemloft.net \
    --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).