mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] i2c: rust: mark I2cAdapter methods as inline
@ 2026-05-21 19:08 Nicolás Antinori
  2026-05-22  5:09 ` Onur Özkan
  2026-05-23  8:24 ` Igor Korotin
  0 siblings, 2 replies; 3+ messages in thread
From: Nicolás Antinori @ 2026-05-21 19:08 UTC (permalink / raw)
  To: igor.korotin
  Cc: Nicolás Antinori, dakr, daniel.almeida, ojeda, boqun, gary,
	bjorn3_gh, lossin, aliceryhl, tmgross, rust-for-linux,
	linux-kernel

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 <kernel::i2c::I2cAdapter>::get
ffffffff817ff400 T <kernel::i2c::I2cAdapter as kernel::sync::aref::AlwaysRefCounted>::dec_ref
ffffffff817ff3e0 T <kernel::i2c::I2cAdapter as kernel::sync::aref::AlwaysRefCounted>::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 <aliceryhl@google.com>
Signed-off-by: Nicolás Antinori <nico.antinori.7@gmail.com>
---
 rust/kernel/i2c.rs | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs
index 7b908f0c5a58..07f9fd53c4e5 100644
--- a/rust/kernel/i2c.rs
+++ b/rust/kernel/i2c.rs
@@ -397,6 +397,7 @@ pub fn index(&self) -> i32 {
     }
 
     /// Gets pointer to an `i2c_adapter` by index.
+    #[inline]
     pub fn get(index: i32) -> Result<ARef<Self>> {
         // SAFETY: `index` must refer to a valid I2C adapter; the kernel
         // guarantees that `i2c_get_adapter(index)` returns either a valid
@@ -416,11 +417,13 @@ pub fn get(index: i32) -> Result<ARef<Self>> {
 
 // 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<Self>) {
         // SAFETY: The safety requirements guarantee that the refcount is non-zero.
         unsafe { bindings::i2c_put_adapter(obj.as_ref().as_raw()) }
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] i2c: rust: mark I2cAdapter methods as inline
  2026-05-21 19:08 [PATCH] i2c: rust: mark I2cAdapter methods as inline Nicolás Antinori
@ 2026-05-22  5:09 ` Onur Özkan
  2026-05-23  8:24 ` Igor Korotin
  1 sibling, 0 replies; 3+ messages in thread
From: Onur Özkan @ 2026-05-22  5:09 UTC (permalink / raw)
  To: Nicolás Antinori
  Cc: igor.korotin, dakr, daniel.almeida, ojeda, boqun, gary,
	bjorn3_gh, lossin, aliceryhl, tmgross, rust-for-linux,
	linux-kernel, Onur Özkan

On Thu, 21 May 2026 16:08:50 -0300
Nicolás Antinori <nico.antinori.7@gmail.com> wrote:

> 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 <kernel::i2c::I2cAdapter>::get
> ffffffff817ff400 T <kernel::i2c::I2cAdapter as kernel::sync::aref::AlwaysRefCounted>::dec_ref
> ffffffff817ff3e0 T <kernel::i2c::I2cAdapter as kernel::sync::aref::AlwaysRefCounted>::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 <aliceryhl@google.com>
> Signed-off-by: Nicolás Antinori <nico.antinori.7@gmail.com>

Thanks!

Reviewed-by: Onur Özkan <work@onurozkan.dev>

> ---
>  rust/kernel/i2c.rs | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs
> index 7b908f0c5a58..07f9fd53c4e5 100644
> --- a/rust/kernel/i2c.rs
> +++ b/rust/kernel/i2c.rs
> @@ -397,6 +397,7 @@ pub fn index(&self) -> i32 {
>      }
>  
>      /// Gets pointer to an `i2c_adapter` by index.
> +    #[inline]
>      pub fn get(index: i32) -> Result<ARef<Self>> {
>          // SAFETY: `index` must refer to a valid I2C adapter; the kernel
>          // guarantees that `i2c_get_adapter(index)` returns either a valid
> @@ -416,11 +417,13 @@ pub fn get(index: i32) -> Result<ARef<Self>> {
>  
>  // 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<Self>) {
>          // SAFETY: The safety requirements guarantee that the refcount is non-zero.
>          unsafe { bindings::i2c_put_adapter(obj.as_ref().as_raw()) }
> -- 
> 2.53.0
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] i2c: rust: mark I2cAdapter methods as inline
  2026-05-21 19:08 [PATCH] i2c: rust: mark I2cAdapter methods as inline Nicolás Antinori
  2026-05-22  5:09 ` Onur Özkan
@ 2026-05-23  8:24 ` Igor Korotin
  1 sibling, 0 replies; 3+ messages in thread
From: Igor Korotin @ 2026-05-23  8:24 UTC (permalink / raw)
  To: Nicolás Antinori
  Cc: dakr, daniel.almeida, ojeda, boqun, gary, bjorn3_gh, lossin,
	aliceryhl, tmgross, rust-for-linux, linux-kernel

Hello Nicolas

On 5/21/2026 8:08 PM, Nicolás Antinori wrote:
> 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 <kernel::i2c::I2cAdapter>::get
> ffffffff817ff400 T <kernel::i2c::I2cAdapter as kernel::sync::aref::AlwaysRefCounted>::dec_ref
> ffffffff817ff3e0 T <kernel::i2c::I2cAdapter as kernel::sync::aref::AlwaysRefCounted>::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 <aliceryhl@google.com>
> Signed-off-by: Nicolás Antinori <nico.antinori.7@gmail.com>
> ---
>   rust/kernel/i2c.rs | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs
> index 7b908f0c5a58..07f9fd53c4e5 100644
> --- a/rust/kernel/i2c.rs
> +++ b/rust/kernel/i2c.rs
> @@ -397,6 +397,7 @@ pub fn index(&self) -> i32 {
>       }
>   
>       /// Gets pointer to an `i2c_adapter` by index.
> +    #[inline]
>       pub fn get(index: i32) -> Result<ARef<Self>> {
>           // SAFETY: `index` must refer to a valid I2C adapter; the kernel
>           // guarantees that `i2c_get_adapter(index)` returns either a valid
> @@ -416,11 +417,13 @@ pub fn get(index: i32) -> Result<ARef<Self>> {
>   
>   // 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<Self>) {
>           // SAFETY: The safety requirements guarantee that the refcount is non-zero.
>           unsafe { bindings::i2c_put_adapter(obj.as_ref().as_raw()) }

Reviewed-by: Igor Korotin <igor.korotin@linux.dev>

I'll take it through Rust I2C next

Thanks
Igor

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-05-23  8:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-21 19:08 [PATCH] i2c: rust: mark I2cAdapter methods as inline Nicolás Antinori
2026-05-22  5:09 ` Onur Özkan
2026-05-23  8:24 ` Igor Korotin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome