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]
Message-ID: <20251216070333.2452582-2-u.kleine-koenig@baylibre.com>
Date: Tue, 16 Dec 2025 08:03:33 +0100
From: Uwe Kleine-König <u.kleine-koenig@...libre.com>
To: Andrew Lunn <andrew@...n.ch>,
	Heiner Kallweit <hkallweit1@...il.com>
Cc: 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>,
	netdev@...r.kernel.org
Subject: [PATCH net-next] mdio: Make use of bus callbacks

Introduce a bus specific probe, remove and shutdown function.

The objective is to get rid of users of struct device_driver callbacks
.probe(), .remove() and .shutdown() to eventually remove these.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@...libre.com>
---
Hello,

this is part of an effort to drop the callbacks in struct device_driver.

The only relevant differences between the driver callbacks and the bus
callbacks is that .remove() returns void for the latter and .shutdown()
is also called for unbound devices (so mdio_bus_shutdown() has to check
for drv != NULL).

Best regards
Uwe

 drivers/net/phy/mdio_bus.c    | 56 +++++++++++++++++++++++++++++++++
 drivers/net/phy/mdio_device.c | 58 -----------------------------------
 2 files changed, 56 insertions(+), 58 deletions(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index afdf1ad6c0e6..dea67470a7bf 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -1004,11 +1004,67 @@ static const struct attribute_group *mdio_bus_dev_groups[] = {
 	NULL,
 };
 
+/**
+ * mdio_bus_probe - probe an MDIO device
+ * @dev: device to probe
+ *
+ * Description: Take care of setting up the mdio_device structure
+ * and calling the driver to probe the device.
+ *
+ * Return: Zero if successful, negative error code on failure
+ */
+static int mdio_bus_probe(struct device *dev)
+{
+	struct mdio_device *mdiodev = to_mdio_device(dev);
+	struct device_driver *drv = dev->driver;
+	struct mdio_driver *mdiodrv = to_mdio_driver(drv);
+	int err = 0;
+
+	/* Deassert the reset signal */
+	mdio_device_reset(mdiodev, 0);
+
+	if (mdiodrv->probe) {
+		err = mdiodrv->probe(mdiodev);
+		if (err) {
+			/* Assert the reset signal */
+			mdio_device_reset(mdiodev, 1);
+		}
+	}
+
+	return err;
+}
+
+static void mdio_bus_remove(struct device *dev)
+{
+	struct mdio_device *mdiodev = to_mdio_device(dev);
+	struct device_driver *drv = dev->driver;
+	struct mdio_driver *mdiodrv = to_mdio_driver(drv);
+
+	if (mdiodrv->remove)
+		mdiodrv->remove(mdiodev);
+
+	/* Assert the reset signal */
+	mdio_device_reset(mdiodev, 1);
+}
+
+static void mdio_bus_shutdown(struct device *dev)
+{
+	struct mdio_device *mdiodev = to_mdio_device(dev);
+	struct device_driver *drv = dev->driver;
+	struct mdio_driver *mdiodrv = to_mdio_driver(drv);
+
+	if (drv && mdiodrv->shutdown)
+		mdiodrv->shutdown(mdiodev);
+}
+
 const struct bus_type mdio_bus_type = {
 	.name		= "mdio_bus",
 	.dev_groups	= mdio_bus_dev_groups,
 	.match		= mdio_bus_match,
 	.uevent		= mdio_uevent,
+	.probe		= mdio_bus_probe,
+	.remove		= mdio_bus_remove,
+	.shutdown	= mdio_bus_shutdown,
 };
 EXPORT_SYMBOL(mdio_bus_type);
 
diff --git a/drivers/net/phy/mdio_device.c b/drivers/net/phy/mdio_device.c
index 6e90ed42cd98..29172fa8d0df 100644
--- a/drivers/net/phy/mdio_device.c
+++ b/drivers/net/phy/mdio_device.c
@@ -202,61 +202,6 @@ void mdio_device_reset(struct mdio_device *mdiodev, int value)
 }
 EXPORT_SYMBOL(mdio_device_reset);
 
-/**
- * mdio_probe - probe an MDIO device
- * @dev: device to probe
- *
- * Description: Take care of setting up the mdio_device structure
- * and calling the driver to probe the device.
- *
- * Return: Zero if successful, negative error code on failure
- */
-static int mdio_probe(struct device *dev)
-{
-	struct mdio_device *mdiodev = to_mdio_device(dev);
-	struct device_driver *drv = mdiodev->dev.driver;
-	struct mdio_driver *mdiodrv = to_mdio_driver(drv);
-	int err = 0;
-
-	/* Deassert the reset signal */
-	mdio_device_reset(mdiodev, 0);
-
-	if (mdiodrv->probe) {
-		err = mdiodrv->probe(mdiodev);
-		if (err) {
-			/* Assert the reset signal */
-			mdio_device_reset(mdiodev, 1);
-		}
-	}
-
-	return err;
-}
-
-static int mdio_remove(struct device *dev)
-{
-	struct mdio_device *mdiodev = to_mdio_device(dev);
-	struct device_driver *drv = mdiodev->dev.driver;
-	struct mdio_driver *mdiodrv = to_mdio_driver(drv);
-
-	if (mdiodrv->remove)
-		mdiodrv->remove(mdiodev);
-
-	/* Assert the reset signal */
-	mdio_device_reset(mdiodev, 1);
-
-	return 0;
-}
-
-static void mdio_shutdown(struct device *dev)
-{
-	struct mdio_device *mdiodev = to_mdio_device(dev);
-	struct device_driver *drv = mdiodev->dev.driver;
-	struct mdio_driver *mdiodrv = to_mdio_driver(drv);
-
-	if (mdiodrv->shutdown)
-		mdiodrv->shutdown(mdiodev);
-}
-
 /**
  * mdio_driver_register - register an mdio_driver with the MDIO layer
  * @drv: new mdio_driver to register
@@ -271,9 +216,6 @@ int mdio_driver_register(struct mdio_driver *drv)
 	pr_debug("%s: %s\n", __func__, mdiodrv->driver.name);
 
 	mdiodrv->driver.bus = &mdio_bus_type;
-	mdiodrv->driver.probe = mdio_probe;
-	mdiodrv->driver.remove = mdio_remove;
-	mdiodrv->driver.shutdown = mdio_shutdown;
 
 	retval = driver_register(&mdiodrv->driver);
 	if (retval) {

base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
-- 
2.47.3


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ