diff options
author | Liav A <liavalb@gmail.com> | 2022-12-16 10:04:42 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-12-16 10:00:31 +0100 |
commit | d94f3b902c82417c25a8e251f909e1d9ecabe6dc (patch) | |
tree | 9f39428e36b81edf94758d6c15dca73d4dfcdaf4 /Kernel | |
parent | e785c66f91f6cc04235703142c1b07a6cf458bfb (diff) | |
download | serenity-d94f3b902c82417c25a8e251f909e1d9ecabe6dc.zip |
Kernel: Propagate properly errors from ISAIDEController initialization
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Arch/x86/ISABus/IDEController.cpp | 43 | ||||
-rw-r--r-- | Kernel/Arch/x86/ISABus/IDEController.h | 4 | ||||
-rw-r--r-- | Kernel/Storage/StorageManagement.cpp | 3 |
3 files changed, 23 insertions, 27 deletions
diff --git a/Kernel/Arch/x86/ISABus/IDEController.cpp b/Kernel/Arch/x86/ISABus/IDEController.cpp index af22874137..64831f5ebd 100644 --- a/Kernel/Arch/x86/ISABus/IDEController.cpp +++ b/Kernel/Arch/x86/ISABus/IDEController.cpp @@ -15,47 +15,42 @@ namespace Kernel { -UNMAP_AFTER_INIT NonnullLockRefPtr<ISAIDEController> ISAIDEController::initialize() +UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<ISAIDEController>> ISAIDEController::initialize() { - return adopt_lock_ref(*new ISAIDEController()); + auto controller = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) ISAIDEController())); + TRY(controller->initialize_channels()); + return controller; } UNMAP_AFTER_INIT ISAIDEController::ISAIDEController() { - initialize_channels(); } -UNMAP_AFTER_INIT void ISAIDEController::initialize_channels() +UNMAP_AFTER_INIT ErrorOr<void> ISAIDEController::initialize_channels() { - auto primary_base_io_window = IOWindow::create_for_io_space(IOAddress(0x1F0), 8).release_value_but_fixme_should_propagate_errors(); - auto primary_control_io_window = IOWindow::create_for_io_space(IOAddress(0x3F6), 4).release_value_but_fixme_should_propagate_errors(); - auto secondary_base_io_window = IOWindow::create_for_io_space(IOAddress(0x170), 8).release_value_but_fixme_should_propagate_errors(); - auto secondary_control_io_window = IOWindow::create_for_io_space(IOAddress(0x376), 4).release_value_but_fixme_should_propagate_errors(); - - auto initialize_and_enumerate = [](IDEChannel& channel) -> void { - { - auto result = channel.allocate_resources_for_isa_ide_controller({}); - // FIXME: Propagate errors properly - VERIFY(!result.is_error()); - } - { - auto result = channel.detect_connected_devices(); - // FIXME: Propagate errors properly - VERIFY(!result.is_error()); - } + auto primary_base_io_window = TRY(IOWindow::create_for_io_space(IOAddress(0x1F0), 8)); + auto primary_control_io_window = TRY(IOWindow::create_for_io_space(IOAddress(0x3F6), 4)); + auto secondary_base_io_window = TRY(IOWindow::create_for_io_space(IOAddress(0x170), 8)); + auto secondary_control_io_window = TRY(IOWindow::create_for_io_space(IOAddress(0x376), 4)); + + auto initialize_and_enumerate = [](IDEChannel& channel) -> ErrorOr<void> { + TRY(channel.allocate_resources_for_isa_ide_controller({})); + TRY(channel.detect_connected_devices()); + return {}; }; auto primary_channel_io_window_group = IDEChannel::IOWindowGroup { move(primary_base_io_window), move(primary_control_io_window) }; auto secondary_channel_io_window_group = IDEChannel::IOWindowGroup { move(secondary_base_io_window), move(secondary_control_io_window) }; - m_channels.append(IDEChannel::create(*this, move(primary_channel_io_window_group), IDEChannel::ChannelType::Primary)); - initialize_and_enumerate(m_channels[0]); + TRY(m_channels.try_append(IDEChannel::create(*this, move(primary_channel_io_window_group), IDEChannel::ChannelType::Primary))); + TRY(initialize_and_enumerate(m_channels[0])); m_channels[0].enable_irq(); - m_channels.append(IDEChannel::create(*this, move(secondary_channel_io_window_group), IDEChannel::ChannelType::Secondary)); - initialize_and_enumerate(m_channels[1]); + TRY(m_channels.try_append(IDEChannel::create(*this, move(secondary_channel_io_window_group), IDEChannel::ChannelType::Secondary))); + TRY(initialize_and_enumerate(m_channels[1])); m_channels[1].enable_irq(); dbgln("ISA IDE controller detected and initialized"); + return {}; } } diff --git a/Kernel/Arch/x86/ISABus/IDEController.h b/Kernel/Arch/x86/ISABus/IDEController.h index 9be7b3b37e..0fa83df194 100644 --- a/Kernel/Arch/x86/ISABus/IDEController.h +++ b/Kernel/Arch/x86/ISABus/IDEController.h @@ -18,12 +18,12 @@ class AsyncBlockDeviceRequest; class ISAIDEController final : public IDEController { public: - static NonnullLockRefPtr<ISAIDEController> initialize(); + static ErrorOr<NonnullLockRefPtr<ISAIDEController>> initialize(); private: ISAIDEController(); LockRefPtr<StorageDevice> device_by_channel_and_position(u32 index) const; - void initialize_channels(); + ErrorOr<void> initialize_channels(); }; } diff --git a/Kernel/Storage/StorageManagement.cpp b/Kernel/Storage/StorageManagement.cpp index 3040571203..aa2ec76393 100644 --- a/Kernel/Storage/StorageManagement.cpp +++ b/Kernel/Storage/StorageManagement.cpp @@ -429,7 +429,8 @@ UNMAP_AFTER_INIT void StorageManagement::initialize(StringView root_device, bool #if ARCH(I386) || ARCH(X86_64) // Note: If PCI is disabled, we assume that at least we have an ISA IDE controller // to probe and use - m_controllers.append(ISAIDEController::initialize()); + auto isa_ide_controller = MUST(ISAIDEController::initialize()); + m_controllers.append(isa_ide_controller); #endif } else { enumerate_pci_controllers(force_pio, poll); |