net: mdio: of: fix potential NULL pointer derefernce

of_find_mii_timestamper() returns NULL if no timestamper is found.
Therefore, guard the unregister_mii_timestamper() calls.

Fixes: 1dca22b184 ("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>
This commit is contained in:
Michael Walle 2020-01-30 18:44:50 +01:00 committed by Jakub Kicinski
parent 9f68e3655a
commit 0e0daf6ac3
1 changed files with 6 additions and 3 deletions

View File

@ -81,13 +81,15 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,
else
phy = get_phy_device(mdio, addr, is_c45);
if (IS_ERR(phy)) {
unregister_mii_timestamper(mii_ts);
if (mii_ts)
unregister_mii_timestamper(mii_ts);
return PTR_ERR(phy);
}
rc = of_irq_get(child, 0);
if (rc == -EPROBE_DEFER) {
unregister_mii_timestamper(mii_ts);
if (mii_ts)
unregister_mii_timestamper(mii_ts);
phy_device_free(phy);
return rc;
}
@ -116,7 +118,8 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,
* register it */
rc = phy_device_register(phy);
if (rc) {
unregister_mii_timestamper(mii_ts);
if (mii_ts)
unregister_mii_timestamper(mii_ts);
phy_device_free(phy);
of_node_put(child);
return rc;