mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01: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:
parent
7c6a3f0a84
commit
5e59169237
|
|
@ -12,7 +12,6 @@
|
|||
alloc::{self, AllocError},
|
||||
error::to_result,
|
||||
prelude::*,
|
||||
transmute::AsBytes,
|
||||
types::Opaque,
|
||||
ThisModule,
|
||||
};
|
||||
|
|
@ -22,6 +21,11 @@
|
|||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user