* [PATCH net-next] rust: netlink: remove unnecessary bitfield transmutes
@ 2026-11-02 2:33 Thorsten Blum
0 siblings, 0 replies; only message in thread
From: Thorsten Blum @ 2026-11-02 2:33 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan
Cc: Thorsten Blum, netdev, rust-for-linux, linux-kernel
Use __BindgenBitfieldUnit::new() to build the bitfield.
Since the generated type implements PartialEq, compare the bitfields
directly in test_family_flags_bitfield().
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
test_family_flags_bitfield() still passes.
rust/kernel/net/netlink.rs | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/rust/kernel/net/netlink.rs b/rust/kernel/net/netlink.rs
index 2f8733a694a9..d0c79a254f12 100644
--- a/rust/kernel/net/netlink.rs
+++ b/rust/kernel/net/netlink.rs
@@ -180,8 +180,7 @@ impl FamilyFlags {
}
// Convert from little endian to the target's endianness.
bits = u8::from_le(bits);
- // SAFETY: This bitfield is represented as an u8.
- unsafe { core::mem::transmute::<u8, bindings::__BindgenBitfieldUnit<[u8; 1]>>(bits) }
+ bindings::__BindgenBitfieldUnit::new([bits])
}
}
@@ -335,11 +334,7 @@ fn test_family_flags_bitfield() {
}
.into_bitfield();
- // SAFETY: The bit field is stored as u8.
- let b_val: u8 = unsafe { core::mem::transmute(b_fam._bitfield_1) };
- // SAFETY: The bit field is stored as u8.
- let c_val: u8 = unsafe { core::mem::transmute(c_bitfield) };
- assert_eq!(b_val, c_val);
+ assert_eq!(b_fam._bitfield_1, c_bitfield);
}
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-02 2:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 2:33 [PATCH net-next] rust: netlink: remove unnecessary bitfield transmutes Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®