diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-06 22:22:14 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-07 01:18:02 +0200 |
commit | e6929835d2438fff5f10da11537dd7d1eb225a80 (patch) | |
tree | 52a1439f8b3ccb3a1731d939c65491b63a88d652 /Kernel/StdLib.cpp | |
parent | ef94c73a01b9da22b323310a0ed0df53e39a3dea (diff) | |
download | serenity-e6929835d2438fff5f10da11537dd7d1eb225a80.zip |
Kernel: Make copy_time_from_user() helpers use KResultOr<Time>
...and use TRY() for smooth error propagation everywhere.
Diffstat (limited to 'Kernel/StdLib.cpp')
-rw-r--r-- | Kernel/StdLib.cpp | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/Kernel/StdLib.cpp b/Kernel/StdLib.cpp index 5bb48ea2b0..68f4baa142 100644 --- a/Kernel/StdLib.cpp +++ b/Kernel/StdLib.cpp @@ -40,31 +40,28 @@ Kernel::KResultOr<NonnullOwnPtr<Kernel::KString>> try_copy_kstring_from_user(Use return new_string; } -[[nodiscard]] Optional<Time> copy_time_from_user(const timespec* ts_user) +KResultOr<Time> copy_time_from_user(timespec const* ts_user) { - timespec ts; - if (copy_from_user(&ts, ts_user, sizeof(timespec)).is_error()) { - return {}; - } + timespec ts {}; + TRY(copy_from_user(&ts, ts_user, sizeof(timespec))); return Time::from_timespec(ts); } -[[nodiscard]] Optional<Time> copy_time_from_user(const timeval* tv_user) + +KResultOr<Time> copy_time_from_user(timeval const* tv_user) { - timeval tv; - if (copy_from_user(&tv, tv_user, sizeof(timeval)).is_error()) { - return {}; - } + timeval tv {}; + TRY(copy_from_user(&tv, tv_user, sizeof(timeval))); return Time::from_timeval(tv); } template<> -[[nodiscard]] Optional<Time> copy_time_from_user<const timeval>(Userspace<const timeval*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); } +KResultOr<Time> copy_time_from_user<const timeval>(Userspace<timeval const*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); } template<> -[[nodiscard]] Optional<Time> copy_time_from_user<timeval>(Userspace<timeval*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); } +KResultOr<Time> copy_time_from_user<timeval>(Userspace<timeval*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); } template<> -[[nodiscard]] Optional<Time> copy_time_from_user<const timespec>(Userspace<const timespec*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); } +KResultOr<Time> copy_time_from_user<const timespec>(Userspace<timespec const*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); } template<> -[[nodiscard]] Optional<Time> copy_time_from_user<timespec>(Userspace<timespec*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); } +KResultOr<Time> copy_time_from_user<timespec>(Userspace<timespec*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); } Optional<u32> user_atomic_fetch_add_relaxed(volatile u32* var, u32 val) { |