1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 16:24:59 +00:00

Kernel: Make KBuffer::try_create_with_size() return KResultOr

This allows us to use TRY() in a lot of new places.
This commit is contained in:
Andreas Kling 2021-09-07 15:15:08 +02:00
parent c69035c630
commit 899cee8185
10 changed files with 31 additions and 72 deletions

View file

@ -553,9 +553,7 @@ KResult Plan9FS::read_and_dispatch_one_message()
Header header;
TRY(do_read(reinterpret_cast<u8*>(&header), sizeof(header)));
auto buffer = KBuffer::try_create_with_size(header.size, Memory::Region::Access::ReadWrite);
if (!buffer)
return ENOMEM;
auto buffer = TRY(KBuffer::try_create_with_size(header.size, Memory::Region::Access::ReadWrite));
// Copy the already read header into the buffer.
memcpy(buffer->data(), &header, sizeof(header));
TRY(do_read(buffer->data() + sizeof(header), header.size - sizeof(header)));
@ -567,7 +565,7 @@ KResult Plan9FS::read_and_dispatch_one_message()
auto completion = optional_completion.value();
SpinlockLocker lock(completion->lock);
completion->result = KSuccess;
completion->message = adopt_own_if_nonnull(new (nothrow) Message { buffer.release_nonnull() });
completion->message = adopt_own_if_nonnull(new (nothrow) Message { move(buffer) });
completion->completed = true;
m_completions.remove(header.tag);