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

Benno Lossin
2025-03-13T10:21:26Z

On Thu Mar 13, 2025 at 3:13 AM CET, Danilo Krummrich wrote:
> 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>

Reviewed-by: Benno Lossin <benno.lossin@proton.me>

---
Cheers,
Benno

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