]> git.itanic.dy.fi Git - linux-stable/commit
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)
committerDavid S. Miller <davem@davemloft.net>
Fri, 5 Jan 2024 11:56:35 +0000 (11:56 +0000)
commit68e1010cda7967cfca9c8650ee1f4efcae54ab90
treecedc1128591a758f1b13d0005ea63f5be85ab88d
parent7a898539391dccce00c3cb24d96a6ba80cef7f6d
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 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>
drivers/net/dsa/qca/qca8k-8xxx.c