mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-05 16:14:38 +00:00
Kernel/PCI: Don't hold spinlocks when doing fast device enumeration
Instead, hold the lock while we copy the contents to a stack-based Vector then iterate on it without any locking. Because we rely on heap allocations, we need to propagate errors back in case of OOM condition, therefore, both PCI::enumerate API function and PCI::Access::add_host_controller_and_enumerate_attached_devices use now a ErrorOr<void> return value to propagate errors. OOM Error can only occur when enumerating the m_device_identifiers vector under a spinlock and trying to expand the temporary Vector which will be used locklessly to actually iterate over the PCI::DeviceIdentifiers objects.
This commit is contained in:
@@ -112,13 +112,13 @@ UNMAP_AFTER_INIT RefPtr<NetworkAdapter> NetworkingManagement::determine_network_
|
||||
bool NetworkingManagement::initialize()
|
||||
{
|
||||
if (!kernel_command_line().is_physical_networking_disabled() && !PCI::Access::is_disabled()) {
|
||||
PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) {
|
||||
MUST(PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) {
|
||||
// Note: PCI class 2 is the class of Network devices
|
||||
if (device_identifier.class_code().value() != 0x02)
|
||||
return;
|
||||
if (auto adapter = determine_network_device(device_identifier); !adapter.is_null())
|
||||
m_adapters.with([&](auto& adapters) { adapters.append(adapter.release_nonnull()); });
|
||||
});
|
||||
}));
|
||||
}
|
||||
auto loopback = LoopbackAdapter::try_create();
|
||||
VERIFY(loopback);
|
||||
|
||||
Reference in New Issue
Block a user