Re: Printing with overflow checks can cause modpost errors
From: Timur Tabi
Date: Wed Sep 17 2025 - 19:19:49 EST
On Tue, 2025-09-16 at 14:52 -0400, Joel Fernandes wrote:
> From: Joel Fernandes <joelagnelf@xxxxxxxxxx>
> Subject: [PATCH] rust: print: Fix issue with rust_build_error
>
> When printing just before calling io.write32(), modpost fails. The issue
> seems to be that, the printk arguments are used in an unsafe block, thus Rust
> cannot trust its value. This can be fixed by simply creating a variable alias
> for each variable.
>
> Fix it in an even simpler way by just call printk in a closure. Rust captures
> the arguments into the closure's arguments thus breaking the dependencies.
> Tested with the following snippet and it builds with patch:
>
> let offset = 0;
> pr_err!("{}", offset);
> io.write32(base, offset);
>
> Signed-off-by: Joel Fernandes <joelagnelf@xxxxxxxxxx>
Tested-by: Timur Tabi <ttabi@xxxxxxxxxx>
This fixes an issue I had with pr_err!() and io.write32() and causing rust_build_error.