summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/getrandom.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/getrandom.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/getrandom.cpp')
-rw-r--r--Kernel/Syscalls/getrandom.cpp6
1 files changed, 2 insertions, 4 deletions
diff --git a/Kernel/Syscalls/getrandom.cpp b/Kernel/Syscalls/getrandom.cpp
index 21e9efb848..ee1e6d4913 100644
--- a/Kernel/Syscalls/getrandom.cpp
+++ b/Kernel/Syscalls/getrandom.cpp
@@ -20,11 +20,9 @@ ErrorOr<FlatPtr> Process::sys$getrandom(Userspace<void*> buffer, size_t buffer_s
if (buffer_size > NumericLimits<ssize_t>::max())
return EINVAL;
- auto data_buffer = UserOrKernelBuffer::for_user_buffer(buffer, buffer_size);
- if (!data_buffer.has_value())
- return EFAULT;
+ auto data_buffer = TRY(UserOrKernelBuffer::for_user_buffer(buffer, buffer_size));
- return TRY(data_buffer.value().write_buffered<1024>(buffer_size, [&](Bytes bytes) {
+ return TRY(data_buffer.write_buffered<1024>(buffer_size, [&](Bytes bytes) {
get_good_random_bytes(bytes);
return bytes.size();
}));