1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:57:45 +00:00

Kernel/SysFS: Prevent allocation for component name during construction

Instead, allocate before constructing the object and pass NonnullOwnPtr
of KString to the object if needed. Some classes can determine their
names as they have a known attribute to look for or have a static name.
This commit is contained in:
Liav A 2021-12-12 16:33:08 +02:00 committed by Andreas Kling
parent 4daf07e69f
commit 478f543899
17 changed files with 116 additions and 65 deletions

View file

@ -22,6 +22,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);
private:
@ -30,16 +31,17 @@ private:
class ACPISysFSComponent : public SysFSComponent {
public:
static NonnullRefPtr<ACPISysFSComponent> create(String name, PhysicalAddress, size_t table_size);
static NonnullRefPtr<ACPISysFSComponent> create(StringView name, PhysicalAddress, size_t table_size);
virtual StringView name() const override { return m_table_name->view(); }
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const override;
protected:
ErrorOr<NonnullOwnPtr<KBuffer>> try_to_generate_buffer() const;
ACPISysFSComponent(String name, PhysicalAddress, size_t table_size);
ACPISysFSComponent(NonnullOwnPtr<KString> table_name, PhysicalAddress, size_t table_size);
PhysicalAddress m_paddr;
size_t m_length;
NonnullOwnPtr<KString> m_table_name;
};
class Parser final : public IRQHandler {