Commit acba174d authored by Ilpo Järvinen's avatar Ilpo Järvinen Committed by Bjorn Helgaas
Browse files

PCI: Use while loop and break instead of gotos

pci_assign_unassigned_root_bus_resources() and
pci_assign_unassigned_bridge_resources() contain ad hoc loops using
backwards goto and gotos out of the loop. Replace them with while loops
and break statements.

While reindenting the loop bodies, add braces & remove parenthesis.

Link: https://lore.kernel.org/r/20241216175632.4175-15-ilpo.jarvinen@linux.intel.com


Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Tested-by: default avatarXiaochun Lee <lixc17@lenovo.com>
parent 0aa089cd
Loading
Loading
Loading
Loading
+106 −106
Original line number Diff line number Diff line
@@ -2161,15 +2161,16 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
			 max_depth, pci_try_num);
	}

again:
	while (1) {
		/*
	 * Last try will use add_list, otherwise will try good to have as must
	 * have, so can realloc parent bridge resource
		 * Last try will use add_list, otherwise will try good to
		 * have as must have, so can realloc parent bridge resource
		 */
		if (tried_times + 1 == pci_try_num)
			add_list = &realloc_head;
		/*
	 * Depth first, calculate sizes and alignments of all subordinate buses.
		 * Depth first, calculate sizes and alignments of all
		 * subordinate buses.
		 */
		__pci_bus_size_bridges(bus, add_list);

@@ -2183,33 +2184,36 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)

		/* Any device complain? */
		if (list_empty(&fail_head))
		goto dump;
			break;

		if (tried_times >= pci_try_num) {
		if (enable_local == undefined)
			dev_info(&bus->dev, "Some PCI device resources are unassigned, try booting with pci=realloc\n");
		else if (enable_local == auto_enabled)
			dev_info(&bus->dev, "Automatically enabled pci realloc, if you have problem, try booting with pci=realloc=off\n");

			if (enable_local == undefined) {
				dev_info(&bus->dev,
					 "Some PCI device resources are unassigned, try booting with pci=realloc\n");
			} else if (enable_local == auto_enabled) {
				dev_info(&bus->dev,
					 "Automatically enabled pci realloc, if you have problem, try booting with pci=realloc=off\n");
			}
			free_list(&fail_head);
		goto dump;
			break;
		}

		dev_info(&bus->dev, "No. %d try to assign unassigned res\n",
			 tried_times + 1);

		/* Third times and later will not check if it is leaf */
	if ((tried_times + 1) > 2)
		if (tried_times + 1 > 2)
			rel_type = whole_subtree;

		/*
	 * Try to release leaf bridge's resources that doesn't fit resource of
	 * child device under that bridge.
		 * Try to release leaf bridge's resources that doesn't fit
		 * resource of child device under that bridge.
		 */
	list_for_each_entry(fail_res, &fail_head, list)
		list_for_each_entry(fail_res, &fail_head, list) {
			pci_bus_release_bridge_resources(fail_res->dev->bus,
							 fail_res->flags & PCI_RES_TYPE_MASK,
							 rel_type);
		}

		/* Restore size and flags */
		list_for_each_entry(fail_res, &fail_head, list) {
@@ -2228,11 +2232,8 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
			}
		}
		free_list(&fail_head);
	}

	goto again;

dump:
	/* Dump the resource on buses */
	pci_bus_dump_resources(bus);
}

@@ -2260,13 +2261,13 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
	struct pci_dev_resource *fail_res;
	int retval;

again:
	while (1) {
		__pci_bus_size_bridges(parent, &add_list);

		/*
	 * Distribute remaining resources (if any) equally between hotplug
	 * bridges below.  This makes it possible to extend the hierarchy
	 * later without running out of resources.
		 * Distribute remaining resources (if any) equally between
		 * hotplug bridges below. This makes it possible to extend
		 * the hierarchy later without running out of resources.
		 */
		pci_bridge_distribute_available_resources(bridge, &add_list);

@@ -2275,25 +2276,26 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
		tried_times++;

		if (list_empty(&fail_head))
		goto enable_all;
			break;

		if (tried_times >= 2) {
			/* Still fail, don't need to try more */
			free_list(&fail_head);
		goto enable_all;
			break;
		}

		printk(KERN_DEBUG "PCI: No. %d try to assign unassigned res\n",
				 tried_times + 1);

		/*
	 * Try to release leaf bridge's resources that aren't big enough
	 * to contain child device resources.
		 * Try to release leaf bridge's resources that aren't big
		 * enough to contain child device resources.
		 */
	list_for_each_entry(fail_res, &fail_head, list)
		list_for_each_entry(fail_res, &fail_head, list) {
			pci_bus_release_bridge_resources(fail_res->dev->bus,
							 fail_res->flags & PCI_RES_TYPE_MASK,
							 whole_subtree);
		}

		/* Restore size and flags */
		list_for_each_entry(fail_res, &fail_head, list) {
@@ -2312,10 +2314,8 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
			}
		}
		free_list(&fail_head);
	}

	goto again;

enable_all:
	retval = pci_reenable_device(bridge);
	if (retval)
		pci_err(bridge, "Error reenabling bridge (%d)\n", retval);