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-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230405-net-next-topic-net-phy-reset-v1-7-7e5329f08002@pengutronix.de>
Date:   Wed, 05 Apr 2023 11:26:58 +0200
From:   Marco Felsch <m.felsch@...gutronix.de>
To:     Andrew Lunn <andrew@...n.ch>,
        Heiner Kallweit <hkallweit1@...il.com>,
        Russell King <linux@...linux.org.uk>,
        "David S. Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>,
        Florian Fainelli <f.fainelli@...il.com>,
        Broadcom internal kernel review list 
        <bcm-kernel-feedback-list@...adcom.com>,
        Richard Cochran <richardcochran@...il.com>,
        Radu Pirea <radu-nicolae.pirea@....nxp.com>,
        Shyam Sundar S K <Shyam-sundar.S-k@....com>,
        Yisen Zhuang <yisen.zhuang@...wei.com>,
        Salil Mehta <salil.mehta@...wei.com>,
        Jassi Brar <jaswinder.singh@...aro.org>,
        Ilias Apalodimas <ilias.apalodimas@...aro.org>,
        Iyappan Subramanian <iyappan@...amperecomputing.com>,
        Keyur Chudgar <keyur@...amperecomputing.com>,
        Quan Nguyen <quan@...amperecomputing.com>,
        "Rafael J. Wysocki" <rafael@...nel.org>,
        Len Brown <lenb@...nel.org>, Rob Herring <robh+dt@...nel.org>,
        Frank Rowand <frowand.list@...il.com>
Cc:     netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
        linux-acpi@...r.kernel.org, devicetree@...r.kernel.org,
        kernel@...gutronix.de
Subject: [PATCH 07/12] net: mdio: make use of phy_device_atomic_register
 helper

The current fwnode_mdiobus_register_phy() implementation assume that the
phy is accessible to read the PHYID register values first which isn't
the case in some cases. Fix this by using the new
phy_device_atomic_register() helper which ensures that the prerequisites
are fulfilled before accessing the PHYID registers.

Signed-off-by: Marco Felsch <m.felsch@...gutronix.de>
---
 Documentation/firmware-guide/acpi/dsd/phy.rst |  2 +-
 drivers/net/mdio/acpi_mdio.c                  | 18 ++++++++++++------
 drivers/net/mdio/of_mdio.c                    | 13 ++++++++++++-
 3 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/Documentation/firmware-guide/acpi/dsd/phy.rst b/Documentation/firmware-guide/acpi/dsd/phy.rst
index 673ac374f92a..489e978c7412 100644
--- a/Documentation/firmware-guide/acpi/dsd/phy.rst
+++ b/Documentation/firmware-guide/acpi/dsd/phy.rst
@@ -5,7 +5,7 @@ MDIO bus and PHYs in ACPI
 =========================
 
 The PHYs on an MDIO bus [phy] are probed and registered using
-fwnode_mdiobus_register_phy().
+phy_device_atomic_register().
 
 Later, for connecting these PHYs to their respective MACs, the PHYs registered
 on the MDIO bus have to be referenced.
diff --git a/drivers/net/mdio/acpi_mdio.c b/drivers/net/mdio/acpi_mdio.c
index 4630dde01974..25feb571bd1f 100644
--- a/drivers/net/mdio/acpi_mdio.c
+++ b/drivers/net/mdio/acpi_mdio.c
@@ -31,8 +31,10 @@ MODULE_LICENSE("GPL");
 int __acpi_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode,
 			    struct module *owner)
 {
+	struct phy_device_config config = {
+		.mii_bus = mdio,
+	};
 	struct fwnode_handle *child;
-	u32 addr;
 	int ret;
 
 	/* Mask out all PHYs from auto probing. */
@@ -45,15 +47,19 @@ int __acpi_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode,
 
 	/* Loop over the child nodes and register a phy_device for each PHY */
 	fwnode_for_each_child_node(fwnode, child) {
-		ret = acpi_get_local_address(ACPI_HANDLE_FWNODE(child), &addr);
-		if (ret || addr >= PHY_MAX_ADDR)
+		struct phy_device *phy;
+
+		ret = acpi_get_local_address(ACPI_HANDLE_FWNODE(child),
+					     &config.phy_addr);
+		if (ret || config.phy_addr >= PHY_MAX_ADDR)
 			continue;
 
-		ret = fwnode_mdiobus_register_phy(mdio, child, addr);
-		if (ret == -ENODEV)
+		config.fwnode = child;
+		phy = phy_device_atomic_register(&config);
+		if (PTR_ERR(phy) == -ENODEV)
 			dev_err(&mdio->dev,
 				"MDIO device at address %d is missing.\n",
-				addr);
+				config.phy_addr);
 	}
 	return 0;
 }
diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c
index 7eb32ebb846d..10dd45c3bde0 100644
--- a/drivers/net/mdio/of_mdio.c
+++ b/drivers/net/mdio/of_mdio.c
@@ -45,7 +45,18 @@ EXPORT_SYMBOL(of_mdiobus_phy_device_register);
 static int of_mdiobus_register_phy(struct mii_bus *mdio,
 				    struct device_node *child, u32 addr)
 {
-	return fwnode_mdiobus_register_phy(mdio, of_fwnode_handle(child), addr);
+	struct phy_device_config config = {
+		.mii_bus = mdio,
+		.phy_addr = addr,
+		.fwnode = of_fwnode_handle(child),
+	};
+	struct phy_device *phy;
+
+	phy = phy_device_atomic_register(&config);
+	if (IS_ERR(phy))
+		return PTR_ERR(phy);
+
+	return 0;
 }
 
 static int of_mdiobus_register_device(struct mii_bus *mdio,

-- 
2.39.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ