Skip to contentSkip to conversation

rust: phy: use to_result for error handling

PATCH Applied Onur Özkan 4 participants 4 messages Aug 21, 2025 – Sep 3, 2025

Subsystems (4)
lore
Share & tools
lore

Onur Özkan

author reviewer
#0 lore raw

PATCH 1/1 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.

---
 rust/kernel/net/phy.rs | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
rust/kernel/net/phy.rs +2 -5
index 7de5cc7a0eee..c895582cd624 100644
@@ -196,11 +196,8 @@ pub fn read_paged(&mut self, page: u16, regnum: u16) -> Result<u16> {
         // 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.

--
2.50.0

Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Onur Özkan

Simplifies error handling by replacing the manual check of the return value with the to_result helper.

---
 rust/kernel/net/phy.rs | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
rust/kernel/net/phy.rs +2 -6
index 7de5cc7a0eee..c895582cd624 100644
@@ -196,11 +196,8 @@ pub fn read_paged(&mut self, page: u16, regnum: u16) -> Result<u16> {
         // 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.
--
Quoted 1 line

2.50.0

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Onur Özkan
Quoted 4 lines · Onur Özkan

Simplifies error handling by replacing the manual check of the return value with the to_result helper.

Quoted 24 lines
---
 rust/kernel/net/phy.rs | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
rust/kernel/net/phy.rs +2 -6
index 7de5cc7a0eee..c895582cd624 100644
@@ -196,11 +196,8 @@ pub fn read_paged(&mut self, page: u16, regnum: u16) -> Result<u16> {
         // 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.
--

2.50.0

#3 lore raw
In reply to Onur Özkan
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Thu, 21 Aug 2025 12:12:35 +0300 you wrote:

Simplifies error handling by replacing the manual check of the return value with the to_result helper.

---
 rust/kernel/net/phy.rs | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

[...]

Here is the summary with links:
- rust: phy: use to_result for error handling

    https://git.kernel.org/netdev/net-next/c/a7ddedc84c59

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html