1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 13:05:09 +00:00

Kernel: Make copy_time_from_user() helpers use KResultOr<Time>

...and use TRY() for smooth error propagation everywhere.
This commit is contained in:
Andreas Kling 2021-09-06 22:22:14 +02:00
parent ef94c73a01
commit e6929835d2
6 changed files with 29 additions and 54 deletions

View file

@ -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)
{