diff options
author | Andreas Kling <kling@serenityos.org> | 2021-11-21 12:24:32 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-21 20:22:48 +0100 |
commit | f2c3a41a8f8dab3ccd46b91f52a351a9a855879c (patch) | |
tree | 77fe50edcb6521dff4a40af73231adb214923631 /Kernel/Syscalls/getrandom.cpp | |
parent | b820ae2828379f1b34ee8106256c5f10c243077b (diff) | |
download | serenity-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.cpp | 6 |
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(); })); |