summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/write.cpp
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/Syscalls/write.cpp
parentb820ae2828379f1b34ee8106256c5f10c243077b (diff)
downloadserenity-f2c3a41a8f8dab3ccd46b91f52a351a9a855879c.zip
Kernel: Make UserOrKernelBuffer::for_user_buffer() return ErrorOr<T>
This simplifies EFAULT propagation with TRY(). :^)
Diffstat (limited to 'Kernel/Syscalls/write.cpp')
-rw-r--r--Kernel/Syscalls/write.cpp12
1 files changed, 4 insertions, 8 deletions
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<FlatPtr> Process::sys$writev(int fd, Userspace<const struct iovec*> 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<FlatPtr> Process::sys$write(int fd, Userspace<const u8*> data, size_t si
if (!description->is_writable())
return EBADF;
- auto buffer = UserOrKernelBuffer::for_user_buffer(data, static_cast<size_t>(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_t>(size)));
+ return do_write(*description, buffer, size);
}
}