1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:37:36 +00:00

Kernel/VirtIO: Ensure proper error propagation in core methods

Simplify core methods in the VirtIO bus handling code by ensuring proper
error propagation. This makes initialization of queues, handling changes
in device configuration, and other core patterns more readable as well.

It also allows us to remove the obnoxious pattern of checking for
boolean "success" and if we get false answer then returning an actual
errno code.
This commit is contained in:
Liav A 2023-09-23 00:44:33 +03:00 committed by Andrew Kaster
parent 6ee6a2534d
commit 7718842829
12 changed files with 56 additions and 81 deletions

View file

@ -19,14 +19,10 @@ UNMAP_AFTER_INIT NonnullLockRefPtr<RNG> RNG::must_create_for_pci_instance(PCI::D
UNMAP_AFTER_INIT ErrorOr<void> RNG::initialize_virtio_resources()
{
TRY(Device::initialize_virtio_resources());
bool success = negotiate_features([&](auto) {
TRY(negotiate_features([&](auto) {
return 0;
});
if (!success)
return Error::from_errno(EIO);
success = setup_queues(1);
if (!success)
return Error::from_errno(EIO);
}));
TRY(setup_queues(1));
finish_init();
m_entropy_buffer = TRY(MM.allocate_contiguous_kernel_region(PAGE_SIZE, "VirtIO::RNG"sv, Memory::Region::Access::ReadWrite));
memset(m_entropy_buffer->vaddr().as_ptr(), 0, m_entropy_buffer->size());
@ -39,9 +35,9 @@ UNMAP_AFTER_INIT RNG::RNG(NonnullOwnPtr<TransportEntity> transport_entity)
{
}
bool RNG::handle_device_config_change()
ErrorOr<void> RNG::handle_device_config_change()
{
return false; // Device has no config
return Error::from_errno(EIO); // Device has no config
}
void RNG::handle_queue_update(u16 queue_index)