net: dsa: qca8k: put MDIO bus OF node on qca8k_mdio_register() failure
authorVladimir Oltean <vladimir.oltean@nxp.com>
Thu, 4 Jan 2024 14:00:31 +0000 (16:00 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 5 Feb 2024 20:14:25 +0000 (20:14 +0000)
commit9916fdd8a29aa0366f93635502bb718de4ef8192
treeaa273ca0ac4ee7275030fbb6d804eb844f50b9e5
parent45d201c4335bc7d144a5b5090922da9f2120a2e9
net: dsa: qca8k: put MDIO bus OF node on qca8k_mdio_register() failure

[ Upstream commit 68e1010cda7967cfca9c8650ee1f4efcae54ab90 ]

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 3b73a7b8ec38 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/dsa/qca/qca8k-8xxx.c