From f2c3a41a8f8dab3ccd46b91f52a351a9a855879c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 21 Nov 2021 12:24:32 +0100 Subject: Kernel: Make UserOrKernelBuffer::for_user_buffer() return ErrorOr This simplifies EFAULT propagation with TRY(). :^) --- Kernel/Syscalls/write.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'Kernel/Syscalls/write.cpp') diff --git a/Kernel/Syscalls/write.cpp b/Kernel/Syscalls/write.cpp index 09d4c40cfb..d056df3b6b 100644 --- a/Kernel/Syscalls/write.cpp +++ b/Kernel/Syscalls/write.cpp @@ -38,10 +38,8 @@ ErrorOr Process::sys$writev(int fd, Userspace iov, int nwritten = 0; for (auto& vec : vecs) { - auto buffer = UserOrKernelBuffer::for_user_buffer((u8*)vec.iov_base, vec.iov_len); - if (!buffer.has_value()) - return EFAULT; - auto result = do_write(*description, buffer.value(), vec.iov_len); + auto buffer = TRY(UserOrKernelBuffer::for_user_buffer((u8*)vec.iov_base, vec.iov_len)); + auto result = do_write(*description, buffer, vec.iov_len); if (result.is_error()) { if (nwritten == 0) return result.release_error(); @@ -104,10 +102,8 @@ ErrorOr Process::sys$write(int fd, Userspace data, size_t si if (!description->is_writable()) return EBADF; - auto buffer = UserOrKernelBuffer::for_user_buffer(data, static_cast(size)); - if (!buffer.has_value()) - return EFAULT; - return do_write(*description, buffer.value(), size); + auto buffer = TRY(UserOrKernelBuffer::for_user_buffer(data, static_cast(size))); + return do_write(*description, buffer, size); } } -- cgit v1.2.3