From: Onur Özkan Date: Thu, 21 Aug 2025 09:12:35 +0000 (+0300) Subject: rust: phy: use to_result for error handling X-Git-Tag: v6.18-rc1~132^2~267 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a7ddedc84c59a645ef970b992f7cda5bffc70cc0;p=thirdparty%2Flinux.git rust: phy: 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 Reviewed-by: Elle Rhumsaa Reviewed-by: Trevor Gross Link: https://patch.msgid.link/20250821091235.800-1-work@onurozkan.dev Signed-off-by: Jakub Kicinski --- diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index 7de5cc7a0eeee..c895582cd6245 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -196,11 +196,8 @@ impl Device { // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`. // So it's just an FFI call. let ret = unsafe { bindings::phy_read_paged(phydev, page.into(), regnum.into()) }; - if ret < 0 { - Err(Error::from_errno(ret)) - } else { - Ok(ret as u16) - } + + to_result(ret).map(|()| ret as u16) } /// Resolves the advertisements into PHY settings.