Skip to content

Commit

Permalink
net: mdio: thunder: switch to scoped device_for_each_child_node()
Browse files Browse the repository at this point in the history
There has already been an issue with the handling of early exits from
device_for_each_child() in this driver, and it was solved with commit
b1de5c7 ("net: mdio: thunder: Add missing fwnode_handle_put()") by
adding a call to fwnode_handle_put() right after the loop.

That solution is valid indeed, but if a new error path with a 'return'
is added to the loop, this solution will fail. A more secure approach
is using the scoped variant of the macro, which automatically
decrements the refcount of the child node when it goes out of scope,
removing the need for explicit calls to fwnode_handle_put().

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://patch.msgid.link/20240930-net-device_for_each_child_node_scoped-v2-1-35f09333c1d7@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Javier Carrasco authored and Jakub Kicinski committed Oct 4, 2024
1 parent 6443cf1 commit 1d39d02
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions drivers/net/mdio/mdio-thunder.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ static int thunder_mdiobus_pci_probe(struct pci_dev *pdev,
const struct pci_device_id *ent)
{
struct device_node *node;
struct fwnode_handle *fwn;
struct thunder_mdiobus_nexus *nexus;
int err;
int i;
Expand Down Expand Up @@ -54,7 +53,7 @@ static int thunder_mdiobus_pci_probe(struct pci_dev *pdev,
}

i = 0;
device_for_each_child_node(&pdev->dev, fwn) {
device_for_each_child_node_scoped(&pdev->dev, fwn) {
struct resource r;
struct mii_bus *mii_bus;
struct cavium_mdiobus *bus;
Expand Down Expand Up @@ -106,7 +105,6 @@ static int thunder_mdiobus_pci_probe(struct pci_dev *pdev,
if (i >= ARRAY_SIZE(nexus->buses))
break;
}
fwnode_handle_put(fwn);
return 0;

err_release_regions:
Expand Down

0 comments on commit 1d39d02

Please sign in to comment.