Kernel: Cleanup kmalloc VirtualRange creation

This commit is contained in:
Bananymous 2024-02-25 21:33:30 +02:00
parent efdc4817bb
commit 09c24088a2
1 changed files with 5 additions and 8 deletions

View File

@ -75,21 +75,18 @@ namespace Kernel
BAN::ErrorOr<BAN::UniqPtr<VirtualRange>> VirtualRange::create_kmalloc(size_t size) BAN::ErrorOr<BAN::UniqPtr<VirtualRange>> VirtualRange::create_kmalloc(size_t size)
{ {
VirtualRange* result = new VirtualRange(PageTable::kernel(), false, true); auto* result_ptr = new VirtualRange(PageTable::kernel(), false, true);
ASSERT(result); if (!result_ptr)
return BAN::Error::from_errno(ENOMEM);
auto result = BAN::UniqPtr<VirtualRange>::adopt(result_ptr);
result->m_size = size; result->m_size = size;
result->m_flags = PageTable::Flags::ReadWrite | PageTable::Flags::Present; result->m_flags = PageTable::Flags::ReadWrite | PageTable::Flags::Present;
result->m_vaddr = (vaddr_t)kmalloc(size); result->m_vaddr = (vaddr_t)kmalloc(size);
if (result->m_vaddr == 0) if (result->m_vaddr == 0)
{
delete result;
return BAN::Error::from_errno(ENOMEM); return BAN::Error::from_errno(ENOMEM);
}
result->set_zero(); result->set_zero();
return result;
return BAN::UniqPtr<VirtualRange>::adopt(result);
} }
VirtualRange::VirtualRange(PageTable& page_table, bool preallocated, bool kmalloc) VirtualRange::VirtualRange(PageTable& page_table, bool preallocated, bool kmalloc)