7 Commits
Author SHA1 Message Date
Danilo Krummrich 9b25d4111e rust: alloc: cleanup imports and use "kernel vertical" style
Change all imports in the alloc module to use the "kernel vertical"
import style [1].

While at it, drop unnecessary imports covered by prelude::*.

Link: https://docs.kernel.org/rust/coding-guidelines.html#imports [1]
Reviewed-by: Eliot Courtney <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-05-20 17:34:17 +02:00
Alistair Francis 4f13c93497 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 <[email protected]>
Link: https://lore.kernel.org/all/[email protected]/ [1]
Signed-off-by: Alistair Francis <[email protected]>
Acked-by: Danilo Krummrich <[email protected]>
Acked-by: Andreas Hindborg <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ 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 <[email protected]>
2026-03-27 12:49:00 +01:00
Tamir Duberstein b0af4f9142 rust: alloc: use kernel::fmt
Reduce coupling to implementation details of the formatting machinery by
avoiding direct use for `core`'s formatting traits and macros.

This backslid in commit 9def0d0a2a ("rust: alloc: add
Vec::push_within_capacity").

Reviewed-by: Alice Ryhl <[email protected]>
Acked-by: Danilo Krummrich <[email protected]>
Signed-off-by: Tamir Duberstein <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Miguel Ojeda <[email protected]>
2025-10-20 04:04:23 +02:00
Tamir Duberstein 1f96115f50 rust: alloc: use kernel::{fmt,prelude::fmt!}
Reduce coupling to implementation details of the formatting machinery by
avoiding direct use for `core`'s formatting traits and macros.

Acked-by: Greg Kroah-Hartman <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Reviewed-by: Benno Lossin <[email protected]>
Acked-by: Danilo Krummrich <[email protected]>
Signed-off-by: Tamir Duberstein <[email protected]>
Signed-off-by: Miguel Ojeda <[email protected]>
2025-09-16 09:26:58 +02:00
Alice Ryhl 771c5a7d98 rust: alloc: add Vec::insert_within_capacity
This adds a variant of Vec::insert that does not allocate memory. This
makes it safe to use this function while holding a spinlock. Rust Binder
uses it for the range allocator fast path.

Signed-off-by: Alice Ryhl <[email protected]>
Reviewed-by: Greg Kroah-Hartman <[email protected]>
Reviewed-by: Benno Lossin <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2025-05-07 18:40:45 +02:00
Alice Ryhl 294a7ecbdf rust: alloc: add Vec::remove
This is needed by Rust Binder in the range allocator, and by upcoming
GPU drivers during firmware initialization.

Panics in the kernel are best avoided when possible, so an error is
returned if the index is out of bounds. An error type is used rather
than just returning Option<T> to let callers handle errors with ?.

Signed-off-by: Alice Ryhl <[email protected]>
Reviewed-by: Greg Kroah-Hartman <[email protected]>
Reviewed-by: Benno Lossin <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[ Remove `# Panics` section; `Vec::remove() handles the error properly.`
  - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2025-05-07 18:40:02 +02:00
Alice Ryhl 9def0d0a2a rust: alloc: add Vec::push_within_capacity
This introduces a new method called `push_within_capacity` for appending
to a vector without attempting to allocate if the capacity is full. Rust
Binder will use this in various places to safely push to a vector while
holding a spinlock.

The implementation is moved to a push_within_capacity_unchecked method.
This is preferred over having push() call push_within_capacity()
followed by an unwrap_unchecked() for simpler unsafe.

Panics in the kernel are best avoided when possible, so an error is
returned if the vector does not have sufficient capacity. An error type
is used rather than just returning Result<(),T> to make it more
convenient for callers (i.e. they can use ? or unwrap).

Signed-off-by: Alice Ryhl <[email protected]>
Reviewed-by: Greg Kroah-Hartman <[email protected]>
Reviewed-by: Benno Lossin <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[ Remove public visibility from `Vec::push_within_capacity_unchecked()`.
  - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2025-05-07 18:39:01 +02:00