PCI: kirin: Convert kirin_pcie_parse_port() to scoped iterator
authorJavier Carrasco <javier.carrasco.cruz@gmail.com>
Sun, 9 Jun 2024 10:56:14 +0000 (12:56 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 9 Jul 2024 22:40:34 +0000 (17:40 -0500)
Convert loops in kirin_pcie_parse_port() to use the _scoped() version of
for_each_available_child_of_node() so the refcounts of children are
implicitly decremented when the loop is exited.

No functional change intended here, but it will make future error exits
from these loops easier.

Link: https://lore.kernel.org/linux-pci/20240609-pcie-kirin-memleak-v1-1-62b45b879576@gmail.com
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Signed-off-by: Krzysztof WilczyƄski <kwilczynski@kernel.org>
[bhelgaas: move to GPIO series to avoid bisection hole, commit log]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/pci/controller/dwc/pcie-kirin.c

index d5523f3021024cc96c6b239a2ca4a7bffde8b2e3..11af2cb88c98a67352151b748b74ddc2feb92f53 100644 (file)
@@ -400,11 +400,10 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
                                 struct device_node *node)
 {
        struct device *dev = &pdev->dev;
-       struct device_node *parent, *child;
        int ret, slot, i;
 
-       for_each_available_child_of_node(node, parent) {
-               for_each_available_child_of_node(parent, child) {
+       for_each_available_child_of_node_scoped(node, parent) {
+               for_each_available_child_of_node_scoped(parent, child) {
                        i = pcie->num_slots;
 
                        pcie->gpio_id_reset[i] = of_get_named_gpio(child,
@@ -415,14 +414,13 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
                        pcie->num_slots++;
                        if (pcie->num_slots > MAX_PCI_SLOTS) {
                                dev_err(dev, "Too many PCI slots!\n");
-                               ret = -EINVAL;
-                               goto put_node;
+                               return -EINVAL;
                        }
 
                        ret = of_pci_get_devfn(child);
                        if (ret < 0) {
                                dev_err(dev, "failed to parse devfn: %d\n", ret);
-                               goto put_node;
+                               return ret;
                        }
 
                        slot = PCI_SLOT(ret);
@@ -430,19 +428,12 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
                        pcie->reset_names[i] = devm_kasprintf(dev, GFP_KERNEL,
                                                              "pcie_perst_%d",
                                                              slot);
-                       if (!pcie->reset_names[i]) {
-                               ret = -ENOMEM;
-                               goto put_node;
-                       }
+                       if (!pcie->reset_names[i])
+                               return -ENOMEM;
                }
        }
 
        return 0;
-
-put_node:
-       of_node_put(child);
-       of_node_put(parent);
-       return ret;
 }
 
 static long kirin_pcie_get_resource(struct kirin_pcie *kirin_pcie,