Skip to contentSkip to conversation

rust: cpumask: Mark CpumaskVar as transparent

PATCH Applied Baptiste Lepers 3 participants 3 messages Aug 12, 2025 – Aug 14, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: cpumask: Mark CpumaskVar as transparent

Unsafe code in CpumaskVar's methods assumes that the type has the same layout as bindings::cpumask_var_t. This is not guaranteed by the default struct representation in Rust, but requires specifying the transparent representation.

Fixes 8961b8cb3099a ("rust: cpumask: Add initial abstractions")
---
 rust/kernel/cpumask.rs | 1 +
 1 file changed, 1 insertion(+)
rust/kernel/cpumask.rs +1 -0
index 3fcbff438670..05e1c882404e 100644
@@ -212,6 +212,7 @@ pub fn copy(&self, dstp: &mut Self) {
 /// }
 /// assert_eq!(mask2.weight(), count);
 /// ```
+#[repr(transparent)]
 pub struct CpumaskVar {
     #[cfg(CONFIG_CPUMASK_OFFSTACK)]
     ptr: NonNull<Cpumask>,
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Baptiste Lepers

Unsafe code in CpumaskVar's methods assumes that the type has the same layout as bindings::cpumask_var_t. This is not guaranteed by the default struct representation in Rust, but requires specifying the transparent representation.

Fixes 8961b8cb3099a ("rust: cpumask: Add initial abstractions")

Only during CONFIG_CPUMASK_OFFSTACK=n, but yes.

maintainer Applied
#2 lore raw
In reply to Baptiste Lepers
Quoted 11 lines · Baptiste Lepers

Unsafe code in CpumaskVar's methods assumes that the type has the same layout as bindings::cpumask_var_t. This is not guaranteed by the default struct representation in Rust, but requires specifying the transparent representation.

Fixes 8961b8cb3099a ("rust: cpumask: Add initial abstractions")
---
 rust/kernel/cpumask.rs | 1 +
 1 file changed, 1 insertion(+)

Applied. Thanks.

Signature · 1 line
viresh