diff options
author | Liav A <liavalb@gmail.com> | 2022-02-04 19:48:13 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-14 22:39:09 +0100 |
commit | 3fb289e27d3e0ca171438f178ea6750e25ce6f32 (patch) | |
tree | 627a284bebe455e85029a6f99ae03f21b1e36a01 /Kernel/GlobalProcessExposed.cpp | |
parent | c0ed656c94ffa11e1949ed2e4cc68469aa0d0cd0 (diff) | |
download | serenity-3fb289e27d3e0ca171438f178ea6750e25ce6f32.zip |
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.
Diffstat (limited to 'Kernel/GlobalProcessExposed.cpp')
-rw-r--r-- | Kernel/GlobalProcessExposed.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Kernel/GlobalProcessExposed.cpp b/Kernel/GlobalProcessExposed.cpp index c216876ff9..a4c68ca489 100644 --- a/Kernel/GlobalProcessExposed.cpp +++ b/Kernel/GlobalProcessExposed.cpp @@ -5,6 +5,7 @@ */ #include <AK/JsonObjectSerializer.h> +#include <AK/Try.h> #include <AK/UBSanitizer.h> #include <Kernel/Arch/x86/InterruptDisabler.h> #include <Kernel/Arch/x86/ProcessorInfo.h> @@ -680,7 +681,7 @@ private: { auto array = TRY(JsonArraySerializer<>::try_create(builder)); ErrorOr<void> result; // FIXME: Make this nicer - PCI::enumerate([&array, &result](PCI::DeviceIdentifier const& device_identifier) { + TRY(PCI::enumerate([&array, &result](PCI::DeviceIdentifier const& device_identifier) { if (result.is_error()) return; result = ([&]() -> ErrorOr<void> { @@ -699,7 +700,7 @@ private: TRY(obj.finish()); return {}; })(); - }); + })); TRY(result); TRY(array.finish()); return {}; |