From 3fb289e27d3e0ca171438f178ea6750e25ce6f32 Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 4 Feb 2022 19:48:13 +0200 Subject: 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 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. --- Kernel/Devices/Audio/Management.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Kernel/Devices/Audio') diff --git a/Kernel/Devices/Audio/Management.cpp b/Kernel/Devices/Audio/Management.cpp index e444d3351f..abf57a4991 100644 --- a/Kernel/Devices/Audio/Management.cpp +++ b/Kernel/Devices/Audio/Management.cpp @@ -39,7 +39,7 @@ UNMAP_AFTER_INIT AudioManagement::AudioManagement() UNMAP_AFTER_INIT void AudioManagement::enumerate_hardware_controllers() { if (!PCI::Access::is_disabled()) { - PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) { + MUST(PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) { // Note: Only consider PCI audio controllers if (device_identifier.class_code().value() != to_underlying(PCI::ClassID::Multimedia) || device_identifier.subclass_code().value() != to_underlying(PCI::Multimedia::SubclassID::AudioController)) @@ -53,7 +53,7 @@ UNMAP_AFTER_INIT void AudioManagement::enumerate_hardware_controllers() return; } m_controllers_list.append(ac97_device.release_value()); - }); + })); } } -- cgit v1.2.3