From: Florian Fainelli <f.fainelli@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, andrew@lunn.ch, Woojung.Huh@microchip.com
Subject: Re: [PATCH net-next] net: phy: Relax error checking on sysfs_create_link()
Date: Sat, 27 May 2017 08:40:54 -0700 [thread overview]
Message-ID: <021D486A-A81D-45F6-BB66-8FF075B03F70@gmail.com> (raw)
In-Reply-To: <20170527033418.3583-1-f.fainelli@gmail.com>
On May 26, 2017 8:34:18 PM PDT, Florian Fainelli <f.fainelli@gmail.com> wrote:
>Some Ethernet drivers will attach/connect to a PHY device before
>calling
>register_netdevice() which is responsible for calling
>netdev_register_kobject()
>which would do the network device's kobject initialization. In such a
>case,
>sysfs_create_link() would return -ENOENT because the network device's
>kobject
>is not ready yet, and we would fail to connect to the PHY device.
>
>In order to keep things simple and symetrical, we just take the success
>path as
>indicative of the ability to access the network device's kobject, and
>create
>the second link if that's the case.
>
>Fixes: 5568363f0cb3 ("net: phy: Create sysfs reciprocal links for
>attached_dev/phydev")
>Reported-by: Woojung Hung <Woojung.Huh@microchip.com>
>Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
>---
> drivers/net/phy/phy_device.c | 28 ++++++++++++++++++++--------
> include/linux/phy.h | 2 ++
> 2 files changed, 22 insertions(+), 8 deletions(-)
>
>diff --git a/drivers/net/phy/phy_device.c
>b/drivers/net/phy/phy_device.c
>index f84414b8f2ee..523366bd705a 100644
>--- a/drivers/net/phy/phy_device.c
>+++ b/drivers/net/phy/phy_device.c
>@@ -960,15 +960,25 @@ int phy_attach_direct(struct net_device *dev,
>struct phy_device *phydev,
>
> phydev->attached_dev = dev;
> dev->phydev = phydev;
>+
>+ /* Some Ethernet drivers try to connect to a PHY device before
>+ * calling register_netdevice() -> netdev_register_kobject() and
>+ * does the dev->dev.kobj initialization. Here we only check for
>+ * success which indicates that the network device kobject is
>+ * ready. Once we do that we still need to keep track of whether
>+ * links were successfully set up or not for phy_detach() to
>+ * remove them accordingly.
>+ */
> err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj,
> "attached_dev");
>- if (err)
>- goto error;
>+ if (!err) {
>+ err = sysfs_create_link(&dev->dev.kobj, &phydev->mdio.dev.kobj,
>+ "phydev");
>+ if (err)
>+ goto error;
>
>- err = sysfs_create_link(&dev->dev.kobj, &phydev->mdio.dev.kobj,
>- "phydev");
>- if (err)
>- goto error;
>+ phydev->sysfs_links = true;
>+ }
>
We should not assume that this Boolean will be true or false if we enter this function a second time, v2 coming.
--
Florian
prev parent reply other threads:[~2017-05-27 15:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-27 3:34 [PATCH net-next] net: phy: Relax error checking on sysfs_create_link() Florian Fainelli
2017-05-27 15:40 ` Florian Fainelli [this message]
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=021D486A-A81D-45F6-BB66-8FF075B03F70@gmail.com \
--to=f.fainelli@gmail.com \
--cc=Woojung.Huh@microchip.com \
--cc=andrew@lunn.ch \
--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