From: Onur Özkan Date: Thu, 21 Aug 2025 09:10:01 +0000 (+0300) Subject: rust: file: use to_result for error handling X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c37adf34a5dc511e017b5a3bab15fe3171269e46;p=users%2Fhch%2Fmisc.git rust: file: use to_result for error handling Simplifies error handling by replacing the manual check of the return value with the `to_result` helper. Signed-off-by: Onur Özkan Link: https://lore.kernel.org/20250821091001.28563-1-work@onurozkan.dev Signed-off-by: Christian Brauner --- diff --git a/rust/kernel/fs/file.rs b/rust/kernel/fs/file.rs index 18cf579d3312..f1a3fa698745 100644 --- a/rust/kernel/fs/file.rs +++ b/rust/kernel/fs/file.rs @@ -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 { // 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,