🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Thorsten Blum Mon, 02 Nov 2026 02:33
[PATCH net-next] rust: netlink: remove unnecessary bitfield transmutes
#9442
Author: Thorsten Blum
Date: Mon, 02 Nov 2026 02:33
40 lines
9340 bytes
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);
             }
         }
     }
Re: [PATCH net-next] rust: netlink: remove unnecessary bitfield transmutes
#13496
Author: patchwork-bot+netdevbpf
Date: Mon, 09 Nov 2026 23:30
24 lines
8773 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads