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.
This commit is contained in:
Liav A 2021-12-12 16:46:11 +02:00 committed by Andreas Kling
parent 478f543899
commit 381fdaa163
Notes: sideshowbarker 2024-07-17 22:47:42 +09:00
5 changed files with 15 additions and 22 deletions

View file

@ -67,9 +67,9 @@ UNMAP_AFTER_INIT ACPISysFSComponent::ACPISysFSComponent(NonnullOwnPtr<KString> t
{
}
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<ACPISysFSDirectory>> ACPISysFSDirectory::try_create(FirmwareSysFSDirectory& firmware_directory)
UNMAP_AFTER_INIT NonnullRefPtr<ACPISysFSDirectory> 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;
}

View file

@ -23,7 +23,7 @@ namespace Kernel::ACPI {
class ACPISysFSDirectory : public SysFSDirectory {
public:
virtual StringView name() const override { return "acpi"sv; }
static ErrorOr<NonnullRefPtr<ACPISysFSDirectory>> try_create(FirmwareSysFSDirectory& firmware_directory);
static NonnullRefPtr<ACPISysFSDirectory> must_create(FirmwareSysFSDirectory& firmware_directory);
private:
explicit ACPISysFSDirectory(FirmwareSysFSDirectory& firmware_directory);

View file

@ -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> DMIEntryPointExposedBlob::create(PhysicalAddress dmi_entry_point, size_t blob_size)
UNMAP_AFTER_INIT NonnullRefPtr<DMIEntryPointExposedBlob> 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<NonnullOwnPtr<KBuffer>> DMIEntryPointExposedBlob::try_to_generate_buffer
return KBuffer::try_create_with_bytes(Span<u8> { dmi_blob.ptr(), m_dmi_entry_point_length });
}
UNMAP_AFTER_INIT NonnullRefPtr<SMBIOSExposedTable> SMBIOSExposedTable::create(PhysicalAddress smbios_structure_table, size_t smbios_structure_table_length)
UNMAP_AFTER_INIT NonnullRefPtr<SMBIOSExposedTable> 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<NonnullRefPtr<BIOSSysFSDirectory>> BIOSSysFSDirectory::try_create(FirmwareSysFSDirectory& firmware_directory)
UNMAP_AFTER_INIT NonnullRefPtr<BIOSSysFSDirectory> 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()

View file

@ -72,7 +72,7 @@ protected:
class DMIEntryPointExposedBlob : public BIOSSysFSComponent {
public:
virtual StringView name() const override { return "smbios_entry_point"sv; }
static NonnullRefPtr<DMIEntryPointExposedBlob> create(PhysicalAddress dmi_entry_point, size_t blob_size);
static NonnullRefPtr<DMIEntryPointExposedBlob> 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<SMBIOSExposedTable> create(PhysicalAddress, size_t blob_size);
static NonnullRefPtr<SMBIOSExposedTable> 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<NonnullRefPtr<BIOSSysFSDirectory>> try_create(FirmwareSysFSDirectory&);
static NonnullRefPtr<BIOSSysFSDirectory> must_create(FirmwareSysFSDirectory&);
void create_components();

View file

@ -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()