Skip to content

Commit c37adf3

Browse files
onur-ozkanbrauner
authored andcommitted
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 <work@onurozkan.dev> Link: https://lore.kernel.org/20250821091001.28563-1-work@onurozkan.dev Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 7619674 commit c37adf3

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

rust/kernel/fs/file.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use crate::{
1111
bindings,
1212
cred::Credential,
13-
error::{code::*, Error, Result},
13+
error::{code::*, to_result, Error, Result},
1414
sync::aref::{ARef, AlwaysRefCounted},
1515
types::{NotThreadSafe, Opaque},
1616
};
@@ -399,9 +399,8 @@ impl FileDescriptorReservation {
399399
pub fn get_unused_fd_flags(flags: u32) -> Result<Self> {
400400
// SAFETY: FFI call, there are no safety requirements on `flags`.
401401
let fd: i32 = unsafe { bindings::get_unused_fd_flags(flags) };
402-
if fd < 0 {
403-
return Err(Error::from_errno(fd));
404-
}
402+
to_result(fd)?;
403+
405404
Ok(Self {
406405
fd: fd as u32,
407406
_not_send: NotThreadSafe,

0 commit comments

Comments
 (0)