Re: [PATCH] rust: iommu: replace core::mem::zeroed with pin_init::zeroed

From: Alexandre Courbot

Date: Sat Jun 27 2026 - 04:35:27 EST


On Sat Jun 27, 2026 at 5:31 AM JST, Nicolás Antinori wrote:
> All types in `bindings` implement `Zeroable` if they can. This enables
> using `pin_init::zeroed()` for `io_pgtable_cfg` initialization instead
> of relying on `..unsafe { core::mem::zeroed() }`.
>
> This change improves readability and removes an unnecessary unsafe
> block.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1189
> Suggested-by: Benno Lossin <lossin@xxxxxxxxxx>
> Signed-off-by: Nicolás Antinori <nico.antinori.7@xxxxxxxxx>
> ---
> rust/kernel/iommu/pgtable.rs | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/rust/kernel/iommu/pgtable.rs b/rust/kernel/iommu/pgtable.rs
> index c88e38fd938a..8faa1d8d9fad 100644
> --- a/rust/kernel/iommu/pgtable.rs
> +++ b/rust/kernel/iommu/pgtable.rs
> @@ -102,8 +102,7 @@ pub unsafe fn new_raw(dev: &Device<Bound>, config: Config) -> Result<IoPageTable
> coherent_walk: config.coherent_walk,
> tlb: &raw const NOOP_FLUSH_OPS,
> iommu_dev: dev.as_raw(),
> - // SAFETY: All zeroes is a valid value for `struct io_pgtable_cfg`.
> - ..unsafe { core::mem::zeroed() }
> + ..pin_init::zeroed()

Note that you can also use `..Zeroable::zeroed()` here since we are not
in const context. Not sure which one we prefer in this case, but I'd
personally err on the side of not referring to `pin_init` unless we are
dealing with a pinned object or need to because of a const requirement.