* [PATCH] rust: phy: use to_result for error handling
@ 2025-08-21 9:12 Onur Özkan
2025-08-25 22:55 ` Elle Rhumsaa
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Onur Özkan @ 2025-08-21 9:12 UTC (permalink / raw)
To: rust-for-linux
Cc: fujita.tomonori, tmgross, ojeda, alex.gaynor, boqun.feng, gary,
bjorn3_gh, lossin, a.hindborg, aliceryhl, dakr, netdev,
linux-kernel, Onur Özkan
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>
---
rust/kernel/net/phy.rs | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
index 7de5cc7a0eee..c895582cd624 100644
--- a/rust/kernel/net/phy.rs
+++ b/rust/kernel/net/phy.rs
@@ -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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: phy: use to_result for error handling
2025-08-21 9:12 [PATCH] rust: phy: use to_result for error handling Onur Özkan
@ 2025-08-25 22:55 ` Elle Rhumsaa
2025-09-01 8:25 ` Trevor Gross
2025-09-03 22:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Elle Rhumsaa @ 2025-08-25 22:55 UTC (permalink / raw)
To: Onur Özkan
Cc: rust-for-linux, fujita.tomonori, tmgross, ojeda, alex.gaynor,
boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, dakr,
netdev, linux-kernel
On Thu, Aug 21, 2025 at 12:12:35PM +0300, Onur Özkan wrote:
> 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>
> ---
> rust/kernel/net/phy.rs | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
> index 7de5cc7a0eee..c895582cd624 100644
> --- a/rust/kernel/net/phy.rs
> +++ b/rust/kernel/net/phy.rs
> @@ -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: Elle Rhumsaa <elle@weathered-steel.dev>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: phy: use to_result for error handling
2025-08-21 9:12 [PATCH] rust: phy: use to_result for error handling Onur Özkan
2025-08-25 22:55 ` Elle Rhumsaa
@ 2025-09-01 8:25 ` Trevor Gross
2025-09-03 22:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Trevor Gross @ 2025-09-01 8:25 UTC (permalink / raw)
To: Onur Özkan, rust-for-linux
Cc: fujita.tomonori, tmgross, ojeda, alex.gaynor, boqun.feng, gary,
bjorn3_gh, lossin, a.hindborg, aliceryhl, dakr, netdev,
linux-kernel
On Thu Aug 21, 2025 at 4:12 AM CDT, Onur Özkan wrote:
> 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: Trevor Gross <tmgross@umich.edu>
> ---
> rust/kernel/net/phy.rs | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
> index 7de5cc7a0eee..c895582cd624 100644
> --- a/rust/kernel/net/phy.rs
> +++ b/rust/kernel/net/phy.rs
> @@ -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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: phy: use to_result for error handling
2025-08-21 9:12 [PATCH] rust: phy: use to_result for error handling Onur Özkan
2025-08-25 22:55 ` Elle Rhumsaa
2025-09-01 8:25 ` Trevor Gross
@ 2025-09-03 22:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-09-03 22:40 UTC (permalink / raw)
To: =?utf-8?q?Onur_=C3=96zkan_=3Cwork=40onurozkan=2Edev=3E?=
Cc: rust-for-linux, fujita.tomonori, tmgross, ojeda, alex.gaynor,
boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, dakr,
netdev, linux-kernel
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
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.
>
> Signed-off-by: Onur Özkan <work@onurozkan.dev>
> ---
> 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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-03 22:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21 9:12 [PATCH] rust: phy: use to_result for error handling Onur Özkan
2025-08-25 22:55 ` Elle Rhumsaa
2025-09-01 8:25 ` Trevor Gross
2025-09-03 22:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).