Kernel: Use TRY() in sys$getrandom()

This commit is contained in:
Andreas Kling 2021-09-06 02:30:27 +02:00
parent a8516681b7
commit f2512071f2
Notes: sideshowbarker 2024-07-18 04:38:16 +09:00

View file

@ -23,14 +23,11 @@ KResultOr<FlatPtr> Process::sys$getrandom(Userspace<void*> buffer, size_t buffer
auto data_buffer = UserOrKernelBuffer::for_user_buffer(buffer, buffer_size);
if (!data_buffer.has_value())
return EFAULT;
auto result = data_buffer.value().write_buffered<1024>(buffer_size, [&](Bytes bytes) {
return TRY(data_buffer.value().write_buffered<1024>(buffer_size, [&](Bytes bytes) {
get_good_random_bytes(bytes);
return bytes.size();
});
if (result.is_error())
return result.error();
else
return result.release_value();
}));
}
}