Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: mii_timestamper: fix static allocation by PHY driver

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: 1dca22b18421 ("net: mdio: of: Register discovered MII time stampers.")
Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Michael Walle and committed by
Jakub Kicinski
2e1bf3a7 0e0daf6a

+14 -1
+7
drivers/net/phy/mii_timestamper.c
··· 111 111 struct mii_timestamping_desc *desc; 112 112 struct list_head *this; 113 113 114 + /* mii_timestamper statically registered by the PHY driver won't use the 115 + * register_mii_timestamper() and thus don't have ->device set. Don't 116 + * try to unregister these. 117 + */ 118 + if (!mii_ts->device) 119 + return; 120 + 114 121 mutex_lock(&tstamping_devices_lock); 115 122 list_for_each(this, &mii_timestamping_devices) { 116 123 desc = list_entry(this, struct mii_timestamping_desc, list);
+7 -1
drivers/of/of_mdio.c
··· 124 124 of_node_put(child); 125 125 return rc; 126 126 } 127 - phy->mii_ts = mii_ts; 127 + 128 + /* phy->mii_ts may already be defined by the PHY driver. A 129 + * mii_timestamper probed via the device tree will still have 130 + * precedence. 131 + */ 132 + if (mii_ts) 133 + phy->mii_ts = mii_ts; 128 134 129 135 dev_dbg(&mdio->dev, "registered phy %pOFn at address %i\n", 130 136 child, addr);