lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 29 Jun 2020 10:26:36 +0300
From:   Claudiu Beznea <claudiu.beznea@...rochip.com>
To:     <andrew@...n.ch>, <f.fainelli@...il.com>, <hkallweit1@...il.com>,
        <linux@...linux.org.uk>, <robh+dt@...nel.org>,
        <frowand.list@...il.com>
CC:     <netdev@...r.kernel.org>, <devicetree@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>,
        Claudiu Beznea <claudiu.beznea@...rochip.com>
Subject: [PATCH] of: of_mdio: count number of regitered phys

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@...rochip.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ