[PATCH 1/4] rust: pci: use to_result() in enable_device_mem()

Danilo Krummrich
2025-03-13T02:17:37Z

Simplify enable_device_mem() by using to_result() to handle the return
value of the corresponding FFI call.

Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
rust/kernel/pci.rs | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index 4c98b5b9aa1e..386484dcf36e 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -382,12 +382,7 @@ pub fn device_id(&self) -> u16 {
/// Enable memory resources for this device.
pub fn enable_device_mem(&self) -> Result {
// SAFETY: `self.as_raw` is guaranteed to be a pointer to a valid `struct pci_dev`.
- let ret = unsafe { bindings::pci_enable_device_mem(self.as_raw()) };
- if ret != 0 {
- Err(Error::from_errno(ret))
- } else {
- Ok(())
- }
+ to_result(unsafe { bindings::pci_enable_device_mem(self.as_raw()) })
}

/// Enable bus-mastering for this device.
--
2.48.1