Re: [PATCH] rust: print: add SAFETY comments to unsafe blocks
From: Shivendra Sharma
Date: Sun Mar 22 2026 - 02:29:29 EST
On Sun, Mar 22, 2026 at 8:40 AM Albab Hasan <albabhasan276@xxxxxxxxx> wrote:
>
> Thanks for pointing these out Miguel. I wasn't aware of the prior
> patches. Sorry for the
> duplicate. Happy to drop mine in favor of whichever version you prefer.
>
> Thanks,
> Albab
>
> On Sun, 22 Mar 2026 at 05:14, Miguel Ojeda
> <miguel.ojeda.sandonis@xxxxxxxxx> wrote:
> >
> > On Sat, Mar 21, 2026 at 3:34 PM Albab Hasan <albabhasan276@xxxxxxxxx> wrote:
> > >
> > > Replace the placeholder // SAFETY: TODO. comments with proper safety
> > > descriptions for the two unsafe blocks in rust_fmt_argument and
> > > call_printk.
> > >
> > > For rust_fmt_argument the ptr parameter is provided by the %pA
> > > format specifier handler in vsprintf that guarantees it points to a
> > > valid properly aligned fmt::Arguments<'_> value. since
> > > fmt::Arguments implements Copy the dereference is a bitwise
> > > copy with no side effects.
> > >
> > > For call_printk the safety depends on the functions documented
> > > preconditions the format string is one of the fixed compile time
> > > constants from format_strings and the module name is null terminated.
> > > the arguments match the format specifiers (%s for module name %pA
> > > for the fmt::Arguments pointer).
> > >
> > > Signed-off-by: Albab Hasan <albabhasan276@xxxxxxxxx>
> >
> > Did you see the following ones?
> >
> > https://lore.kernel.org/rust-for-linux/20260212125427.122362-1-alizainuimx@xxxxxxxxx/
> > https://lore.kernel.org/rust-for-linux/20260211182755.82220-1-shivendra02467@xxxxxxxxx/
> >
> > What is the relation with them? (Cc'ing their authors)
> >
> > Thanks!
> >
> > Link: https://github.com/Rust-for-Linux/linux/issues/351
> >
> > Cheers,
> > Miguel
Hi Albab,
Thank you for the kind response! It is incredibly easy to miss older
threads on the mailing list. I really appreciate you taking the time
to look into this and write up these safety requirements.
Hi Miguel,
Regarding the relation: the v2 patch I linked earlier targets the
exact same two TODOs in print.rs.
The v2 implements the generic wording Alice Ryhl suggested to ensure
the %pA guarantee covers all users. I also believe that v2 cleanly
resolves all the lints related to Issue #351 in print.rs.
That said, Albab did provide some great extra detail regarding the
call_printk invariants. If you prefer their more detailed wording for
that specific block over the v2 version, just let me know and I am
fully open to incorporating it!
Best regards,
Shivendra