Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <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>

authored by

Onur Özkan and committed by
Jakub Kicinski
a7ddedc8 69cd9935

+2 -5
+2 -5
rust/kernel/net/phy.rs
··· 196 196 // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`. 197 197 // So it's just an FFI call. 198 198 let ret = unsafe { bindings::phy_read_paged(phydev, page.into(), regnum.into()) }; 199 - if ret < 0 { 200 - Err(Error::from_errno(ret)) 201 - } else { 202 - Ok(ret as u16) 203 - } 199 + 200 + to_result(ret).map(|()| ret as u16) 204 201 } 205 202 206 203 /// Resolves the advertisements into PHY settings.