Replace explicit imports of `transmute::FromBytes`/`AsBytes` with zerocopy's equivalents. Link: https://github.com/Rust-for-Linux/linux/issues/1241 Signed-off-by: Sagar Taunk --- rust/kernel/dma.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs index 2ce09f8e90c6..9bd47f20c784 100644 --- a/rust/kernel/dma.rs +++ b/rust/kernel/dma.rs @@ -25,10 +25,6 @@ prelude::*, ptr::KnownSize, sync::aref::ARef, - transmute::{ - AsBytes, - FromBytes, // - }, uaccess::UserSliceWriter, // }; use core::{ @@ -417,7 +413,7 @@ fn from(direction: DataDirection) -> Self { /// ``` pub struct CoherentBox(Coherent); -impl CoherentBox<[T]> { +impl CoherentBox<[T]> { /// [`CoherentBox`] variant of [`Coherent::zeroed_slice_with_attrs`]. #[inline] pub fn zeroed_slice_with_attrs( @@ -454,7 +450,7 @@ pub fn init_at(&mut self, i: usize, init: impl Init) -> Result // SAFETY: // - `ptr` is valid, properly aligned, and within this allocation. - // - `T: AsBytes + FromBytes` guarantees all bit patterns are valid, so partial writes on + // - `T: IntoBytes + FromBytes` guarantees all bit patterns are valid, so partial writes on // error cannot leave the element in an invalid state. // - The DMA address has not been exposed yet, so there is no concurrent device access. unsafe { pin_init::raw_try_init(ptr, init)? }; @@ -523,7 +519,7 @@ pub fn from_slice( } } -impl CoherentBox { +impl CoherentBox { /// Same as [`CoherentBox::zeroed_slice_with_attrs`], but for a single element. #[inline] pub fn zeroed_with_attrs( @@ -554,7 +550,7 @@ fn deref(&self) -> &Self::Target { } } -impl DerefMut for CoherentBox { +impl DerefMut for CoherentBox { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { // SAFETY: @@ -565,7 +561,7 @@ fn deref_mut(&mut self) -> &mut Self::Target { } } -impl From> for Coherent { +impl From> for Coherent { #[inline] fn from(value: CoherentBox) -> Self { value.0 @@ -663,7 +659,7 @@ pub unsafe fn as_mut(&self) -> &mut T { } } -impl Coherent { +impl Coherent { /// Allocates a region of `T` of coherent memory. fn alloc_with_attrs( dev: &device::Device, @@ -753,7 +749,7 @@ pub fn init_with_attrs( // SAFETY: // - `ptr` is valid, properly aligned, and points to exclusively owned memory. // - If `raw_try_init` fails, `self` is dropped, which safely frees the underlying - // `Coherent`'s DMA memory. `T: AsBytes + FromBytes` ensures there are no complex `Drop` + // `Coherent`'s DMA memory. `T: IntoBytes + FromBytes` ensures there are no complex `Drop` // requirements we are bypassing. unsafe { pin_init::raw_try_init(ptr, init)? }; @@ -948,9 +944,9 @@ unsafe impl Send for Coherent {} // methods that access the buffer contents (`field_read`, `field_write`, `as_slice`, // `as_slice_mut`) are `unsafe`, and callers are responsible for ensuring no data races occur. // The safe methods only return metadata or raw pointers whose use requires `unsafe`. -unsafe impl Sync for Coherent {} +unsafe impl Sync for Coherent {} -impl debugfs::BinaryWriter for Coherent { +impl debugfs::BinaryWriter for Coherent { fn write_to_slice( &self, writer: &mut UserSliceWriter, -- 2.55.0