public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] rust: task: use `as_char_ptr` instead of `as_ptr().cast()`
@ 2026-01-22 14:44 Gary Guo
  2026-01-22 14:44 ` [PATCH v2 2/2] rust: disallow use of `CStr::as_ptr` Gary Guo
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Gary Guo @ 2026-01-22 14:44 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Panagiotis Foliadis, Shankari Anand,
	FUJITA Tomonori
  Cc: kernel test robot, rust-for-linux, linux-kernel

From: Gary Guo <gary@garyguo.net>

`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.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202601221157.89t3Sqbl-lkp@intel.com/
Signed-off-by: Gary Guo <gary@garyguo.net>
---
 rust/kernel/task.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
index cc907fb531bc..7ccb20a8f813 100644
--- a/rust/kernel/task.rs
+++ b/rust/kernel/task.rs
@@ -9,6 +9,7 @@
     ffi::{c_int, c_long, c_uint},
     mm::MmWithUser,
     pid_namespace::PidNamespace,
+    str::CStrExt,
     sync::aref::ARef,
     types::{NotThreadSafe, Opaque},
 };
@@ -419,7 +420,7 @@ pub fn might_sleep() {
         let file = kernel::file_from_location(loc);
 
         // SAFETY: `file.as_ptr()` is valid for reading and guaranteed to be nul-terminated.
-        unsafe { crate::bindings::__might_sleep(file.as_ptr().cast(), loc.line() as i32) }
+        unsafe { crate::bindings::__might_sleep(file.as_char_ptr(), loc.line() as i32) }
     }
 
     // SAFETY: Always safe to call.

base-commit: 053966c344dbd346e71305f530e91ea77916189f
-- 
2.51.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-01-26 12:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-22 14:44 [PATCH v2 1/2] rust: task: use `as_char_ptr` instead of `as_ptr().cast()` Gary Guo
2026-01-22 14:44 ` [PATCH v2 2/2] rust: disallow use of `CStr::as_ptr` Gary Guo
2026-01-22 14:48 ` [PATCH v2 1/2] rust: task: use `as_char_ptr` instead of `as_ptr().cast()` Gary Guo
2026-01-22 22:33   ` Tamir Duberstein
2026-01-24 23:33 ` kernel test robot
2026-01-25 20:19   ` Tamir Duberstein
2026-01-26  9:22     ` Alice Ryhl
2026-01-26 12:25       ` Gary Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox