net: phy: factor out legacy PHY fixup support and make it always built-in
Subsystems (3)
Heiner Kallweit
maintainerPATCH 1/1 net: phy: factor out legacy PHY fixup support and make it always built-in
PHY fixup registration is used from platform code in init phase only. Let's move the PHY fixup code from the modular part of phylib to the always built-in part of phylib. This allows to annotate the fixup registration as __init. No caller uses the return code of PHY fixup registration, therefore change related functions to return void.
phy_needs_fixup() and phy_scan_fixups() wouldn't have to be moved to the built-in part of phylib. But doing so allows to fully factor out legacy fixup support into its own source code file, and make struct phy_fixup and phy_fixup_list strictly private to phy_fixup.c.
phy_scan_fixups() is used after init phase only, then phy_fixup_list is read-only. So we don't need the mutex when accessing the list. Also when registering PHY fixups the mutex isn't needed, because fixup registration is done sequentially from platform init code. Actually there is only one platform with more than one fixup.
In addition this change lays the foundation for enabling modular phylib on platforms where the fixup just sets a flag.
---
This is a resubmit from Jan 2026. The change depends on removal of the dnet driver, and at that time the dnet driver had just been removed, with a certain risk that this removal has to be reverted.
--- drivers/net/phy/Makefile | 2 +- drivers/net/phy/phy_device.c | 90 ---------------------------- drivers/net/phy/phy_fixup.c | 99 +++++++++++++++++++++++++++++++ drivers/net/phy/phylib-internal.h | 1 + include/linux/phy.h | 8 +-- 5 files changed, 105 insertions(+), 95 deletions(-) create mode 100644 drivers/net/phy/phy_fixup.c
drivers/net/phy/Makefile +1 -1
@@ -8,7 +8,7 @@ libphy-y := phy.o phy-c45.o phy-core.o phy_device.o \ ifdef CONFIG_PHYLIB # built-in whenever PHYLIB is built-in or module -obj-y += stubs.o +obj-y += stubs.o phy_fixup.o endif libphy-$(CONFIG_SWPHY) += swphy.o
drivers/net/phy/phy_device.c +0 -90
108 lines not on this page · raw message
drivers/net/phy/phy_fixup.c new file +99 -0
99 lines not on this page · raw message
drivers/net/phy/phylib-internal.h +1 -0
@@ -23,6 +23,7 @@ void of_set_phy_eee_broken(struct phy_device *phydev);void of_set_phy_timing_role (struct phy_device *phydev);int phy_speed_down_core (struct phy_device *phydev);void phy_check_downshift (struct phy_device *phydev); +int phy_scan_fixups (struct phy_device *phydev);int mdiobus_register_device (struct mdio_device *mdiodev);int mdiobus_unregister_device (struct mdio_device *mdiodev);
include/linux/phy.h +4 -4
@@ -2422,10 +2422,10 @@ int phy_get_mac_termination(struct phy_device *phydev, struct device *dev,void phy_resolve_pause (unsigned long *local_adv,unsigned long *partner_adv,bool *tx_pause,bool *rx_pause); -int phy_register_fixup_for_id (const char *bus_id, -int (*run)(struct phy_device *)); -int phy_register_fixup_for_uid (u32 phy_uid,u32 phy_uid_mask, -int (*run)(struct phy_device *)); +void __init phy_register_fixup_for_id (const char *bus_id, +int (*run)(struct phy_device *)); +void __init phy_register_fixup_for_uid (u32 phy_uid,u32 phy_uid_mask, +int (*run)(struct phy_device *));int phy_eee_tx_clock_stop_capable (struct phy_device *phydev);int phy_eee_rx_clock_stop (struct phy_device *phydev,bool clk_stop_enable);
Signature · 1 line
2.55.0
Quoted 17 lines · Heiner Kallweit
PHY fixup registration is used from platform code in init phase only. Let's move the PHY fixup code from the modular part of phylib to the always built-in part of phylib. This allows to annotate the fixup registration as
__init. No caller uses the return code of PHY fixup registration, therefore change related functions to return void.
phy_needs_fixup()andphy_scan_fixups()wouldn't have to be moved to the built-in part of phylib. But doing so allows to fully factor out legacy fixup support into its own source code file, and make structphy_fixupandphy_fixup_liststrictly private tophy_fixup.c.
phy_scan_fixups()is used after init phase only, thenphy_fixup_listis read-only. So we don't need the mutex when accessing the list. Also when registering PHY fixups the mutex isn't needed, because fixup registration is done sequentially from platform init code. Actually there is only one platform with more than one fixup.
Quoted 4 lines
In addition this change lays the foundation for enabling modular phylib on platforms where the fixup just sets a flag.
Signed-off-by Heiner Kallweit <[email protected]>
Andrew
Jakub Kicinski
maintainerThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: phy: factor out legacy PHY fixup support and make it always built-in
This moves the legacy PHY fixup code out of the modular part of phylib into a new always-built-in file, drivers/net/phy/phy_fixup.c, marks the registration helpers __init and changes them to return void. struct phy_fixup and phy_fixup_list become private to the new file and the fixup mutex is dropped.
Quoted 4 lines
drivers/net/phy/phy_device.c +0
-0
[ ... ]
Quoted 12 lines
drivers/net/phy/phy_device.c +0
-8@@ -427,85 +416,6 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(mdio_bus_phy_pm_ops, mdio_bus_phy_suspend, mdio_bus_phy_resume); -/** -* phy_register_fixup - creates a new phy_fixup and adds it to the list -* @bus_id: A string which matches phydev->mdio.dev.bus_id (or NULL) -* @phy_uid: Used to match against phydev->phy_id (the UID of the PHY) -* @phy_uid_mask: Applied to phydev->phy_id and fixup->phy_uid before -* comparison (or 0 to disable id-based matching) -* @run: The actual code to be run when a matching PHY is found -*/
[ ... ]
Quoted 6 lines
drivers/net/phy/phy_fixup.c new file +0
-0@@ -0,0 +1,99 @@
[ ... ]
Quoted 9 lines
+/**
+ *phy_register_fixup- creates a newphy_fixupand adds it to the list
+ * @bus_id: A string which matchesphydev->mdio.dev.bus_id(orPHY_ANY_ID)
+ * @phy_uid: Used to match againstphydev->phy_id(the UID of the PHY)
+ * It can also bePHY_ANY_UID
+ * @phy_uid_mask: Applied tophydev->phy_idandfixup->phy_uidbefore
+ * comparison
+ * @run: The actual code to be run when a matching PHY is found
+ */
[Severity: Low]
Was the wording change in this kernel-doc block intentional? The version removed from phy_device.c said "(or NULL)" for @bus_id and "(or 0 to disable id-based matching)" for @phy_uid_mask, which matches what the code does. The new text mentions PHY_ANY_ID and PHY_ANY_UID instead.
Grepping the tree at this commit, PHY_ANY_ID and PHY_ANY_UID have no definition anywhere; the only hits are these two new comment lines in phy_fixup.c plus one sentence in Documentation/networking/phy.rst.
The matching code moved by this patch, phy_needs_fixup() in phy_fixup.c, has no wildcard handling:
if (!strcmp(fixup->bus_id, phydev_name(phydev))) return true; if (fixup->phy_uid_mask && phy_id_compare(phydev->phy_id, fixup->phy_uid, fixup->phy_uid_mask)) return true;
and phy_register_fixup() only special-cases a NULL bus_id:
if (bus_id) strscpy(fixup->bus_id, bus_id); fixup->phy_uid = phy_uid; fixup->phy_uid_mask = phy_uid_mask;
So platform code written against this comment would either fail to build on the undefined identifier, or register a fixup that never matches. Would it be better to keep the "(or NULL)" and "(or 0 to disable id-based matching)" wording?
Quoted 3 lines
drivers/net/phy/phy_fixup.c new file +3
-0+static void __init phy_register_fixup (const char *bus_id,u32 phy_uid, +u32 phy_uid_mask, +int (*run)(struct phy_device *))
[ ... ]
Quoted 13 lines
drivers/net/phy/phy_fixup.c new file +13
-0+/* Registers a fixup to be run on any PHY with the UID in phy_uid */ +void __init phy_register_fixup_for_uid (u32 phy_uid,u32 phy_uid_mask, +int (*run)(struct phy_device *)) +{ +phy_register_fixup (NULL , phy_uid, phy_uid_mask, run); +} + +/* Registers a fixup to be run on the PHY with id string bus_id */ +void __init phy_register_fixup_for_id (const char *bus_id, +int (*run)(struct phy_device *)) +{ +phy_register_fixup (bus_id,0 ,0 , run); +}
[ ... ]
Quoted 6 lines
include/linux/phy.h +0
-0@@ -2440,10 +2440,10 @@ int phy_get_mac_termination(struct phy_device *phydev, struct device *dev, void phy_resolve_pause(unsigned long *local_adv, unsigned long *partner_adv,
include/linux/phy.h int phy_get_mac_termination(struct phy_device *phydev, struct device *dev, · line 2446
Quoted 10 lines
include/linux/phy.h +4
-4bool *tx_pause, bool *rx_pause); -int phy_register_fixup_for_id (const char *bus_id, -int (*run)(struct phy_device *)); -int phy_register_fixup_for_uid (u32 phy_uid,u32 phy_uid_mask, -int (*run)(struct phy_device *)); +void __init phy_register_fixup_for_id (const char *bus_id, +int (*run)(struct phy_device *)); +void __init phy_register_fixup_for_uid (u32 phy_uid,u32 phy_uid_mask, +int (*run)(struct phy_device *));
[Severity: Low]
Should Documentation/networking/phy.rst be updated in the same patch? The "Board Fixups" section still documents the old prototypes:
int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
int (*run)(struct phy_device *)); int phy_register_fixup_for_id(const char *phy_id, int (*run)(struct phy_device *));
Two things there are now stale. The return type is void, so code that assigns or tests the return value as the document suggests no longer compiles.
The document also just says platform code registers fixups, with no mention that registration is now init-only: the helpers are __init and are no longer exported, and phy_register_fixup() adds to phy_fixup_list, which is declared
static struct list_head phy_fixup_list __ro_after_init = LIST_HEAD_INIT(phy_fixup_list);
so a caller outside init context gets a section mismatch from modpost and, if it ever runs after init, writes to read-only memory. Modules can no longer call these at all.
Same section of phy.rst also describes PHY_ANY_ID and PHY_ANY_UID as wildcards, which ties in with the kernel-doc comment above.
Signature · 1 line
pw-bot: cr