From: Claudiu Beznea <claudiu.beznea@microchip.com>
To: <andrew@lunn.ch>, <f.fainelli@gmail.com>, <hkallweit1@gmail.com>,
<linux@armlinux.org.uk>, <robh+dt@kernel.org>,
<frowand.list@gmail.com>
Cc: <netdev@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
Claudiu Beznea <claudiu.beznea@microchip.com>
Subject: [PATCH] of: of_mdio: count number of regitered phys
Date: Mon, 29 Jun 2020 10:26:36 +0300 [thread overview]
Message-ID: <1593415596-9487-1-git-send-email-claudiu.beznea@microchip.com> (raw)
In case of_mdiobus_register_phy()/of_mdiobus_register_device()
returns -ENODEV for all PHYs in device tree or for all scanned
PHYs there is a chance that of_mdiobus_register() to
return success code although no PHY devices were registered.
Add a counter that increments every time a PHY was registered
to avoid the above scenario.
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
Though I haven't encountered the scenario described in commit
message. Just went through this code and seemed to me that it
could be enhanved by checking the number of successfuly
registered devices.
Thank you,
Claudiu Beznea
drivers/of/of_mdio.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index eb84507de28a..bbf1d42d27f8 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -249,7 +249,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
{
struct device_node *child;
bool scanphys = false;
- int addr, rc;
+ int addr, rc, devices = 0;
if (!np)
return mdiobus_register(mdio);
@@ -293,9 +293,11 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
addr);
else if (rc)
goto unregister;
+ else
+ devices++;
}
- if (!scanphys)
+ if (!scanphys && devices)
return 0;
/* auto scan for PHYs with empty reg property */
@@ -319,14 +321,21 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
* scanning should continue.
*/
rc = of_mdiobus_register_phy(mdio, child, addr);
- if (!rc)
+ if (!rc) {
+ devices++;
break;
+ }
if (rc != -ENODEV)
goto unregister;
}
}
}
+ if (!devices) {
+ rc = -ENODEV;
+ goto unregister;
+ }
+
return 0;
unregister:
--
2.7.4
next reply other threads:[~2020-06-29 18:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-29 7:26 Claudiu Beznea [this message]
2020-06-30 0:45 ` [PATCH] of: of_mdio: count number of regitered phys Andrew Lunn
2020-06-30 3:35 ` Florian Fainelli
2020-07-01 8:47 ` Claudiu.Beznea
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=1593415596-9487-1-git-send-email-claudiu.beznea@microchip.com \
--to=claudiu.beznea@microchip.com \
--cc=andrew@lunn.ch \
--cc=devicetree@vger.kernel.org \
--cc=f.fainelli@gmail.com \
--cc=frowand.list@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=robh+dt@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).