diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-05 17:38:37 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-05 17:38:37 +0200 |
commit | 48a0b31c478cb78dece459369610e0f993c8f6f0 (patch) | |
tree | f08fde80936619aa94f84edb0973878d8810d147 /Kernel/Syscalls/stat.cpp | |
parent | 9903f5c6ef76dfd3c15e63205e307c9519c32ff3 (diff) | |
download | serenity-48a0b31c478cb78dece459369610e0f993c8f6f0.zip |
Kernel: Make copy_{from,to}_user() return KResult and use TRY()
This makes EFAULT propagation flow much more naturally. :^)
Diffstat (limited to 'Kernel/Syscalls/stat.cpp')
-rw-r--r-- | Kernel/Syscalls/stat.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/Kernel/Syscalls/stat.cpp b/Kernel/Syscalls/stat.cpp index ac31ec9ce0..908213b297 100644 --- a/Kernel/Syscalls/stat.cpp +++ b/Kernel/Syscalls/stat.cpp @@ -19,10 +19,8 @@ KResultOr<FlatPtr> Process::sys$fstat(int fd, Userspace<stat*> user_statbuf) if (!description) return EBADF; stat buffer = {}; - auto result = description->stat(buffer); - if (!copy_to_user(user_statbuf, &buffer)) - return EFAULT; - return result; + TRY(description->stat(buffer)); + return copy_to_user(user_statbuf, &buffer); } KResultOr<FlatPtr> Process::sys$stat(Userspace<const Syscall::SC_stat_params*> user_params) @@ -30,8 +28,7 @@ KResultOr<FlatPtr> Process::sys$stat(Userspace<const Syscall::SC_stat_params*> u VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) REQUIRE_PROMISE(rpath); Syscall::SC_stat_params params; - if (!copy_from_user(¶ms, user_params)) - return EFAULT; + TRY(copy_from_user(¶ms, user_params)); auto path = get_syscall_path_argument(params.path); if (path.is_error()) return path.error(); @@ -55,9 +52,7 @@ KResultOr<FlatPtr> Process::sys$stat(Userspace<const Syscall::SC_stat_params*> u auto result = metadata_or_error.value().stat(statbuf); if (result.is_error()) return result; - if (!copy_to_user(params.statbuf, &statbuf)) - return EFAULT; - return 0; + return copy_to_user(params.statbuf, &statbuf); } } |