* [PATCH] rust: Mark all from() for Error functions inline
@ 2026-03-20 1:18 alistair23
2026-03-20 2:55 ` Miguel Ojeda
2026-03-20 8:15 ` Benno Lossin
0 siblings, 2 replies; 3+ messages in thread
From: alistair23 @ 2026-03-20 1:18 UTC (permalink / raw)
To: linux-kernel, rust-for-linux, aliceryhl, ojeda
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]`
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
rust/kernel/alloc/kvec/errors.rs | 3 +++
rust/kernel/error.rs | 6 ++++++
rust/kernel/ptr/projection.rs | 2 +-
rust/kernel/xarray.rs | 1 +
rust/pin-init/examples/error.rs | 2 ++
rust/pin-init/examples/pthread_mutex.rs | 2 ++
rust/syn/error.rs | 1 +
7 files changed, 16 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/pin-init/examples/error.rs b/rust/pin-init/examples/error.rs
index 8f4e135eb8ba..96f095398e8d 100644
--- a/rust/pin-init/examples/error.rs
+++ b/rust/pin-init/examples/error.rs
@@ -11,6 +11,7 @@
pub struct Error;
impl From<Infallible> for Error {
+ #[inline]
fn from(e: Infallible) -> Self {
match e {}
}
@@ -18,6 +19,7 @@ fn from(e: Infallible) -> Self {
#[cfg(feature = "alloc")]
impl From<AllocError> for Error {
+ #[inline]
fn from(_: AllocError) -> Self {
Self
}
diff --git a/rust/pin-init/examples/pthread_mutex.rs b/rust/pin-init/examples/pthread_mutex.rs
index 4e082ec7d5de..aae3492d3958 100644
--- a/rust/pin-init/examples/pthread_mutex.rs
+++ b/rust/pin-init/examples/pthread_mutex.rs
@@ -49,6 +49,7 @@ pub enum Error {
}
impl From<Infallible> for Error {
+ #[inline]
fn from(e: Infallible) -> Self {
match e {}
}
@@ -56,6 +57,7 @@ fn from(e: Infallible) -> Self {
#[cfg(feature = "alloc")]
impl From<AllocError> for Error {
+ #[inline]
fn from(_: AllocError) -> Self {
Self::Alloc
}
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] 3+ messages in thread* Re: [PATCH] rust: Mark all from() for Error functions inline
2026-03-20 1:18 [PATCH] rust: Mark all from() for Error functions inline alistair23
@ 2026-03-20 2:55 ` Miguel Ojeda
2026-03-20 8:15 ` Benno Lossin
1 sibling, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2026-03-20 2:55 UTC (permalink / raw)
To: alistair23
Cc: linux-kernel, rust-for-linux, aliceryhl, ojeda, Alistair Francis
On Fri, Mar 20, 2026 at 2:19 AM <alistair23@gmail.com> wrote:
>
> rust/kernel/alloc/kvec/errors.rs | 3 +++
> rust/kernel/error.rs | 6 ++++++
> rust/kernel/ptr/projection.rs | 2 +-
> rust/kernel/xarray.rs | 1 +
> rust/pin-init/examples/error.rs | 2 ++
> rust/pin-init/examples/pthread_mutex.rs | 2 ++
> rust/syn/error.rs | 1 +
Please Cc all the relevant maintainers and reviewers using e.g.
`scripts/get_maintainer.pl`.
The commit log also should explain why we mark them as such. It also
doesn't say that one `inline(always)` was lowered to `inline` as well
and why that would be preferred (or not).
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] rust: Mark all from() for Error functions inline
2026-03-20 1:18 [PATCH] rust: Mark all from() for Error functions inline alistair23
2026-03-20 2:55 ` Miguel Ojeda
@ 2026-03-20 8:15 ` Benno Lossin
1 sibling, 0 replies; 3+ messages in thread
From: Benno Lossin @ 2026-03-20 8:15 UTC (permalink / raw)
To: alistair23, linux-kernel, rust-for-linux, aliceryhl, ojeda
Cc: Alistair Francis
On Fri Mar 20, 2026 at 2:18 AM CET, alistair23 wrote:
> From: Alistair Francis <alistair.francis@wdc.com>
>
> Mark all of the existing
>
> impl From<...> for Error {
> fn from(err: ...) -> Self {
> ...
> }
> }
>
> functions as `#[inline]`
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
> rust/kernel/alloc/kvec/errors.rs | 3 +++
> rust/kernel/error.rs | 6 ++++++
> rust/kernel/ptr/projection.rs | 2 +-
> rust/kernel/xarray.rs | 1 +
> rust/pin-init/examples/error.rs | 2 ++
> rust/pin-init/examples/pthread_mutex.rs | 2 ++
Please split the pin-init changes into a separate patch.
Also note that I prefer to take patches to pin-init upstream:
https://github.com/rust-for-linux/pin-init
I'm also open to picking it from the mailing list if you don't want to
go to GitHub.
Cheers,
Benno
> rust/syn/error.rs | 1 +
> 7 files changed, 16 insertions(+), 1 deletion(-)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-20 8:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-20 1:18 [PATCH] rust: Mark all from() for Error functions inline alistair23
2026-03-20 2:55 ` Miguel Ojeda
2026-03-20 8:15 ` Benno Lossin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox