Iterate over busses using uclass_foreach_dev_probe() instead of ad-hoc
loop. The uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus) == 0 in
the ad-hoc loop would break on first controller that does not link up
in its .probe() function, which is undesired, as it prevents listing
of PCIe devices on other controllers. Using uclass_get_device_by_seq()
mitigates that problem, and, at the same time, simplifies the code.

Signed-off-by: Marek Vasut <[email protected]>
---
Cc: Neil Armstrong <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
 cmd/pci.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/cmd/pci.c b/cmd/pci.c
index 3c0aed50cae..d2a10aec41a 100644
--- a/cmd/pci.c
+++ b/cmd/pci.c
@@ -550,14 +550,10 @@ static int do_pci(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
                }
                if (busnum == -1) {
                        if (cmd != 'r') {
-                               for (busnum = 0;
-                                    uclass_get_device_by_seq(UCLASS_PCI, 
busnum, &bus) == 0;
-                                    busnum++)
+                               uclass_foreach_dev_probe(UCLASS_PCI, bus)
                                        pciinfo(bus, value, true);
                        } else {
-                               for (busnum = 0;
-                                    uclass_get_device_by_seq(UCLASS_PCI, 
busnum, &bus) == 0;
-                                    busnum++) {
+                               uclass_foreach_dev_probe(UCLASS_PCI, bus) {
                                        /* Regions are controller specific so 
skip non-root buses */
                                        if (device_is_on_pci_bus(bus))
                                                continue;
-- 
2.53.0

Reply via email to