PCI: mt7621: Use helper function for_each_available_child_of_node_scoped()
authorZhang Zekun <zhangzekun11@huawei.com>
Sat, 31 Aug 2024 04:04:11 +0000 (12:04 +0800)
committerKrzysztof Wilczyński <kwilczynski@kernel.org>
Thu, 6 Mar 2025 09:31:45 +0000 (09:31 +0000)
The for_each_available_child_of_node_scoped() helper provides
a scope-based clean-up functionality to put the device_node
automatically, and as such, there is no need to call of_node_put()
directly.

Thus, use this helper to simplify the code.

Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
Reviewed-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Link: https://lore.kernel.org/r/20240831040413.126417-5-zhangzekun11@huawei.com
[kwilczynski: commit log]
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
drivers/pci/controller/pcie-mt7621.c

index 776caa0b10115b7a6ee3dc7a8a9c9a19541d80c7..01ead2f92e872f8768512c4a5bf853b0d4c653e3 100644 (file)
@@ -258,30 +258,25 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie)
 {
        struct device *dev = pcie->dev;
        struct platform_device *pdev = to_platform_device(dev);
-       struct device_node *node = dev->of_node, *child;
+       struct device_node *node = dev->of_node;
        int err;
 
        pcie->base = devm_platform_ioremap_resource(pdev, 0);
        if (IS_ERR(pcie->base))
                return PTR_ERR(pcie->base);
 
-       for_each_available_child_of_node(node, child) {
+       for_each_available_child_of_node_scoped(node, child) {
                int slot;
 
                err = of_pci_get_devfn(child);
-               if (err < 0) {
-                       of_node_put(child);
-                       dev_err(dev, "failed to parse devfn: %d\n", err);
-                       return err;
-               }
+               if (err < 0)
+                       return dev_err_probe(dev, err, "failed to parse devfn\n");
 
                slot = PCI_SLOT(err);
 
                err = mt7621_pcie_parse_port(pcie, child, slot);
-               if (err) {
-                       of_node_put(child);
+               if (err)
                        return err;
-               }
        }
 
        return 0;