Skip to contentSkip to conversation

net: phy: move mdiobus_setup_mdiodev_from_board_info to mdio_bus_provider.c

PATCH In review Heiner Kallweit 2 participants 4 messages May 15, 2025 – May 25, 2025

Subsystems (3)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

PATCH 1/1 net: phy: move mdiobus_setup_mdiodev_from_board_info to mdio_bus_provider.c

Move mdiobus_setup_mdiodev_from_board_info() to mdio_bus_provider.c. Benefits are:
- The function doesn't have to be exported any longer and can be made static.
- We can call mdiobus_create_device() directly instead of passing it as a callback.

Only drawback is that now list and mutex have to be exported.

---
 drivers/net/phy/mdio-boardinfo.c    | 41 +++--------------------------
 drivers/net/phy/mdio-boardinfo.h    |  9 +++----
 drivers/net/phy/mdio_bus_provider.c | 26 +++++++++++++++++-
 3 files changed, 33 insertions(+), 43 deletions(-)
drivers/net/phy/mdio-boardinfo.c +4 -37
index 2de679a68..a52eaefe2 100644
@@ -11,43 +11,10 @@
 
 #include "mdio-boardinfo.h"
 
-static LIST_HEAD(mdio_board_list);
-static DEFINE_MUTEX(mdio_board_lock);
-
-/**
- * mdiobus_setup_mdiodev_from_board_info - create and setup MDIO devices
- * from pre-collected board specific MDIO information
- * @bus: Bus the board_info belongs to
- * @cb: Callback to create device on bus
- * Context: can sleep
- */
-void mdiobus_setup_mdiodev_from_board_info(struct mii_bus *bus,
-					   int (*cb)
-					   (struct mii_bus *bus,
-					    struct mdio_board_info *bi))
-{
-	struct mdio_board_entry *be;
-	struct mdio_board_entry *tmp;
-	struct mdio_board_info *bi;
-	int ret;
-
-	mutex_lock(&mdio_board_lock);
-	list_for_each_entry_safe(be, tmp, &mdio_board_list, list) {
-		bi = &be->board_info;
-
-		if (strcmp(bus->id, bi->bus_id))
-			continue;
-
-		mutex_unlock(&mdio_board_lock);
-		ret = cb(bus, bi);
-		mutex_lock(&mdio_board_lock);
-		if (ret)
-			continue;
-
-	}
-	mutex_unlock(&mdio_board_lock);
-}
-EXPORT_SYMBOL(mdiobus_setup_mdiodev_from_board_info);
+LIST_HEAD(mdio_board_list);
+EXPORT_SYMBOL_GPL(mdio_board_list);
+DEFINE_MUTEX(mdio_board_lock);
+EXPORT_SYMBOL_GPL(mdio_board_lock);
 
 /**
  * mdiobus_register_board_info - register MDIO devices for a given board
drivers/net/phy/mdio-boardinfo.h +4 -5
index 773bb5139..7488e3de2 100644
@@ -7,17 +7,16 @@
 #ifndef __MDIO_BOARD_INFO_H
 #define __MDIO_BOARD_INFO_H
 
-#include <linux/phy.h>
+#include <linux/list.h>
 #include <linux/mutex.h>
+#include <linux/phy.h>
 
 struct mdio_board_entry {
 	struct list_head	list;
 	struct mdio_board_info	board_info;
 };
 
-void mdiobus_setup_mdiodev_from_board_info(struct mii_bus *bus,
-					   int (*cb)
-					   (struct mii_bus *bus,
-					    struct mdio_board_info *bi));
+extern struct list_head mdio_board_list;
+extern struct mutex mdio_board_lock;
 
 #endif /* __MDIO_BOARD_INFO_H */
drivers/net/phy/mdio_bus_provider.c +25 -1
index 48dc4bf85..dd3219969 100644
@@ -161,6 +161,30 @@ static int mdiobus_create_device(struct mii_bus *bus,
 	return ret;
 }
 
+/**
+ * mdiobus_setup_mdiodev_from_board_info - create and setup MDIO devices
+ * from pre-collected board specific MDIO information
+ * @bus: Bus the board_info belongs to
+ * Context: can sleep
+ */
+static void mdiobus_setup_mdiodev_from_board_info(struct mii_bus *bus)
+{
+	struct mdio_board_entry *be, *tmp;
+
+	mutex_lock(&mdio_board_lock);
+	list_for_each_entry_safe(be, tmp, &mdio_board_list, list) {
+		struct mdio_board_info *bi = &be->board_info;
+
+		if (strcmp(bus->id, bi->bus_id))
+			continue;
+
+		mutex_unlock(&mdio_board_lock);
+		mdiobus_create_device(bus, bi);
+		mutex_lock(&mdio_board_lock);
+	}
+	mutex_unlock(&mdio_board_lock);
+}
+
 static struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr, bool c45)
 {
 	struct phy_device *phydev = ERR_PTR(-ENODEV);
@@ -404,7 +428,7 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
 			goto error;
 	}
 
-	mdiobus_setup_mdiodev_from_board_info(bus, mdiobus_create_device);
+	mdiobus_setup_mdiodev_from_board_info(bus);
 
 	bus->state = MDIOBUS_REGISTERED;
 	dev_dbg(&bus->dev, "probed\n");
Signature · 1 line
2.49.0
maintainer
#1 lore raw
Quoted 8 lines · Heiner Kallweit

Move mdiobus_setup_mdiodev_from_board_info() to mdio_bus_provider.c. Benefits are:
- The function doesn't have to be exported any longer and can be made static.
- We can call mdiobus_create_device() directly instead of passing it as a callback.

Only drawback is that now list and mutex have to be exported.

... so the total exports count actually increases, and I personally think that exporting a function is preferable to exporting a variable.

@Andrew, Russell: WDYT?

Thanks,

Paolo

author maintainer
#2 lore raw
Quoted 9 lines · Paolo Abeni
Quoted 7 lines · Heiner Kallweit

Move mdiobus_setup_mdiodev_from_board_info() to mdio_bus_provider.c. Benefits are:
- The function doesn't have to be exported any longer and can be made static.
- We can call mdiobus_create_device() directly instead of passing it as a callback.

Quoted 5 lines
Quoted 1 line

Only drawback is that now list and mutex have to be exported.

... so the total exports count actually increases, and I personally think that exporting a function is preferable to exporting a variable.

Current call chain is:

__mdio_bus_register() // in mdio_bus_provider.c (module or built-in)
mdiobus_setup_mdiodev_from_board_info() // in mdio-boardinfo.c (built-in)
mdiobus_create_device() // in mdio_bus_provider.c, currently
passed to mdiobus_setup_mdiodev_from_board_info as function pointer

Having this call chain in one source file and not having to pass mdiobus_create_device
as a function pointer outweighs the drawback of having to export list/mutex IMO. But as always YMMV

Quoted 2 lines

@Andrew, Russell: WDYT?

+1

Quoted 4 lines

Thanks,

Paolo

Thanks, Heiner

author maintainer
#3 lore raw
In reply to Paolo Abeni
Quoted 10 lines · Paolo Abeni
Quoted 8 lines · Heiner Kallweit

Move mdiobus_setup_mdiodev_from_board_info() to mdio_bus_provider.c. Benefits are:
- The function doesn't have to be exported any longer and can be made static.
- We can call mdiobus_create_device() directly instead of passing it as a callback.

Only drawback is that now list and mutex have to be exported.

Quoted 9 lines

... so the total exports count actually increases, and I personally think that exporting a function is preferable to exporting a variable.

@Andrew, Russell: WDYT?

Thanks,

Paolo

--
pw-bot: cr