summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/Inode.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-05 17:38:37 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-05 17:38:37 +0200
commit48a0b31c478cb78dece459369610e0f993c8f6f0 (patch)
treef08fde80936619aa94f84edb0973878d8810d147 /Kernel/FileSystem/Inode.cpp
parent9903f5c6ef76dfd3c15e63205e307c9519c32ff3 (diff)
downloadserenity-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/FileSystem/Inode.cpp')
-rw-r--r--Kernel/FileSystem/Inode.cpp16
1 files changed, 4 insertions, 12 deletions
diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp
index 3e5da1d239..7d3537d906 100644
--- a/Kernel/FileSystem/Inode.cpp
+++ b/Kernel/FileSystem/Inode.cpp
@@ -317,9 +317,7 @@ KResult Inode::can_apply_flock(FileDescription const& description, flock const&
KResult Inode::apply_flock(Process const& process, FileDescription const& description, Userspace<flock const*> input_lock)
{
flock new_lock = {};
- if (!copy_from_user(&new_lock, input_lock))
- return EFAULT;
-
+ TRY(copy_from_user(&new_lock, input_lock));
TRY(normalize_flock(description, new_lock));
MutexLocker locker(m_inode_lock);
@@ -343,9 +341,7 @@ KResult Inode::apply_flock(Process const& process, FileDescription const& descri
KResult Inode::get_flock(FileDescription const& description, Userspace<flock*> reference_lock) const
{
flock lookup = {};
- if (!copy_from_user(&lookup, reference_lock))
- return EFAULT;
-
+ TRY(copy_from_user(&lookup, reference_lock));
TRY(normalize_flock(description, lookup));
MutexLocker locker(m_inode_lock, Mutex::Mode::Shared);
@@ -356,16 +352,12 @@ KResult Inode::get_flock(FileDescription const& description, Userspace<flock*> r
if ((lookup.l_type == F_RDLCK && lock.type == F_WRLCK) || lookup.l_type == F_WRLCK) {
lookup = { lock.type, SEEK_SET, lock.start, lock.len, lock.pid };
- if (!copy_to_user(reference_lock, &lookup))
- return EFAULT;
- return KSuccess;
+ return copy_to_user(reference_lock, &lookup);
}
}
lookup.l_type = F_UNLCK;
- if (!copy_to_user(reference_lock, &lookup))
- return EFAULT;
- return KSuccess;
+ return copy_to_user(reference_lock, &lookup);
}
void Inode::remove_flocks_for_description(FileDescription const& description)