mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-10-26 10:57:38 +08:00
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:
1 parent
7c6a3f0a84
commit
5e59169237
1 file changed
+6
-2
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user