diff options
| author | Gary Guo <gary@garyguo.net> | 2026-02-03 13:06:27 +0000 |
|---|---|---|
| committer | Miguel Ojeda <ojeda@kernel.org> | 2026-03-11 00:33:40 +0100 |
| commit | b3d161f22ba9b2dc16bb82aa2b8515d98c99624f (patch) | |
| tree | f1f721e472a021c4d073a1ad16f1b06126fc1f7c /rust/kernel/alloc/kvec/errors.rs | |
| parent | 1a933719e70787f462d6126230a403c15f95598e (diff) | |
rust: disallow use of `CStr::as_ptr` and `CStr::from_ptr`
As kernel always use unsigned char and not the platform ABI's default, an
user should always use `as_char_ptr` provided via `CStrExt` instead.
Therefore configure `disallow-methods` feature of clippy to catch incorrect
usage.
Similarly, the dual `from_ptr` is also disallowed.
[ 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 ]
Signed-off-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Tamir Duberstein <tamird@kernel.org>
Link: https://patch.msgid.link/20260203130745.868762-2-gary@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/kernel/alloc/kvec/errors.rs')
0 files changed, 0 insertions, 0 deletions
