mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +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},
|
alloc::{self, AllocError},
|
||||||
error::to_result,
|
error::to_result,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
transmute::AsBytes,
|
|
||||||
types::Opaque,
|
types::Opaque,
|
||||||
ThisModule,
|
ThisModule,
|
||||||
};
|
};
|
||||||
|
|
@ -22,6 +21,11 @@
|
||||||
ptr::NonNull, //
|
ptr::NonNull, //
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use zerocopy::{
|
||||||
|
Immutable,
|
||||||
|
IntoBytes, //
|
||||||
|
};
|
||||||
|
|
||||||
/// The default netlink message size.
|
/// The default netlink message size.
|
||||||
pub const GENLMSG_DEFAULT_SIZE: usize = bindings::GENLMSG_DEFAULT_SIZE;
|
pub const GENLMSG_DEFAULT_SIZE: usize = bindings::GENLMSG_DEFAULT_SIZE;
|
||||||
|
|
||||||
|
|
@ -84,7 +88,7 @@ impl GenlMsg {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn put<T>(&mut self, attrtype: c_int, value: &T) -> Result
|
fn put<T>(&mut self, attrtype: c_int, value: &T) -> Result
|
||||||
where
|
where
|
||||||
T: ?Sized + AsBytes,
|
T: ?Sized + IntoBytes + Immutable,
|
||||||
{
|
{
|
||||||
let skb = self.skb.skb.as_ptr();
|
let skb = self.skb.skb.as_ptr();
|
||||||
let len = size_of_val(value);
|
let len = size_of_val(value);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user