]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rust: phy: use to_result for error handling
authorOnur Özkan <work@onurozkan.dev>
Thu, 21 Aug 2025 09:12:35 +0000 (12:12 +0300)
committerJakub Kicinski <kuba@kernel.org>
Wed, 3 Sep 2025 22:35:42 +0000 (15:35 -0700)
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>
Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Link: https://patch.msgid.link/20250821091235.800-1-work@onurozkan.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
rust/kernel/net/phy.rs

index 7de5cc7a0eeee03ad87de1a150ed7232605b5182..c895582cd624586e37634c870568c7db68209955 100644 (file)
@@ -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.