public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] rust: Mark all from() for Error functions inline
@ 2026-03-25  0:51 alistair23
  2026-03-25  1:19 ` Miguel Ojeda
  0 siblings, 1 reply; 4+ messages in thread
From: alistair23 @ 2026-03-25  0:51 UTC (permalink / raw)
  To: dakr, ljs, vbabka, Liam.Howlett, urezki, ojeda, boqun, gary,
	bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, tamird, work,
	acourbot, rust-for-linux, linux-kernel
  Cc: alistair23, Alistair Francis

From: Alistair Francis <alistair.francis@wdc.com>

Mark all of the existing

impl From<...> for Error {
    fn from(err: ...) -> Self {
        ...
    }
}

functions as `#[inline]`

There was a recent request [1] to inline the simple from() Error
functions to avoid the function call overhead.

This patch inlines all of the functions (except for the pin-init) and
converts one existing `inline(always)` to `inline` to match the styles.

1: https://lkml.org/lkml/2026/3/13/962

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
The pin-init changes have been submitted here instead:
https://github.com/Rust-for-Linux/pin-init/pull/126

 rust/kernel/alloc/kvec/errors.rs | 3 +++
 rust/kernel/error.rs             | 6 ++++++
 rust/kernel/ptr/projection.rs    | 2 +-
 rust/kernel/xarray.rs            | 1 +
 rust/syn/error.rs                | 1 +
 5 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/alloc/kvec/errors.rs b/rust/kernel/alloc/kvec/errors.rs
index e7de5049ee47..985c5f2c3962 100644
--- a/rust/kernel/alloc/kvec/errors.rs
+++ b/rust/kernel/alloc/kvec/errors.rs
@@ -15,6 +15,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 }
 
 impl<T> From<PushError<T>> for Error {
+    #[inline]
     fn from(_: PushError<T>) -> Error {
         // Returning ENOMEM isn't appropriate because the system is not out of memory. The vector
         // is just full and we are refusing to resize it.
@@ -32,6 +33,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 }
 
 impl From<RemoveError> for Error {
+    #[inline]
     fn from(_: RemoveError) -> Error {
         EINVAL
     }
@@ -55,6 +57,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 }
 
 impl<T> From<InsertError<T>> for Error {
+    #[inline]
     fn from(_: InsertError<T>) -> Error {
         EINVAL
     }
diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
index 258b12afdcba..935787c2a91c 100644
--- a/rust/kernel/error.rs
+++ b/rust/kernel/error.rs
@@ -216,36 +216,42 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 }
 
 impl From<AllocError> for Error {
+    #[inline]
     fn from(_: AllocError) -> Error {
         code::ENOMEM
     }
 }
 
 impl From<TryFromIntError> for Error {
+    #[inline]
     fn from(_: TryFromIntError) -> Error {
         code::EINVAL
     }
 }
 
 impl From<Utf8Error> for Error {
+    #[inline]
     fn from(_: Utf8Error) -> Error {
         code::EINVAL
     }
 }
 
 impl From<LayoutError> for Error {
+    #[inline]
     fn from(_: LayoutError) -> Error {
         code::ENOMEM
     }
 }
 
 impl From<fmt::Error> for Error {
+    #[inline]
     fn from(_: fmt::Error) -> Error {
         code::EINVAL
     }
 }
 
 impl From<core::convert::Infallible> for Error {
+    #[inline]
     fn from(e: core::convert::Infallible) -> Error {
         match e {}
     }
diff --git a/rust/kernel/ptr/projection.rs b/rust/kernel/ptr/projection.rs
index 140ea8e21617..7e37390da6c6 100644
--- a/rust/kernel/ptr/projection.rs
+++ b/rust/kernel/ptr/projection.rs
@@ -13,7 +13,7 @@
 pub struct OutOfBound;
 
 impl From<OutOfBound> for Error {
-    #[inline(always)]
+    #[inline]
     fn from(_: OutOfBound) -> Self {
         ERANGE
     }
diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
index a49d6db28845..46e5f43223fe 100644
--- a/rust/kernel/xarray.rs
+++ b/rust/kernel/xarray.rs
@@ -172,6 +172,7 @@ pub struct StoreError<T> {
 }
 
 impl<T> From<StoreError<T>> for Error {
+    #[inline]
     fn from(value: StoreError<T>) -> Self {
         value.error
     }
diff --git a/rust/syn/error.rs b/rust/syn/error.rs
index 6fa0faf7f4e4..636f07d56d05 100644
--- a/rust/syn/error.rs
+++ b/rust/syn/error.rs
@@ -405,6 +405,7 @@ impl Copy for SpanRange {}
 impl std::error::Error for Error {}
 
 impl From<LexError> for Error {
+    #[inline]
     fn from(err: LexError) -> Self {
         Error::new(err.span(), err)
     }
-- 
2.53.0


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

* Re: [PATCH v2] rust: Mark all from() for Error functions inline
  2026-03-25  0:51 [PATCH v2] rust: Mark all from() for Error functions inline alistair23
@ 2026-03-25  1:19 ` Miguel Ojeda
  2026-03-25 14:21   ` Gary Guo
  2026-03-25 15:29   ` Danilo Krummrich
  0 siblings, 2 replies; 4+ messages in thread
From: Miguel Ojeda @ 2026-03-25  1:19 UTC (permalink / raw)
  To: alistair23, gary
  Cc: dakr, ljs, vbabka, Liam.Howlett, urezki, ojeda, boqun, bjorn3_gh,
	lossin, a.hindborg, aliceryhl, tmgross, tamird, work, acourbot,
	rust-for-linux, linux-kernel, Alistair Francis

On Wed, Mar 25, 2026 at 1:51 AM <alistair23@gmail.com> wrote:
>
> 1: https://lkml.org/lkml/2026/3/13/962

For links, please use the Link: tag (and also please use
lore.kernel.org for mailing list links), e.g. it would usually look
like:

Link: https://lore.kernel.org/... [1]

(By the way, the idea was to create a "good first issue" for new
contributors in our issue tracker, but of course it is also good to
get this done)

>  rust/kernel/alloc/kvec/errors.rs | 3 +++
>  rust/kernel/xarray.rs            | 1 +

Thanks for Cc'ing the maintainers on this -- now the maintainers may
give their Acked-by's! :)

> rust/kernel/ptr/projection.rs    | 2 +-

Gary: there is no `build_assert!` in sight, so it is fine, but perhaps
you wanted to have it more forcefully inlined because it was trivial?

>  rust/syn/error.rs                | 1 +

We don't want to change `syn`, since it is a vendored crate. It also
runs just in the host, so it doesn't matter if it is inline or not.

Thanks!

Cheers,
Miguel

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

* Re: [PATCH v2] rust: Mark all from() for Error functions inline
  2026-03-25  1:19 ` Miguel Ojeda
@ 2026-03-25 14:21   ` Gary Guo
  2026-03-25 15:29   ` Danilo Krummrich
  1 sibling, 0 replies; 4+ messages in thread
From: Gary Guo @ 2026-03-25 14:21 UTC (permalink / raw)
  To: Miguel Ojeda, alistair23, gary
  Cc: dakr, ljs, vbabka, Liam.Howlett, urezki, ojeda, boqun, bjorn3_gh,
	lossin, a.hindborg, aliceryhl, tmgross, tamird, work, acourbot,
	rust-for-linux, linux-kernel, Alistair Francis

On Wed Mar 25, 2026 at 1:19 AM GMT, Miguel Ojeda wrote:
> On Wed, Mar 25, 2026 at 1:51 AM <alistair23@gmail.com> wrote:
>>
>> 1: https://lkml.org/lkml/2026/3/13/962
>
> For links, please use the Link: tag (and also please use
> lore.kernel.org for mailing list links), e.g. it would usually look
> like:
>
> Link: https://lore.kernel.org/... [1]
>
> (By the way, the idea was to create a "good first issue" for new
> contributors in our issue tracker, but of course it is also good to
> get this done)
>
>>  rust/kernel/alloc/kvec/errors.rs | 3 +++
>>  rust/kernel/xarray.rs            | 1 +
>
> Thanks for Cc'ing the maintainers on this -- now the maintainers may
> give their Acked-by's! :)
>
>> rust/kernel/ptr/projection.rs    | 2 +-
>
> Gary: there is no `build_assert!` in sight, so it is fine, but perhaps
> you wanted to have it more forcefully inlined because it was trivial?

I just `#[inline(always)]` everything there :)

I don't think this path is actually exercised by `build_assert!()`, so it is
fine.

>
>>  rust/syn/error.rs                | 1 +
>
> We don't want to change `syn`, since it is a vendored crate. It also
> runs just in the host, so it doesn't matter if it is inline or not.

I wouldn't mind having it, but it should go separately and not be part of this
patch.

Best,
Gary


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

* Re: [PATCH v2] rust: Mark all from() for Error functions inline
  2026-03-25  1:19 ` Miguel Ojeda
  2026-03-25 14:21   ` Gary Guo
@ 2026-03-25 15:29   ` Danilo Krummrich
  1 sibling, 0 replies; 4+ messages in thread
From: Danilo Krummrich @ 2026-03-25 15:29 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: alistair23, gary, ljs, vbabka, Liam.Howlett, urezki, ojeda, boqun,
	bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, tamird, work,
	acourbot, rust-for-linux, linux-kernel, Alistair Francis

On Wed Mar 25, 2026 at 2:19 AM CET, Miguel Ojeda wrote:
>>  rust/kernel/alloc/kvec/errors.rs | 3 +++
>
> Thanks for Cc'ing the maintainers on this -- now the maintainers may
> give their Acked-by's! :)

Acked-by: Danilo Krummrich <dakr@kernel.org>

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

end of thread, other threads:[~2026-03-25 15:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-25  0:51 [PATCH v2] rust: Mark all from() for Error functions inline alistair23
2026-03-25  1:19 ` Miguel Ojeda
2026-03-25 14:21   ` Gary Guo
2026-03-25 15:29   ` Danilo Krummrich

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