Skip to content

Commit 4f13c93

Browse files
alistair23ojeda
authored andcommitted
rust: kernel: mark as #[inline] all From::from()s for Error
There was a recent request [1] to mark as `#[inline]` the simple `From::from()` functions implemented for `Error`. Thus mark all of the existing impl From<...> for Error { fn from(err: ...) -> Self { ... } } functions in the `kernel` crate as `#[inline]`. Suggested-by: Gary Guo <gary@garyguo.net> Link: https://lore.kernel.org/all/8403c8b7a832b5274743816eb77abfa4@garyguo.net/ [1] Signed-off-by: Alistair Francis <alistair.francis@wdc.com> Acked-by: Danilo Krummrich <dakr@kernel.org> Acked-by: Andreas Hindborg <a.hindborg@kernel.org> Link: https://patch.msgid.link/20260326020406.1438210-1-alistair.francis@wdc.com [ Dropped `projection.rs` since it is in another tree and already marked as `inline(always)` and reworded accordingly. Changed Link tag to Gary's original message and added Suggested-by. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent d58f0f1 commit 4f13c93

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

rust/kernel/alloc/kvec/errors.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impl<T> fmt::Debug for PushError<T> {
1515
}
1616

1717
impl<T> From<PushError<T>> for Error {
18+
#[inline]
1819
fn from(_: PushError<T>) -> Error {
1920
// Returning ENOMEM isn't appropriate because the system is not out of memory. The vector
2021
// is just full and we are refusing to resize it.
@@ -32,6 +33,7 @@ impl fmt::Debug for RemoveError {
3233
}
3334

3435
impl From<RemoveError> for Error {
36+
#[inline]
3537
fn from(_: RemoveError) -> Error {
3638
EINVAL
3739
}
@@ -55,6 +57,7 @@ impl<T> fmt::Debug for InsertError<T> {
5557
}
5658

5759
impl<T> From<InsertError<T>> for Error {
60+
#[inline]
5861
fn from(_: InsertError<T>) -> Error {
5962
EINVAL
6063
}

rust/kernel/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,36 +216,42 @@ impl fmt::Debug for Error {
216216
}
217217

218218
impl From<AllocError> for Error {
219+
#[inline]
219220
fn from(_: AllocError) -> Error {
220221
code::ENOMEM
221222
}
222223
}
223224

224225
impl From<TryFromIntError> for Error {
226+
#[inline]
225227
fn from(_: TryFromIntError) -> Error {
226228
code::EINVAL
227229
}
228230
}
229231

230232
impl From<Utf8Error> for Error {
233+
#[inline]
231234
fn from(_: Utf8Error) -> Error {
232235
code::EINVAL
233236
}
234237
}
235238

236239
impl From<LayoutError> for Error {
240+
#[inline]
237241
fn from(_: LayoutError) -> Error {
238242
code::ENOMEM
239243
}
240244
}
241245

242246
impl From<fmt::Error> for Error {
247+
#[inline]
243248
fn from(_: fmt::Error) -> Error {
244249
code::EINVAL
245250
}
246251
}
247252

248253
impl From<core::convert::Infallible> for Error {
254+
#[inline]
249255
fn from(e: core::convert::Infallible) -> Error {
250256
match e {}
251257
}

rust/kernel/xarray.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ pub struct StoreError<T> {
172172
}
173173

174174
impl<T> From<StoreError<T>> for Error {
175+
#[inline]
175176
fn from(value: StoreError<T>) -> Self {
176177
value.error
177178
}

0 commit comments

Comments
 (0)