diff --git a/repos/dde_linux/src/lib/wifi/pci_driver.cc b/repos/dde_linux/src/lib/wifi/pci_driver.cc index a10ef26b8..3019572dd 100644 --- a/repos/dde_linux/src/lib/wifi/pci_driver.cc +++ b/repos/dde_linux/src/lib/wifi/pci_driver.cc @@ -14,6 +14,7 @@ /* Genode inludes */ #include +#include #include #include #include @@ -264,9 +265,7 @@ extern "C" int pci_register_driver(struct pci_driver *drv) { drv->driver.name = drv->name; - pci_device_id const *id = drv->id_table; - if (!id) - return -ENODEV; + if (!drv->id_table) return -ENODEV; using namespace Genode; @@ -279,48 +278,39 @@ extern "C" int pci_register_driver(struct pci_driver *drv) PCI_CLASS_WIFI = 0x028000, }; - unsigned found = 0; + bool found = false; - while (id->device) { - if (id->class_ == (unsigned)PCI_ANY_ID) { - id++; - continue; - } + for (Platform::Device_capability cap = pci()->first_device(PCI_CLASS_WIFI, + PCI_CLASS_MASK); + cap.valid() && !found;) { + Pci_driver *pci_drv = nullptr; + pci_device_cap = cap; - Platform::Device_capability cap = pci()->first_device(PCI_CLASS_WIFI, - PCI_CLASS_MASK); + for (pci_device_id const *id = drv->id_table; id->device && !found; id++) { + + if (id->class_ == (unsigned)PCI_ANY_ID) continue; - while (cap.valid()) { - Pci_driver *pci_drv = 0; try { - pci_device_cap = cap; - - /* probe device */ - pci_drv = new (env()->heap()) Pci_driver(drv, cap, id); - pci()->on_destruction(Platform::Connection::KEEP_OPEN); - found++; - - } catch (Platform::Device::Quota_exceeded) { - Genode::env()->parent()->upgrade(pci()->cap(), "ram_quota=4096"); - continue; + retry( + [&] { + /* probe device */ + pci_drv = new (env()->heap()) Pci_driver(drv, cap, id); + pci()->on_destruction(Platform::Connection::KEEP_OPEN); + found = true; + }, + [&] { + Genode::env()->parent()->upgrade(pci()->cap(), "ram_quota=4096"); + }); } catch (...) { destroy(env()->heap(), pci_drv); - pci_drv = 0; + pci_drv = nullptr; } - - if (found) - break; - - Platform::Device_capability free_up = cap; - cap = pci()->next_device(cap, PCI_CLASS_WIFI, PCI_CLASS_MASK); - if (!pci_drv) - pci()->release_device(free_up); } - id++; - /* XXX */ - if (found) - break; + Platform::Device_capability free_up = cap; + cap = pci()->next_device(cap, PCI_CLASS_WIFI, PCI_CLASS_MASK); + if (!pci_drv) + pci()->release_device(free_up); } return found ? 0 : -ENODEV;