Skip to content

Commit 68e1010

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: qca8k: put MDIO bus OF node on qca8k_mdio_register() failure
of_get_child_by_name() gives us an OF node with an elevated refcount, which should be dropped when we're done with it. This is so that, if (of_node_check_flag(node, OF_DYNAMIC)) is true, the node's memory can eventually be freed. There are 2 distinct paths to be considered in qca8k_mdio_register(): - devm_of_mdiobus_register() succeeds: since commit 3b73a7b ("net: mdio_bus: add refcounting for fwnodes to mdiobus"), the MDIO core treats this well. - devm_of_mdiobus_register() or anything up to that point fails: it is the duty of the qca8k driver to release the OF node. This change addresses the second case by making sure that the OF node reference is not leaked. The "mdio" node may be NULL, but of_node_put(NULL) is safe. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Alvin Šipraga <alsi@bang-olufsen.dk> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7a89853 commit 68e1010

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

drivers/net/dsa/qca/qca8k-8xxx.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -949,10 +949,15 @@ qca8k_mdio_register(struct qca8k_priv *priv)
949949
struct dsa_switch *ds = priv->ds;
950950
struct device_node *mdio;
951951
struct mii_bus *bus;
952+
int err;
953+
954+
mdio = of_get_child_by_name(priv->dev->of_node, "mdio");
952955

953956
bus = devm_mdiobus_alloc(ds->dev);
954-
if (!bus)
955-
return -ENOMEM;
957+
if (!bus) {
958+
err = -ENOMEM;
959+
goto out_put_node;
960+
}
956961

957962
bus->priv = (void *)priv;
958963
snprintf(bus->id, MII_BUS_ID_SIZE, "qca8k-%d.%d",
@@ -962,12 +967,12 @@ qca8k_mdio_register(struct qca8k_priv *priv)
962967
ds->user_mii_bus = bus;
963968

964969
/* Check if the devicetree declare the port:phy mapping */
965-
mdio = of_get_child_by_name(priv->dev->of_node, "mdio");
966970
if (of_device_is_available(mdio)) {
967971
bus->name = "qca8k user mii";
968972
bus->read = qca8k_internal_mdio_read;
969973
bus->write = qca8k_internal_mdio_write;
970-
return devm_of_mdiobus_register(priv->dev, bus, mdio);
974+
err = devm_of_mdiobus_register(priv->dev, bus, mdio);
975+
goto out_put_node;
971976
}
972977

973978
/* If a mapping can't be found the legacy mapping is used,
@@ -976,7 +981,13 @@ qca8k_mdio_register(struct qca8k_priv *priv)
976981
bus->name = "qca8k-legacy user mii";
977982
bus->read = qca8k_legacy_mdio_read;
978983
bus->write = qca8k_legacy_mdio_write;
979-
return devm_mdiobus_register(priv->dev, bus);
984+
985+
err = devm_mdiobus_register(priv->dev, bus);
986+
987+
out_put_node:
988+
of_node_put(mdio);
989+
990+
return err;
980991
}
981992

982993
static int

0 commit comments

Comments
 (0)