From 381fdaa163d8af320f71f817e2922c5d396e2b28 Mon Sep 17 00:00:00 2001 From: Liav A Date: Sun, 12 Dec 2021 16:46:11 +0200 Subject: [PATCH] Kernel/SysFS: Make it clear that some components must be created in boot Using the phrase "create" doesn't give information on whether the object must be allocated or a failure to do so can be handled gracefully. Therefore, we must use better phrase for such purpose, so "must_create" for the allocate-and-construct static methods is definitely good choice. --- Kernel/Firmware/ACPI/Parser.cpp | 4 ++-- Kernel/Firmware/ACPI/Parser.h | 2 +- Kernel/Firmware/BIOS.cpp | 14 ++++++-------- Kernel/Firmware/BIOS.h | 6 +++--- Kernel/Firmware/SysFSFirmware.cpp | 11 +++-------- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/Kernel/Firmware/ACPI/Parser.cpp b/Kernel/Firmware/ACPI/Parser.cpp index 7671957b1b6..ea3458824be 100644 --- a/Kernel/Firmware/ACPI/Parser.cpp +++ b/Kernel/Firmware/ACPI/Parser.cpp @@ -67,9 +67,9 @@ UNMAP_AFTER_INIT ACPISysFSComponent::ACPISysFSComponent(NonnullOwnPtr t { } -UNMAP_AFTER_INIT ErrorOr> ACPISysFSDirectory::try_create(FirmwareSysFSDirectory& firmware_directory) +UNMAP_AFTER_INIT NonnullRefPtr ACPISysFSDirectory::must_create(FirmwareSysFSDirectory& firmware_directory) { - auto acpi_directory = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ACPISysFSDirectory(firmware_directory))); + auto acpi_directory = MUST(adopt_nonnull_ref_or_enomem(new (nothrow) ACPISysFSDirectory(firmware_directory))); return acpi_directory; } diff --git a/Kernel/Firmware/ACPI/Parser.h b/Kernel/Firmware/ACPI/Parser.h index af0a4cd78f8..b00525221eb 100644 --- a/Kernel/Firmware/ACPI/Parser.h +++ b/Kernel/Firmware/ACPI/Parser.h @@ -23,7 +23,7 @@ namespace Kernel::ACPI { class ACPISysFSDirectory : public SysFSDirectory { public: virtual StringView name() const override { return "acpi"sv; } - static ErrorOr> try_create(FirmwareSysFSDirectory& firmware_directory); + static NonnullRefPtr must_create(FirmwareSysFSDirectory& firmware_directory); private: explicit ACPISysFSDirectory(FirmwareSysFSDirectory& firmware_directory); diff --git a/Kernel/Firmware/BIOS.cpp b/Kernel/Firmware/BIOS.cpp index 8f633aa03b1..fed50d6767c 100644 --- a/Kernel/Firmware/BIOS.cpp +++ b/Kernel/Firmware/BIOS.cpp @@ -19,7 +19,7 @@ namespace Kernel { #define SMBIOS_END_SEARCH_ADDR 0xfffff #define SMBIOS_SEARCH_AREA_SIZE (SMBIOS_END_SEARCH_ADDR - SMBIOS_BASE_SEARCH_ADDR) -UNMAP_AFTER_INIT NonnullRefPtr DMIEntryPointExposedBlob::create(PhysicalAddress dmi_entry_point, size_t blob_size) +UNMAP_AFTER_INIT NonnullRefPtr DMIEntryPointExposedBlob::must_create(PhysicalAddress dmi_entry_point, size_t blob_size) { return adopt_ref(*new (nothrow) DMIEntryPointExposedBlob(dmi_entry_point, blob_size)); } @@ -53,7 +53,7 @@ ErrorOr> DMIEntryPointExposedBlob::try_to_generate_buffer return KBuffer::try_create_with_bytes(Span { dmi_blob.ptr(), m_dmi_entry_point_length }); } -UNMAP_AFTER_INIT NonnullRefPtr SMBIOSExposedTable::create(PhysicalAddress smbios_structure_table, size_t smbios_structure_table_length) +UNMAP_AFTER_INIT NonnullRefPtr SMBIOSExposedTable::must_create(PhysicalAddress smbios_structure_table, size_t smbios_structure_table_length) { return adopt_ref(*new (nothrow) SMBIOSExposedTable(smbios_structure_table, smbios_structure_table_length)); } @@ -89,9 +89,9 @@ UNMAP_AFTER_INIT void BIOSSysFSDirectory::set_dmi_32_bit_entry_initialization_va m_smbios_structure_table_length = smbios_entry.ptr()->legacy_structure.smboios_table_length; } -UNMAP_AFTER_INIT ErrorOr> BIOSSysFSDirectory::try_create(FirmwareSysFSDirectory& firmware_directory) +UNMAP_AFTER_INIT NonnullRefPtr BIOSSysFSDirectory::must_create(FirmwareSysFSDirectory& firmware_directory) { - auto bios_directory = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) BIOSSysFSDirectory(firmware_directory))); + auto bios_directory = MUST(adopt_nonnull_ref_or_enomem(new (nothrow) BIOSSysFSDirectory(firmware_directory))); bios_directory->create_components(); return bios_directory; } @@ -108,10 +108,8 @@ void BIOSSysFSDirectory::create_components() dbgln("BIOSSysFSDirectory: invalid smbios structure table length"); return; } - auto dmi_entry_point = DMIEntryPointExposedBlob::create(m_dmi_entry_point, m_dmi_entry_point_length); - m_components.append(dmi_entry_point); - auto smbios_table = SMBIOSExposedTable::create(m_smbios_structure_table, m_smbios_structure_table_length); - m_components.append(smbios_table); + m_components.append(DMIEntryPointExposedBlob::must_create(m_dmi_entry_point, m_dmi_entry_point_length)); + m_components.append(SMBIOSExposedTable::must_create(m_smbios_structure_table, m_smbios_structure_table_length)); } UNMAP_AFTER_INIT void BIOSSysFSDirectory::initialize_dmi_exposer() diff --git a/Kernel/Firmware/BIOS.h b/Kernel/Firmware/BIOS.h index 57699300b6b..afa7b556f8d 100644 --- a/Kernel/Firmware/BIOS.h +++ b/Kernel/Firmware/BIOS.h @@ -72,7 +72,7 @@ protected: class DMIEntryPointExposedBlob : public BIOSSysFSComponent { public: virtual StringView name() const override { return "smbios_entry_point"sv; } - static NonnullRefPtr create(PhysicalAddress dmi_entry_point, size_t blob_size); + static NonnullRefPtr must_create(PhysicalAddress dmi_entry_point, size_t blob_size); private: DMIEntryPointExposedBlob(PhysicalAddress dmi_entry_point, size_t blob_size); @@ -84,7 +84,7 @@ private: class SMBIOSExposedTable : public BIOSSysFSComponent { public: virtual StringView name() const override { return "DMI"sv; } - static NonnullRefPtr create(PhysicalAddress, size_t blob_size); + static NonnullRefPtr must_create(PhysicalAddress, size_t blob_size); private: SMBIOSExposedTable(PhysicalAddress dmi_entry_point, size_t blob_size); @@ -97,7 +97,7 @@ private: class BIOSSysFSDirectory : public SysFSDirectory { public: virtual StringView name() const override { return "bios"sv; } - static ErrorOr> try_create(FirmwareSysFSDirectory&); + static NonnullRefPtr must_create(FirmwareSysFSDirectory&); void create_components(); diff --git a/Kernel/Firmware/SysFSFirmware.cpp b/Kernel/Firmware/SysFSFirmware.cpp index 7cacebda970..e1f6c084bea 100644 --- a/Kernel/Firmware/SysFSFirmware.cpp +++ b/Kernel/Firmware/SysFSFirmware.cpp @@ -21,14 +21,9 @@ UNMAP_AFTER_INIT void FirmwareSysFSDirectory::initialize() void FirmwareSysFSDirectory::create_components() { - auto bios_directory_or_error = BIOSSysFSDirectory::try_create(*this); - VERIFY(!bios_directory_or_error.is_error()); - auto acpi_directory_or_error = ACPI::ACPISysFSDirectory::try_create(*this); - VERIFY(!acpi_directory_or_error.is_error()); - auto power_state_switch_node = PowerStateSwitchNode::must_create(*this); - m_components.append(bios_directory_or_error.release_value()); - m_components.append(acpi_directory_or_error.release_value()); - m_components.append(power_state_switch_node); + m_components.append(BIOSSysFSDirectory::must_create(*this)); + m_components.append(ACPI::ACPISysFSDirectory::must_create(*this)); + m_components.append(PowerStateSwitchNode::must_create(*this)); } UNMAP_AFTER_INIT FirmwareSysFSDirectory::FirmwareSysFSDirectory()