]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rust: file: use to_result for error handling
authorOnur Özkan <work@onurozkan.dev>
Thu, 21 Aug 2025 09:10:01 +0000 (12:10 +0300)
committerChristian Brauner <brauner@kernel.org>
Mon, 1 Sep 2025 11:55:22 +0000 (13:55 +0200)
Simplifies error handling by replacing the manual check
of the return value with the `to_result` helper.

Signed-off-by: Onur Özkan <work@onurozkan.dev>
Link: https://lore.kernel.org/20250821091001.28563-1-work@onurozkan.dev
Signed-off-by: Christian Brauner <brauner@kernel.org>
rust/kernel/fs/file.rs

index 18cf579d3312fa62fc2b59180c4c301320506cf7..f1a3fa6987451dd4221205c9c23cc985710d49e7 100644 (file)
@@ -10,7 +10,7 @@
 use crate::{
     bindings,
     cred::Credential,
-    error::{code::*, Error, Result},
+    error::{code::*, to_result, Error, Result},
     sync::aref::{ARef, AlwaysRefCounted},
     types::{NotThreadSafe, Opaque},
 };
@@ -399,9 +399,8 @@ impl FileDescriptorReservation {
     pub fn get_unused_fd_flags(flags: u32) -> Result<Self> {
         // SAFETY: FFI call, there are no safety requirements on `flags`.
         let fd: i32 = unsafe { bindings::get_unused_fd_flags(flags) };
-        if fd < 0 {
-            return Err(Error::from_errno(fd));
-        }
+        to_result(fd)?;
+
         Ok(Self {
             fd: fd as u32,
             _not_send: NotThreadSafe,