mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
Kernel/VirtIO: Use proper error propagation from the get_config method
This allows us to drop null-checks at call-sites, thus simplifying the code and reducing the chance of nullptr-dereference errors.
This commit is contained in:
parent
87a32ab869
commit
bc3eb6d65f
Notes:
sideshowbarker
2024-07-17 01:06:10 +09:00
Author: https://github.com/supercomputer7
Commit: bc3eb6d65f
Pull-request: https://github.com/SerenityOS/serenity/pull/18517
4 changed files with 7 additions and 11 deletions
|
@ -22,9 +22,7 @@ UNMAP_AFTER_INIT NonnullLockRefPtr<Console> Console::must_create(PCI::DeviceIden
|
|||
UNMAP_AFTER_INIT ErrorOr<void> Console::initialize_virtio_resources()
|
||||
{
|
||||
TRY(Device::initialize_virtio_resources());
|
||||
auto const* cfg = get_config(VirtIO::ConfigurationType::Device);
|
||||
if (!cfg)
|
||||
return Error::from_errno(ENODEV);
|
||||
auto const* cfg = TRY(get_config(VirtIO::ConfigurationType::Device));
|
||||
bool success = negotiate_features([&](u64 supported_features) {
|
||||
u64 negotiated = 0;
|
||||
if (is_feature_set(supported_features, VIRTIO_CONSOLE_F_SIZE))
|
||||
|
|
|
@ -151,9 +151,9 @@ UNMAP_AFTER_INIT ErrorOr<void> Device::initialize_virtio_resources()
|
|||
auto mapping_io_window = TRY(IOWindow::create_for_pci_device_bar(device_identifier(), static_cast<PCI::HeaderType0BaseRegister>(cfg.bar)));
|
||||
m_register_bases[cfg.bar] = move(mapping_io_window);
|
||||
}
|
||||
m_common_cfg = get_config(ConfigurationType::Common, 0);
|
||||
m_notify_cfg = get_config(ConfigurationType::Notify, 0);
|
||||
m_isr_cfg = get_config(ConfigurationType::ISR, 0);
|
||||
m_common_cfg = TRY(get_config(ConfigurationType::Common, 0));
|
||||
m_notify_cfg = TRY(get_config(ConfigurationType::Notify, 0));
|
||||
m_isr_cfg = TRY(get_config(ConfigurationType::ISR, 0));
|
||||
} else {
|
||||
auto mapping_io_window = TRY(IOWindow::create_for_pci_device_bar(device_identifier(), PCI::HeaderType0BaseRegister::BAR0));
|
||||
m_register_bases[0] = move(mapping_io_window);
|
||||
|
|
|
@ -30,7 +30,7 @@ protected:
|
|||
virtual StringView class_name() const { return "VirtIO::Device"sv; }
|
||||
explicit Device(PCI::DeviceIdentifier const&);
|
||||
|
||||
Configuration const* get_config(ConfigurationType cfg_type, u32 index = 0) const
|
||||
ErrorOr<Configuration const*> get_config(ConfigurationType cfg_type, u32 index = 0) const
|
||||
{
|
||||
for (auto const& cfg : m_configs) {
|
||||
if (cfg.cfg_type != cfg_type)
|
||||
|
@ -41,7 +41,7 @@ protected:
|
|||
}
|
||||
return &cfg;
|
||||
}
|
||||
return nullptr;
|
||||
return Error::from_errno(ENXIO);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
|
|
|
@ -146,9 +146,7 @@ VirtIOGraphicsAdapter::VirtIOGraphicsAdapter(PCI::DeviceIdentifier const& device
|
|||
ErrorOr<void> VirtIOGraphicsAdapter::initialize_virtio_resources()
|
||||
{
|
||||
TRY(VirtIO::Device::initialize_virtio_resources());
|
||||
auto* config = get_config(VirtIO::ConfigurationType::Device);
|
||||
if (!config)
|
||||
return Error::from_errno(ENODEV);
|
||||
auto* config = TRY(get_config(VirtIO::ConfigurationType::Device));
|
||||
m_device_configuration = config;
|
||||
bool success = negotiate_features([&](u64 supported_features) {
|
||||
u64 negotiated = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue