Re: [PATCH v3 1/2] rust: task: use `as_char_ptr` instead of `as_ptr().cast()`
From: Miguel Ojeda
Date: Wed Mar 11 2026 - 01:45:48 EST
On Tue, Feb 3, 2026 at 2:08 PM Gary Guo <gary@xxxxxxxxxx> wrote:
>
> From: Gary Guo <gary@xxxxxxxxxxx>
>
> `as_char_ptr` would provide the correct (unsigned char) type without
> needing to convert to an intermediate type and cast the pointer.
>
> The `as_ptr()` function is going to be disallowed by clippy warning, so fix
> this usage.
>
> This is used only if CONFIG_DEBUG_ATOMIC_SLEEP=y. Instead of conditionally
> importing `CStrExt`, import it via prelude instead, and remove other
> imports that are already available via the prelude.
>
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
> Closes: https://lore.kernel.org/oe-kbuild-all/202601221157.89t3Sqbl-lkp@xxxxxxxxx/
> Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
Applied series to `rust-next` -- thanks everyone!
[ As an example, without the previous commit, we would get a warning like:
warning: use of a disallowed method `core::ffi::CStr::as_ptr`
--> rust/kernel/task.rs:422:54
|
422 | unsafe {
crate::bindings::__might_sleep(file.as_ptr().cast(), loc.line() as
i32) }
|
^^^^^^ help: kernel's `char` is always unsigned, use `as_char_ptr`
instead: `kernel::prelude::CStrExt::as_char_ptr`
|
= help: for further information visit
https://rust-lang.github.io/rust-clippy/rust-1.94.0/index.html#disallowed_methods
= note: `-W clippy::disallowed-methods` implied by `-W
clippy::all`
= help: to override `-W clippy::all` add
`#[allow(clippy::disallowed_methods)]`
- Miguel ]
Cheers,
Miguel