[PATCH] rust: pci: Mark Device refcount methods inline

Ethan Plant via B4 Relay posted 1 patch 1 month, 4 weeks ago
rust/kernel/pci.rs | 2 ++
1 file changed, 2 insertions(+)
[PATCH] rust: pci: Mark Device refcount methods inline
Posted by Ethan Plant via B4 Relay 1 month, 4 weeks ago
From: Ethan Plant <plant.ethan@gmail.com>

When building the kernel, the following Rust symbols are generated:
$ nm vmlinux | grep ' _R' | rustfilt | grep -E 'pci::Device.*(inc_ref|dec_ref)'
... T <kernel::pci::Device as kernel::sync::aref::AlwaysRefCounted>::dec_ref
... T <kernel::pci::Device as kernel::sync::aref::AlwaysRefCounted>::inc_ref

These Rust symbols are trivial wrappers around pci_dev_put() and
pci_dev_get(), respectively. It doesn't make sense to go through a
trivial wrapper for these functions, so mark them inline.

Suggested-by: Alice Ryhl <aliceryhl@google.com>
Link: https://github.com/Rust-for-Linux/linux/issues/1145
Signed-off-by: Ethan Plant <plant.ethan@gmail.com>
---
 rust/kernel/pci.rs | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index 5071cae6543f..3e80ec1160b3 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -482,11 +482,13 @@ impl<'a> crate::dma::Device<'a> for Device<device::Core<'a>> {}
 
 // SAFETY: Instances of `Device` are always reference-counted.
 unsafe impl crate::sync::aref::AlwaysRefCounted for Device {
+    #[inline]
     fn inc_ref(&self) {
         // SAFETY: The existence of a shared reference guarantees that the refcount is non-zero.
         unsafe { bindings::pci_dev_get(self.as_raw()) };
     }
 
+    #[inline]
     unsafe fn dec_ref(obj: NonNull<Self>) {
         // SAFETY: The safety requirements guarantee that the refcount is non-zero.
         unsafe { bindings::pci_dev_put(obj.cast().as_ptr()) }

---
base-commit: dc01dfb37b34beeefcfe1c3055364d41a4070c7e
change-id: 20260804-inline-wrappers-f869b6e4601e

Best regards,
--  
Ethan Plant <plant.ethan@gmail.com>
Re: [PATCH] rust: pci: Mark Device refcount methods inline
Posted by Danilo Krummrich 1 month, 3 weeks ago
On Tue, 04 Aug 2026 16:24:25 -0700, Ethan Plant wrote:
> [PATCH] rust: pci: Mark Device refcount methods inline

Applied, thanks!

  Branch: driver-core-testing
  Tree:   git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git

[1/1] rust: pci: Mark Device refcount methods inline
      commit: 56c193a5cb37

The patch will appear in the next linux-next integration (typically within 24
hours on weekdays).

The patch is in the driver-core-testing branch and will be promoted to
driver-core-next after validation.
Re: [PATCH] rust: pci: Mark Device refcount methods inline
Posted by Alice Ryhl 1 month, 3 weeks ago
On Wed, Aug 5, 2026 at 1:24 AM Ethan Plant via B4 Relay
<devnull+plant.ethan.gmail.com@kernel.org> wrote:
>
> From: Ethan Plant <plant.ethan@gmail.com>
>
> When building the kernel, the following Rust symbols are generated:
> $ nm vmlinux | grep ' _R' | rustfilt | grep -E 'pci::Device.*(inc_ref|dec_ref)'
> ... T <kernel::pci::Device as kernel::sync::aref::AlwaysRefCounted>::dec_ref
> ... T <kernel::pci::Device as kernel::sync::aref::AlwaysRefCounted>::inc_ref
>
> These Rust symbols are trivial wrappers around pci_dev_put() and
> pci_dev_get(), respectively. It doesn't make sense to go through a
> trivial wrapper for these functions, so mark them inline.
>
> Suggested-by: Alice Ryhl <aliceryhl@google.com>
> Link: https://github.com/Rust-for-Linux/linux/issues/1145
> Signed-off-by: Ethan Plant <plant.ethan@gmail.com>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>