Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: dma: make use of start_ptr() and start_ptr_mut()

Using start_ptr() and start_ptr_mut() has the advantage that we inherit
the requirements the a mutable or immutable reference from those
methods.

Hence, use them instead of self.cpu_addr.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20251103190655.2326191-1-dakr@kernel.org
[ Keep using self.cpu_addr in item_from_index(). - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

+8 -4
+8 -4
rust/kernel/dma.rs
··· 505 505 // data is also guaranteed by the safety requirements of the function. 506 506 // - `offset + count` can't overflow since it is smaller than `self.count` and we've checked 507 507 // that `self.count` won't overflow early in the constructor. 508 - Ok(unsafe { core::slice::from_raw_parts(self.cpu_addr.add(offset), count) }) 508 + Ok(unsafe { core::slice::from_raw_parts(self.start_ptr().add(offset), count) }) 509 509 } 510 510 511 511 /// Performs the same functionality as [`CoherentAllocation::as_slice`], except that a mutable ··· 525 525 // data is also guaranteed by the safety requirements of the function. 526 526 // - `offset + count` can't overflow since it is smaller than `self.count` and we've checked 527 527 // that `self.count` won't overflow early in the constructor. 528 - Ok(unsafe { core::slice::from_raw_parts_mut(self.cpu_addr.add(offset), count) }) 528 + Ok(unsafe { core::slice::from_raw_parts_mut(self.start_ptr_mut().add(offset), count) }) 529 529 } 530 530 531 531 /// Writes data to the region starting from `offset`. `offset` is in units of `T`, not the ··· 557 557 // - `offset + count` can't overflow since it is smaller than `self.count` and we've checked 558 558 // that `self.count` won't overflow early in the constructor. 559 559 unsafe { 560 - core::ptr::copy_nonoverlapping(src.as_ptr(), self.cpu_addr.add(offset), src.len()) 560 + core::ptr::copy_nonoverlapping( 561 + src.as_ptr(), 562 + self.start_ptr_mut().add(offset), 563 + src.len(), 564 + ) 561 565 }; 562 566 Ok(()) 563 567 } ··· 641 637 bindings::dma_free_attrs( 642 638 self.dev.as_raw(), 643 639 size, 644 - self.cpu_addr.cast(), 640 + self.start_ptr_mut().cast(), 645 641 self.dma_handle, 646 642 self.dma_attrs.as_raw(), 647 643 )