Skip to content

Commit

Permalink
net: mii_timestamper: fix static allocation by PHY driver
Browse files Browse the repository at this point in the history
If phydev->mii_ts is set by the PHY driver, it will always be
overwritten in of_mdiobus_register_phy(). Fix it. Also make sure, that
the unregister() doesn't do anything if the mii_timestamper was provided by
the PHY driver.

Fixes: 1dca22b ("net: mdio: of: Register discovered MII time stampers.")
Signed-off-by: Michael Walle <[email protected]>
Acked-by: Richard Cochran <[email protected]>
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
mwalle authored and kuba-moo committed Jan 31, 2020
1 parent 0e0daf6 commit 2e1bf3a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions drivers/net/phy/mii_timestamper.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ void unregister_mii_timestamper(struct mii_timestamper *mii_ts)
struct mii_timestamping_desc *desc;
struct list_head *this;

/* mii_timestamper statically registered by the PHY driver won't use the
* register_mii_timestamper() and thus don't have ->device set. Don't
* try to unregister these.
*/
if (!mii_ts->device)
return;

mutex_lock(&tstamping_devices_lock);
list_for_each(this, &mii_timestamping_devices) {
desc = list_entry(this, struct mii_timestamping_desc, list);
Expand Down
8 changes: 7 additions & 1 deletion drivers/of/of_mdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,
of_node_put(child);
return rc;
}
phy->mii_ts = mii_ts;

/* phy->mii_ts may already be defined by the PHY driver. A
* mii_timestamper probed via the device tree will still have
* precedence.
*/
if (mii_ts)
phy->mii_ts = mii_ts;

dev_dbg(&mdio->dev, "registered phy %pOFn at address %i\n",
child, addr);
Expand Down

0 comments on commit 2e1bf3a

Please sign in to comment.