* [PATCH] rust: print: Document SAFETY invariants in rust_fmt_argument and call_printk
[not found] <20260212125427.122362-1-alizainuimx@gmail.com>
@ 2026-02-13 5:31 ` Ali Zain
2026-02-16 20:31 ` Miguel Ojeda
0 siblings, 1 reply; 2+ messages in thread
From: Ali Zain @ 2026-02-13 5:31 UTC (permalink / raw)
To: rust-for-linux
Cc: linux-kernel, ojeda, boqun.feng, gary, bjorn3_gh, lossin,
a.hindborg, aliceryhl, tmgross, dakr, Ali Zain
Replace remaining "SAFETY: TODO" comments with proper explanations.
Document why the raw pointer cast to `fmt::Arguments` is valid
and clarify the invariants required when calling `_printk`
through FFI.
This does not change behaviour.
v2:
- Fix rustfmt formatting issue reported by 0-day CI.
- Remove extra blank line before unsafe block.
Signed-off-by: Ali Zain <alizainuimx@gmail.com>
---
rust/kernel/list.rs | 2 ++
rust/kernel/print.rs | 1 -
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/rust/kernel/list.rs b/rust/kernel/list.rs
index 0d8a201f2..65d33957e 100644
--- a/rust/kernel/list.rs
+++ b/rust/kernel/list.rs
@@ -589,6 +589,8 @@ pub unsafe fn remove(&mut self, item: &T) -> Option<ListArc<T, ID>> {
// or in this list (with the same `ID`).
// - We hold `&mut self`, so there is no concurrent mutation of
// the link fields.
+ // - `T::view_links(item)` returns the embedded link fields for this
+ // object, which remain valid for the lifetime of `item`.
let mut item = unsafe { ListLinks::fields(T::view_links(item)) };
// SAFETY: The user provided a reference, and reference are never dangling.
diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs
index 2ae7b4ce9..c3edc0ab3 100644
--- a/rust/kernel/print.rs
+++ b/rust/kernel/print.rs
@@ -112,7 +112,6 @@ pub unsafe fn call_printk(
// at compile time, a null-terminated module name, and a pointer to
// `fmt::Arguments` obtained via `core::ptr::from_ref`. All pointers
// are valid for the duration of the call and respect the C ABI.
-
unsafe {
bindings::_printk(
format_string.as_ptr(),
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] rust: print: Document SAFETY invariants in rust_fmt_argument and call_printk
2026-02-13 5:31 ` [PATCH] rust: print: Document SAFETY invariants in rust_fmt_argument and call_printk Ali Zain
@ 2026-02-16 20:31 ` Miguel Ojeda
0 siblings, 0 replies; 2+ messages in thread
From: Miguel Ojeda @ 2026-02-16 20:31 UTC (permalink / raw)
To: Ali Zain
Cc: rust-for-linux, linux-kernel, ojeda, boqun.feng, gary, bjorn3_gh,
lossin, a.hindborg, aliceryhl, tmgross, dakr
On Fri, Feb 13, 2026 at 6:31 AM Ali Zain <alizainuimx@gmail.com> wrote:
>
> Replace remaining "SAFETY: TODO" comments with proper explanations.
>
> Document why the raw pointer cast to `fmt::Arguments` is valid
> and clarify the invariants required when calling `_printk`
> through FFI.
>
> This does not change behaviour.
>
> v2:
> - Fix rustfmt formatting issue reported by 0-day CI.
> - Remove extra blank line before unsafe block.
>
> Signed-off-by: Ali Zain <alizainuimx@gmail.com>
Since this is meant to be v2, please mark your patch as v2 using flags
like `git format-patch -v2`.
What is the base for this patch, by the way?
Also, you included the changelog within the commit message -- they
usually go after the first `---` line, so that it is not included.
There is also an unrelated change in `print.rs`.
I hope that helps.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-16 20:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20260212125427.122362-1-alizainuimx@gmail.com>
2026-02-13 5:31 ` [PATCH] rust: print: Document SAFETY invariants in rust_fmt_argument and call_printk Ali Zain
2026-02-16 20:31 ` Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®