rust: net: netlink: Migrate to zerocopy's IntoBytes

Replace the kernel's own `transmute::FromBytes` and `AsBytes` traits
with their zerocopy equivalents. Specifically, this updates
`GenlMsg::put` to rely on `IntoBytes` for converting attributes into
byte slices.

Also, add `Immutable` trait bound on `GenlMsg::put` as zerocopy
splits the `no interior mutability` guarantee that `AsBytes` bundled
together.

Link: https://github.com/Rust-for-Linux/linux/issues/1241
Signed-off-by: Sagar Taunk <sagartaunk@proton.me>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20260915144231.31932-1-sagartaunk@proton.me
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Sagar Taunk authored and Jakub Kicinski committed 2026-09-17 17:05:15 -07:00
1 parent 7c6a3f0a84
commit 5e59169237
1 file changed
+6 -2
+6 -2
View File
@@ -12,7 +12,6 @@ use kernel::{
alloc::{self, AllocError},
error::to_result,
prelude::*,
transmute::AsBytes,
types::Opaque,
ThisModule,
};
@@ -22,6 +21,11 @@ use core::{
ptr::NonNull, //
};
use zerocopy::{
Immutable,
IntoBytes, //
};
/// The default netlink message size.
pub const GENLMSG_DEFAULT_SIZE: usize = bindings::GENLMSG_DEFAULT_SIZE;
@@ -84,7 +88,7 @@ impl GenlMsg {
#[inline]
fn put<T>(&mut self, attrtype: c_int, value: &T) -> Result
where
T: ?Sized + AsBytes,
T: ?Sized + IntoBytes + Immutable,
{
let skb = self.skb.skb.as_ptr();
let len = size_of_val(value);