Skip to content

Commit 7e8e4fc

Browse files
javiercarrascocruzbjorn-helgaas
authored andcommitted
PCI: kirin: Convert kirin_pcie_parse_port() to scoped iterator
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/[email protected] Signed-off-by: Javier Carrasco <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> [bhelgaas: move to GPIO series to avoid bisection hole, commit log] Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]>
1 parent 2e81122 commit 7e8e4fc

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

drivers/pci/controller/dwc/pcie-kirin.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,10 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
400400
struct device_node *node)
401401
{
402402
struct device *dev = &pdev->dev;
403-
struct device_node *parent, *child;
404403
int ret, slot, i;
405404

406-
for_each_available_child_of_node(node, parent) {
407-
for_each_available_child_of_node(parent, child) {
405+
for_each_available_child_of_node_scoped(node, parent) {
406+
for_each_available_child_of_node_scoped(parent, child) {
408407
i = pcie->num_slots;
409408

410409
pcie->gpio_id_reset[i] = of_get_named_gpio(child,
@@ -415,34 +414,26 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
415414
pcie->num_slots++;
416415
if (pcie->num_slots > MAX_PCI_SLOTS) {
417416
dev_err(dev, "Too many PCI slots!\n");
418-
ret = -EINVAL;
419-
goto put_node;
417+
return -EINVAL;
420418
}
421419

422420
ret = of_pci_get_devfn(child);
423421
if (ret < 0) {
424422
dev_err(dev, "failed to parse devfn: %d\n", ret);
425-
goto put_node;
423+
return ret;
426424
}
427425

428426
slot = PCI_SLOT(ret);
429427

430428
pcie->reset_names[i] = devm_kasprintf(dev, GFP_KERNEL,
431429
"pcie_perst_%d",
432430
slot);
433-
if (!pcie->reset_names[i]) {
434-
ret = -ENOMEM;
435-
goto put_node;
436-
}
431+
if (!pcie->reset_names[i])
432+
return -ENOMEM;
437433
}
438434
}
439435

440436
return 0;
441-
442-
put_node:
443-
of_node_put(child);
444-
of_node_put(parent);
445-
return ret;
446437
}
447438

448439
static long kirin_pcie_get_resource(struct kirin_pcie *kirin_pcie,

0 commit comments

Comments
 (0)