rust: document safety requirements for fmt::Arguments dereference
PATCH 1/1 rust: document safety requirements for fmt::Arguments dereference
From: Riccardo Adami <[email protected]>
This patch documents the safety requirements for dereferencing fmt::Arguments in the kernel's vsnprintf formatting path. This clarifies why it is safe to perform the unsafe dereference in rust_fmt_argument and helps future maintainers understand the invariants, reducing the risk of incorrect modifications.
--- rust/kernel/print.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
rust/kernel/print.rs +4 -4
@@ -25,10 +25,10 @@// SAFETY: The C contract guarantees that `buf` is valid if it's less than `end`. let mut w =unsafe {RawFormatter ::from_ptrs (buf.cast (), end.cast ()) };//SAFETY: `ptr` is provided by the kernel formatting path for the `%pA` -// specifier during `vsnprintf` processing and always points to a valid -// `fmt::Arguments` value created by the caller. The value lives at least -// for the duration of this call and is only read here. It is not stored -// or accessed after returning, so dereferencing it is safe. +// specifier during `vsnprintf` processing and always points to a valid +// `fmt::Arguments` value created by the caller. The value lives at least +// for the duration of this call and is only read here. It is not stored +// or accessed after returning, so dereferencing it is safe. let _ = w.write_fmt (unsafe { *ptr.cast ::<fmt::Arguments <'_>>() }); w.pos ().cast ()
Signature · 1 line
2.52.0
Quoted 34 lines · Riccardo
From: Riccardo Adami <[email protected]>
This patch documents the safety requirements for dereferencing
fmt::Argumentsin the kernel'svsnprintfformatting path. This clarifies why it is safe to perform the unsafe dereference inrust_fmt_argumentand helps future maintainers understand the invariants, reducing the risk of incorrect modifications.--- rust/kernel/print.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)rust/kernel/print.rs +4
-4@@ -25,10 +25,10 @@// SAFETY: The C contract guarantees that `buf` is valid if it's less than `end`. let mut w =unsafe {RawFormatter ::from_ptrs (buf.cast (), end.cast ()) };//SAFETY: `ptr` is provided by the kernel formatting path for the `%pA` -// specifier during `vsnprintf` processing and always points to a valid -// `fmt::Arguments` value created by the caller. The value lives at least -// for the duration of this call and is only read here. It is not stored -// or accessed after returning, so dereferencing it is safe. +// specifier during `vsnprintf` processing and always points to a valid +// `fmt::Arguments` value created by the caller. The value lives at least +// for the duration of this call and is only read here. It is not stored +// or accessed after returning, so dereferencing it is safe. let _ = w.write_fmt (unsafe { *ptr.cast ::<fmt::Arguments <'_>>() }); w.pos ().cast ()Signature · 1 line
2.52.0
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.
You are receiving this message because of the following common error(s) as indicated below:
- Your patch does not have a Signed-off-by: line. Please read the kernel file, Documentation/process/submitting-patches.rst and resend it after adding that line. Note, the line needs to be in the body of the email, before the patch, not at the bottom of the patch or in the email signature.
- This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/process/submitting-patches.rst for what needs to be done here to properly describe this.
If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.
thanks,
greg k-h's patch email bot