rust: phy: use to_result for error handling
Subsystems (4)
Onur Özkan
reviewerPATCH 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.
Signed-off-by Onur Özkan <[email protected]>
--- rust/kernel/net/phy.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
rust/kernel/net/phy.rs +2 -5
@@ -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 (retas u16 ) - } + +to_result (ret).map (|()| retas u16 ) }/// Resolves the advertisements into PHY settings.
--
2.50.0
Quoted 27 lines · Onur Özkan
Simplifies error handling by replacing the manual check of the return value with the
to_resulthelper.Signed-off-by Onur Özkan <[email protected]>--- rust/kernel/net/phy.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)rust/kernel/net/phy.rs +2
-6@@ -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 (retas u16 ) - } + +to_result (ret).map (|()| retas u16 ) }/// Resolves the advertisements into PHY settings. --
Quoted 1 line
2.50.0
Reviewed-by Elle Rhumsaa <[email protected]>
Quoted 4 lines · Onur Özkan
Simplifies error handling by replacing the manual check of the return value with the
to_resulthelper.Signed-off-by Onur Özkan <[email protected]>
Reviewed-by Trevor Gross <[email protected]>
Quoted 24 lines
--- rust/kernel/net/phy.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)rust/kernel/net/phy.rs +2
-6@@ -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 (retas u16 ) - } + +to_result (ret).map (|()| retas u16 ) }/// Resolves the advertisements into PHY settings. --2.50.0
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_resulthelper.Signed-off-by Onur Özkan <[email protected]>--- 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