Skip to contentSkip to conversation

rust: pci: Use explicit types in FFI callbacks

PATCH In review herculoxz 5 participants 5 messages Jul 29, 2025 – Jul 30, 2025

Subsystems (3)
lore
Share & tools
lore

herculoxz

author
#0 lore raw

PATCH v2 1/1 rust: pci: Use explicit types in FFI callbacks

From: Abhinav Ananthu <[email protected]>

Update PCI FFI callback signatures to use c_int from the prelude, instead of accessing it via kernel::ffi::c_int.

This follows Rust-for-Linux coding guidelines and improves ABI correctness when interfacing with C code.

---
 rust/kernel/pci.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
rust/kernel/pci.rs +2 -2
index 5ce07999168e..fbeeaec4e044 100644
@@ -61,7 +61,7 @@ impl<T: Driver + 'static> Adapter<T> {
     extern "C" fn probe_callback(
         pdev: *mut bindings::pci_dev,
         id: *const bindings::pci_device_id,
-    ) -> kernel::ffi::c_int {
+    ) -> c_int {
         // SAFETY: The PCI bus only ever calls the probe callback with a valid pointer to a
         // `struct pci_dev`.
         //
@@ -333,7 +333,7 @@ unsafe fn do_release(pdev: &Device, ioptr: usize, num: i32) {
         // `ioptr` is valid by the safety requirements.
         // `num` is valid by the safety requirements.
         unsafe {
-            bindings::pci_iounmap(pdev.as_raw(), ioptr as *mut kernel::ffi::c_void);
+            bindings::pci_iounmap(pdev.as_raw(), ioptr as *mut c_void);
             bindings::pci_release_region(pdev.as_raw(), num);
         }
     }
Signature · 1 line
2.34.1
#1 lore raw
Quoted 3 lines · herculoxz

and improves ABI
correctness when interfacing with C code.

I think this still sounds like it is fixing an ABI issue -- I would probably just remove that second sentence.

(But no need for a v3 -- I think it can be fixed on apply unless Danilo wants it).

Thanks!

Cheers,
Miguel

maintainer
#2 lore raw
Quoted 7 lines · Miguel Ojeda
Quoted 3 lines · herculoxz

and improves ABI
correctness when interfacing with C code.

I think this still sounds like it is fixing an ABI issue -- I would probably just remove that second sentence.

I agree, the types exported via prelude are the ones from kernel::ffi.

Quoted 2 lines

(But no need for a v3 -- I think it can be fixed on apply unless Danilo wants it).

Yeah, I can fix it up when applying the patch.

I also think the subject from v1, i.e. "use c_* types via kernel prelude", was better. This one is a bit misleading, the types in the FFI callbacks are already explicit.

Unless I hear otherwise, I will also revert the subject to the one of v1 when I apply the patch.

Thanks,
Danilo

reviewer Reviewed-by
#3 lore raw
Quoted 14 lines · Danilo Krummrich
Quoted 7 lines · Miguel Ojeda
Quoted 3 lines · herculoxz

and improves ABI
correctness when interfacing with C code.

I think this still sounds like it is fixing an ABI issue -- I would probably just remove that second sentence.

I agree, the types exported via prelude are the ones from kernel::ffi.

Quoted 2 lines

(But no need for a v3 -- I think it can be fixed on apply unless Danilo wants it).

Quoted 8 lines

Yeah, I can fix it up when applying the patch.

I also think the subject from v1, i.e. "use c_* types via kernel prelude", was better. This one is a bit misleading, the types in the FFI callbacks are already explicit.

Unless I hear otherwise, I will also revert the subject to the one of v1 when I apply the patch.

With the above changes:

reviewer Reviewed-by on v2 1/1
#4 lore raw
In reply to herculoxz
Quoted 9 lines · herculoxz

From: Abhinav Ananthu <[email protected]>

Update PCI FFI callback signatures to use c_int from the prelude, instead of accessing it via kernel::ffi::c_int.

This follows Rust-for-Linux coding guidelines and improves ABI correctness when interfacing with C code.

---
Cheers,
Benno

Quoted 3 lines
---
 rust/kernel/pci.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)