summaryrefslogtreecommitdiff
path: root/Kernel/UserOrKernelBuffer.h
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-21 12:24:32 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-21 20:22:48 +0100
commitf2c3a41a8f8dab3ccd46b91f52a351a9a855879c (patch)
tree77fe50edcb6521dff4a40af73231adb214923631 /Kernel/UserOrKernelBuffer.h
parentb820ae2828379f1b34ee8106256c5f10c243077b (diff)
downloadserenity-f2c3a41a8f8dab3ccd46b91f52a351a9a855879c.zip
Kernel: Make UserOrKernelBuffer::for_user_buffer() return ErrorOr<T>
This simplifies EFAULT propagation with TRY(). :^)
Diffstat (limited to 'Kernel/UserOrKernelBuffer.h')
-rw-r--r--Kernel/UserOrKernelBuffer.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/Kernel/UserOrKernelBuffer.h b/Kernel/UserOrKernelBuffer.h
index 11ffaf8dac..bebd512f3f 100644
--- a/Kernel/UserOrKernelBuffer.h
+++ b/Kernel/UserOrKernelBuffer.h
@@ -26,18 +26,18 @@ public:
return UserOrKernelBuffer(kernel_buffer);
}
- static Optional<UserOrKernelBuffer> for_user_buffer(u8* user_buffer, size_t size)
+ static ErrorOr<UserOrKernelBuffer> for_user_buffer(u8* user_buffer, size_t size)
{
if (user_buffer && !Memory::is_user_range(VirtualAddress(user_buffer), size))
- return {};
+ return Error::from_errno(EFAULT);
return UserOrKernelBuffer(user_buffer);
}
template<typename UserspaceType>
- static Optional<UserOrKernelBuffer> for_user_buffer(UserspaceType userspace, size_t size)
+ static ErrorOr<UserOrKernelBuffer> for_user_buffer(UserspaceType userspace, size_t size)
{
if (!Memory::is_user_range(VirtualAddress(userspace.unsafe_userspace_ptr()), size))
- return {};
+ return Error::from_errno(EFAULT);
return UserOrKernelBuffer(const_cast<u8*>((const u8*)userspace.unsafe_userspace_ptr()));
}