Skip to content

Commit

Permalink
net: mdio: fix owner field for mdio buses registered using device-tree
Browse files Browse the repository at this point in the history
Bus ownership is wrong when using of_mdiobus_register() to register an mdio
bus. That function is not inline, so when it calls mdiobus_register() the wrong
THIS_MODULE value is captured.

Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
Fixes: 90eff90 ("net: phy: Allow splitting MDIO bus/device support from PHYs")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
  • Loading branch information
mbizonfreebox authored and intel-lab-lkp committed Mar 16, 2023
1 parent 0450479 commit 1449da9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
9 changes: 5 additions & 4 deletions drivers/net/mdio/of_mdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,15 @@ EXPORT_SYMBOL(of_mdiobus_child_is_phy);
* This function registers the mii_bus structure and registers a phy_device
* for each child node of @np.
*/
int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np,
struct module *owner)
{
struct device_node *child;
bool scanphys = false;
int addr, rc;

if (!np)
return mdiobus_register(mdio);
return __mdiobus_register(mdio, owner);

/* Do not continue if the node is disabled */
if (!of_device_is_available(np))
Expand All @@ -172,7 +173,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
of_property_read_u32(np, "reset-post-delay-us", &mdio->reset_post_delay_us);

/* Register the MDIO bus */
rc = mdiobus_register(mdio);
rc = __mdiobus_register(mdio, owner);
if (rc)
return rc;

Expand Down Expand Up @@ -236,7 +237,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
mdiobus_unregister(mdio);
return rc;
}
EXPORT_SYMBOL(of_mdiobus_register);
EXPORT_SYMBOL(__of_mdiobus_register);

/**
* of_mdio_find_device - Given a device tree node, find the mdio_device
Expand Down
8 changes: 4 additions & 4 deletions drivers/net/phy/mdio_devres.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ EXPORT_SYMBOL(__devm_mdiobus_register);
* @mdio: MII bus structure to register
* @np: Device node to parse
*/
int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio,
struct device_node *np)
int __devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio,
struct device_node *np, struct module *owner)
{
struct mdiobus_devres *dr;
int ret;
Expand All @@ -117,7 +117,7 @@ int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio,
if (!dr)
return -ENOMEM;

ret = of_mdiobus_register(mdio, np);
ret = __of_mdiobus_register(mdio, np, owner);
if (ret) {
devres_free(dr);
return ret;
Expand All @@ -127,7 +127,7 @@ int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio,
devres_add(dev, dr);
return 0;
}
EXPORT_SYMBOL(devm_of_mdiobus_register);
EXPORT_SYMBOL(__devm_of_mdiobus_register);
#endif /* CONFIG_OF_MDIO */

MODULE_LICENSE("GPL");
22 changes: 19 additions & 3 deletions include/linux/of_mdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,25 @@

#if IS_ENABLED(CONFIG_OF_MDIO)
bool of_mdiobus_child_is_phy(struct device_node *child);
int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np);
int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio,
struct device_node *np);
int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np,
struct module *owner);

static inline int of_mdiobus_register(struct mii_bus *mdio,
struct device_node *np)
{
return __of_mdiobus_register(mdio, np, THIS_MODULE);
}

int __devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio,
struct device_node *np, struct module *owner);

static inline int devm_of_mdiobus_register(struct device *dev,
struct mii_bus *mdio,
struct device_node *np)
{
return __devm_of_mdiobus_register(dev, mdio, np, THIS_MODULE);
}

struct mdio_device *of_mdio_find_device(struct device_node *np);
struct phy_device *of_phy_find_device(struct device_node *phy_np);
struct phy_device *
Expand Down

0 comments on commit 1449da9

Please sign in to comment.