mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next] rust: netlink: remove unnecessary bitfield transmutes
@ 2026-11-02  2:33 Thorsten Blum
  2026-11-09 23:30 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread

* Re: [PATCH net-next] rust: netlink: remove unnecessary bitfield transmutes
  2026-11-02  2:33 [PATCH net-next] rust: netlink: remove unnecessary bitfield transmutes Thorsten Blum
@ 2026-11-09 23:30 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-09 23:30 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: davem, edumazet, kuba, pabeni, horms, ojeda, boqun, gary,
	bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, dakr,
	daniel.almeida, tamird, acourbot, work, netdev, rust-for-linux,
	linux-kernel

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon,  2 Nov 2026 03:33:03 +0100 you wrote:
> 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>
> 
> [...]

Here is the summary with links:
  - [net-next] rust: netlink: remove unnecessary bitfield transmutes
    https://git.kernel.org/netdev/net-next/c/ce8659b5c8ac

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-09 23:30 UTC | newest]

Thread overview: 2+ messages (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
2026-11-09 23:30 ` patchwork-bot+netdevbpf

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®