Skip to content

Commit

Permalink
Merge branch 'net-switch-to-scoped-device_for_each_child_node'
Browse files Browse the repository at this point in the history
Javier Carrasco says:

====================
net: switch to scoped device_for_each_child_node()

This series switches from the device_for_each_child_node() macro to its
scoped variant. This makes the code more robust if new early exits are
added to the loops, because there is no need for explicit calls to
fwnode_handle_put(), which also simplifies existing code.

The non-scoped macros to walk over nodes turn error-prone as soon as
the loop contains early exits (break, goto, return), and patches to
fix them show up regularly, sometimes due to new error paths in an
existing loop [1].

Note that the child node is now declared in the macro, and therefore the
explicit declaration is no longer required.

The general functionality should not be affected by this modification.
If functional changes are found, please report them back as errors.

Link: https://lore.kernel.org/20240901160829.709296395@linuxfoundation.org

v1: https://lore.kernel.org/r/20240930-net-device_for_each_child_node_scoped-v1-0-bbdd7f9fd649@gmail.com
====================

Link: https://patch.msgid.link/20240930-net-device_for_each_child_node_scoped-v2-0-35f09333c1d7@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Oct 4, 2024
2 parents 6443cf1 + e97dccd commit 7d68b6f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
10 changes: 3 additions & 7 deletions drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,28 +1090,24 @@ int hns_mac_init(struct dsaf_device *dsaf_dev)
u32 port_id;
int max_port_num = hns_mac_get_max_port_num(dsaf_dev);
struct hns_mac_cb *mac_cb;
struct fwnode_handle *child;

device_for_each_child_node(dsaf_dev->dev, child) {
device_for_each_child_node_scoped(dsaf_dev->dev, child) {
ret = fwnode_property_read_u32(child, "reg", &port_id);
if (ret) {
fwnode_handle_put(child);
dev_err(dsaf_dev->dev,
"get reg fail, ret=%d!\n", ret);
return ret;
}
if (port_id >= max_port_num) {
fwnode_handle_put(child);
dev_err(dsaf_dev->dev,
"reg(%u) out of range!\n", port_id);
return -EINVAL;
}
mac_cb = devm_kzalloc(dsaf_dev->dev, sizeof(*mac_cb),
GFP_KERNEL);
if (!mac_cb) {
fwnode_handle_put(child);
if (!mac_cb)
return -ENOMEM;
}

mac_cb->fw_port = child;
mac_cb->mac_id = (u8)port_id;
dsaf_dev->mac_cb[port_id] = mac_cb;
Expand Down
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 7d68b6f

Please sign in to comment.