From b5fa55ad007059547c9139d4c4872e158ae255f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Antinori?= Date: Thu, 21 May 2026 16:08:50 -0300 Subject: [PATCH] i2c: rust: mark I2cAdapter methods as inline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building the kernel using llvm-19.1.7-rust-1.85.0-x86_64, the following symbols are generated: $ nm vmlinux | grep ' _R'.*I2cAdapter | rustfilt ffffffff817ff380 T ::get ffffffff817ff400 T ::dec_ref ffffffff817ff3e0 T ::inc_ref However, these Rust symbols are trivial wrappers around the `i2c_get_adapter` and `i2c_put_adapter` functions. It doesn't make sense to go through a trivial wrapper for these functions. Link: https://github.com/Rust-for-Linux/linux/issues/1145 Suggested-by: Alice Ryhl Signed-off-by: Nicolás Antinori Reviewed-by: Onur Özkan Reviewed-by: Igor Korotin Signed-off-by: Igor Korotin --- rust/kernel/i2c.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs index dd9271af5eb8..c4002e293a73 100644 --- a/rust/kernel/i2c.rs +++ b/rust/kernel/i2c.rs @@ -404,6 +404,7 @@ pub fn index(&self) -> i32 { } /// Gets pointer to an `i2c_adapter` by index. + #[inline] pub fn get(index: i32) -> Result> { // SAFETY: `index` must refer to a valid I2C adapter; the kernel // guarantees that `i2c_get_adapter(index)` returns either a valid @@ -425,11 +426,13 @@ pub fn get(index: i32) -> Result> { // SAFETY: Instances of `I2cAdapter` are always reference-counted. unsafe impl AlwaysRefCounted for I2cAdapter { + #[inline] fn inc_ref(&self) { // SAFETY: The existence of a shared reference guarantees that the refcount is non-zero. unsafe { bindings::i2c_get_adapter(self.index()) }; } + #[inline] unsafe fn dec_ref(obj: NonNull) { // SAFETY: The safety requirements guarantee that the refcount is non-zero. unsafe { bindings::i2c_put_adapter(obj.as_ref().as_raw()) }