[PATCH 0/6] Replace `kernel::str::CStr` with `core::ffi::CStr` (cycle 1)

Tamir Duberstein posted 6 patches 3 months ago
drivers/cpufreq/rcpufreq_dt.rs    |  3 +-
drivers/gpu/nova-core/firmware.rs |  5 +-
rust/kernel/error.rs              |  8 ++--
rust/kernel/fmt.rs                |  7 +++
rust/kernel/lib.rs                |  1 +
rust/kernel/opp.rs                |  2 +-
rust/kernel/prelude.rs            |  2 +-
rust/kernel/print.rs              |  6 +--
rust/kernel/str.rs                | 97 ++++++++++++++++++++++++---------------
samples/rust/rust_print_main.rs   |  2 +-
10 files changed, 83 insertions(+), 50 deletions(-)
[PATCH 0/6] Replace `kernel::str::CStr` with `core::ffi::CStr` (cycle 1)
Posted by Tamir Duberstein 3 months ago
This series makes preparations for the replacement of our custom `CStr`
type with the analogous type available in `core`.

As this is a large migration that touches many subsystems, it will take
place in several cycles, each of which may see multiple series:
1. introduces facades in the kernel crate that downstream
   code can reference. [this series]
2. migrate downstream code to kernel crate facades. (N series, divided
   by subsystem).
3. replace kernel crate facades to allow `Display`ing foreign types
   (such as `core::ffi::CStr`). Replace `CStr` with `core::ffi::CStr`.
4. migrate uses of `c_str!` to C-String literals. Replace references to
   `kernel::str::CStr` with `kernel::ffi::CStr`. (N series, divided by
   subsystem).
5. rename `c_str!` to discourage use. Remove `CStr` reexport from
   `kernel/str.rs`.

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
Tamir Duberstein (6):
      rust: kernel: remove `fmt!`, fix clippy::uninlined-format-args
      rust: kernel: add `fmt` module
      rust: use `kernel::{fmt,prelude::fmt!}`
      rust: str: remove unnecessary qualification
      rust: add `CStr` methods matching `core::ffi::CStr`
      rust: use `core::ffi::CStr` method names

 drivers/cpufreq/rcpufreq_dt.rs    |  3 +-
 drivers/gpu/nova-core/firmware.rs |  5 +-
 rust/kernel/error.rs              |  8 ++--
 rust/kernel/fmt.rs                |  7 +++
 rust/kernel/lib.rs                |  1 +
 rust/kernel/opp.rs                |  2 +-
 rust/kernel/prelude.rs            |  2 +-
 rust/kernel/print.rs              |  6 +--
 rust/kernel/str.rs                | 97 ++++++++++++++++++++++++---------------
 samples/rust/rust_print_main.rs   |  2 +-
 10 files changed, 83 insertions(+), 50 deletions(-)
---
base-commit: 769e324b66b0d92d04f315d0c45a0f72737c7494
change-id: 20250704-core-cstr-prepare-9b9e6a7bd57e

Best regards,
--  
Tamir Duberstein <tamird@gmail.com>
Re: [PATCH 0/6] Replace `kernel::str::CStr` with `core::ffi::CStr` (cycle 1)
Posted by Miguel Ojeda 2 months, 2 weeks ago
On Fri, Jul 4, 2025 at 10:16 PM Tamir Duberstein <tamird@gmail.com> wrote:
>
> As this is a large migration that touches many subsystems, it will take
> place in several cycles, each of which may see multiple series:

Let's start the long road, then...

Applied to `rust-next` -- thanks everyone!

    [ Reworded title. - Miguel ]

    [ Reworded title. - Miguel ]

Cheers,
Miguel
Re: [PATCH 0/6] Replace `kernel::str::CStr` with `core::ffi::CStr` (cycle 1)
Posted by Alice Ryhl 2 months, 4 weeks ago
On Fri, Jul 4, 2025 at 10:16 PM Tamir Duberstein <tamird@gmail.com> wrote:
>
> This series makes preparations for the replacement of our custom `CStr`
> type with the analogous type available in `core`.
>
> As this is a large migration that touches many subsystems, it will take
> place in several cycles, each of which may see multiple series:
> 1. introduces facades in the kernel crate that downstream
>    code can reference. [this series]
> 2. migrate downstream code to kernel crate facades. (N series, divided
>    by subsystem).
> 3. replace kernel crate facades to allow `Display`ing foreign types
>    (such as `core::ffi::CStr`). Replace `CStr` with `core::ffi::CStr`.
> 4. migrate uses of `c_str!` to C-String literals. Replace references to
>    `kernel::str::CStr` with `kernel::ffi::CStr`. (N series, divided by
>    subsystem).
> 5. rename `c_str!` to discourage use. Remove `CStr` reexport from
>    `kernel/str.rs`.
>
> Signed-off-by: Tamir Duberstein <tamird@gmail.com>
> ---
> Tamir Duberstein (6):
>       rust: kernel: remove `fmt!`, fix clippy::uninlined-format-args
>       rust: kernel: add `fmt` module
>       rust: use `kernel::{fmt,prelude::fmt!}`
>       rust: str: remove unnecessary qualification
>       rust: add `CStr` methods matching `core::ffi::CStr`
>       rust: use `core::ffi::CStr` method names
>
>  drivers/cpufreq/rcpufreq_dt.rs    |  3 +-
>  drivers/gpu/nova-core/firmware.rs |  5 +-
>  rust/kernel/error.rs              |  8 ++--
>  rust/kernel/fmt.rs                |  7 +++
>  rust/kernel/lib.rs                |  1 +
>  rust/kernel/opp.rs                |  2 +-
>  rust/kernel/prelude.rs            |  2 +-
>  rust/kernel/print.rs              |  6 +--
>  rust/kernel/str.rs                | 97 ++++++++++++++++++++++++---------------
>  samples/rust/rust_print_main.rs   |  2 +-
>  10 files changed, 83 insertions(+), 50 deletions(-)
> ---
> base-commit: 769e324b66b0d92d04f315d0c45a0f72737c7494
> change-id: 20250704-core-cstr-prepare-9b9e6a7bd57e
>
> Best regards,
> --
> Tamir Duberstein <tamird@gmail.com>
>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>