summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/read.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/read.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/read.cpp')
-rw-r--r--Kernel/Syscalls/read.cpp18
1 files changed, 6 insertions, 12 deletions
diff --git a/Kernel/Syscalls/read.cpp b/Kernel/Syscalls/read.cpp
index a001285925..2de85e5bbf 100644
--- a/Kernel/Syscalls/read.cpp
+++ b/Kernel/Syscalls/read.cpp
@@ -63,10 +63,8 @@ ErrorOr<FlatPtr> Process::sys$readv(int fd, Userspace<const struct iovec*> iov,
int nread = 0;
for (auto& vec : vecs) {
TRY(check_blocked_read(description));
- auto buffer = UserOrKernelBuffer::for_user_buffer((u8*)vec.iov_base, vec.iov_len);
- if (!buffer.has_value())
- return EFAULT;
- auto nread_here = TRY(description->read(buffer.value(), vec.iov_len));
+ auto buffer = TRY(UserOrKernelBuffer::for_user_buffer((u8*)vec.iov_base, vec.iov_len));
+ auto nread_here = TRY(description->read(buffer, vec.iov_len));
nread += nread_here;
}
@@ -84,10 +82,8 @@ ErrorOr<FlatPtr> Process::sys$read(int fd, Userspace<u8*> buffer, size_t size)
dbgln_if(IO_DEBUG, "sys$read({}, {}, {})", fd, buffer.ptr(), size);
auto description = TRY(open_readable_file_description(fds(), fd));
TRY(check_blocked_read(description));
- auto user_buffer = UserOrKernelBuffer::for_user_buffer(buffer, size);
- if (!user_buffer.has_value())
- return EFAULT;
- return TRY(description->read(user_buffer.value(), size));
+ auto user_buffer = TRY(UserOrKernelBuffer::for_user_buffer(buffer, size));
+ return TRY(description->read(user_buffer, size));
}
ErrorOr<FlatPtr> Process::sys$pread(int fd, Userspace<u8*> buffer, size_t size, Userspace<off_t*> userspace_offset)
@@ -107,10 +103,8 @@ ErrorOr<FlatPtr> Process::sys$pread(int fd, Userspace<u8*> buffer, size_t size,
if (!description->file().is_seekable())
return EINVAL;
TRY(check_blocked_read(description));
- auto user_buffer = UserOrKernelBuffer::for_user_buffer(buffer, size);
- if (!user_buffer.has_value())
- return EFAULT;
- return TRY(description->read(user_buffer.value(), offset, size));
+ auto user_buffer = TRY(UserOrKernelBuffer::for_user_buffer(buffer, size));
+ return TRY(description->read(user_buffer, offset, size));
}
}