devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: of_mdio: count number of regitered phys
@ 2020-06-29  7:26 Claudiu Beznea
  2020-06-30  0:45 ` Andrew Lunn
  0 siblings, 1 reply; 4+ messages in thread
From: Claudiu Beznea @ 2020-06-29  7:26 UTC (permalink / raw)
  To: andrew, f.fainelli, hkallweit1, linux, robh+dt, frowand.list
  Cc: netdev, devicetree, linux-kernel, Claudiu Beznea

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] of: of_mdio: count number of regitered phys
  2020-06-29  7:26 [PATCH] of: of_mdio: count number of regitered phys Claudiu Beznea
@ 2020-06-30  0:45 ` Andrew Lunn
  2020-06-30  3:35   ` Florian Fainelli
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2020-06-30  0:45 UTC (permalink / raw)
  To: Claudiu Beznea
  Cc: f.fainelli, hkallweit1, linux, robh+dt, frowand.list, netdev,
	devicetree, linux-kernel

On Mon, Jun 29, 2020 at 10:26:36AM +0300, Claudiu Beznea wrote:
> 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.

Hi Claudiu

There is a danger here this will break something. Without this patch,
an empty bus is O.K. But with this patch, a bus without a PHY is a
problem.

Take for example FEC. It often comes in pairs. Each has an MDIO
bus. But to save pins, there are some designs which place two PHYs on
one bus, leaving the other empty. The driver unconditionally calls
of_mdiobus_register() and if it returns an error, it will error out
the probe. So i would not be too surprised if you get reports of
missing interfaces with this patch.

	Andrew

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] of: of_mdio: count number of regitered phys
  2020-06-30  0:45 ` Andrew Lunn
@ 2020-06-30  3:35   ` Florian Fainelli
  2020-07-01  8:47     ` Claudiu.Beznea
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Fainelli @ 2020-06-30  3:35 UTC (permalink / raw)
  To: Andrew Lunn, Claudiu Beznea
  Cc: hkallweit1, linux, robh+dt, frowand.list, netdev, devicetree,
	linux-kernel



On 6/29/2020 5:45 PM, Andrew Lunn wrote:
> On Mon, Jun 29, 2020 at 10:26:36AM +0300, Claudiu Beznea wrote:
>> 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.
> 
> Hi Claudiu
> 
> There is a danger here this will break something. Without this patch,
> an empty bus is O.K. But with this patch, a bus without a PHY is a
> problem.
> 
> Take for example FEC. It often comes in pairs. Each has an MDIO
> bus. But to save pins, there are some designs which place two PHYs on
> one bus, leaving the other empty. The driver unconditionally calls
> of_mdiobus_register() and if it returns an error, it will error out
> the probe. So i would not be too surprised if you get reports of
> missing interfaces with this patch.

Agreed, the potential for breakage here is too high especially given
this is fixing a hypothetical problem rather an an actual one. Even if
we were taking this from the angle of power management, runtime PM
should ensure that a MDIO bus with no slave, or no activity gets runtime
suspended.
-- 
Florian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] of: of_mdio: count number of regitered phys
  2020-06-30  3:35   ` Florian Fainelli
@ 2020-07-01  8:47     ` Claudiu.Beznea
  0 siblings, 0 replies; 4+ messages in thread
From: Claudiu.Beznea @ 2020-07-01  8:47 UTC (permalink / raw)
  To: f.fainelli, andrew
  Cc: hkallweit1, linux, robh+dt, frowand.list, netdev, devicetree,
	linux-kernel

Hi Andrew, Florian,

On 30.06.2020 06:35, Florian Fainelli wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On 6/29/2020 5:45 PM, Andrew Lunn wrote:
>> On Mon, Jun 29, 2020 at 10:26:36AM +0300, Claudiu Beznea wrote:
>>> 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.
>>
>> Hi Claudiu
>>
>> There is a danger here this will break something. Without this patch,
>> an empty bus is O.K. But with this patch, a bus without a PHY is a
>> problem.
>>
>> Take for example FEC. It often comes in pairs. Each has an MDIO
>> bus. But to save pins, there are some designs which place two PHYs on
>> one bus, leaving the other empty. The driver unconditionally calls
>> of_mdiobus_register() and if it returns an error, it will error out
>> the probe. So i would not be too surprised if you get reports of
>> missing interfaces with this patch.
> 
> Agreed, the potential for breakage here is too high especially given
> this is fixing a hypothetical problem rather an an actual one. Even if
> we were taking this from the angle of power management, runtime PM
> should ensure that a MDIO bus with no slave, or no activity gets runtime
> suspended.

I understand your points. Thank you for taking time on reviewing this.

Claudiu Beznea

> --
> Florian
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-01  8:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29  7:26 [PATCH] of: of_mdio: count number of regitered phys Claudiu Beznea
2020-06-30  0:45 ` Andrew Lunn
2020-06-30  3:35   ` Florian Fainelli
2020-07-01  8:47     ` Claudiu.Beznea

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).