Skip to content

Commit 2dedf83

Browse files
author
Danilo Krummrich
committed
rust: dma: require mutable reference for as_slice_mut() and write()
Given the safety requirements of as_slice_mut() and write() taking an immutable reference is technically not incorrect. However, let's leverage the compiler's capabilities and require a mutable reference to ensure exclusive access. This also fixes a clippy warning introduced with 1.88: warning: mutable borrow from immutable input(s) --> rust/kernel/dma.rs:297:78 | 297 | pub unsafe fn as_slice_mut(&self, offset: usize, count: usize) -> Result<&mut [T]> { | ^^^^^^^^ Fixes: d37a39f ("rust: dma: add as_slice/write functions for CoherentAllocation") Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org> Reviewed-by: Abdiel Janulgue <abdiel.janulgue@gmail.com> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Link: https://lore.kernel.org/r/20250628165120.90149-1-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
1 parent c7e03c5 commit 2dedf83

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

rust/kernel/dma.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl<T: AsBytes + FromBytes> CoherentAllocation<T> {
294294
/// slice is live.
295295
/// * Callers must ensure that this call does not race with a read or write to the same region
296296
/// while the returned slice is live.
297-
pub unsafe fn as_slice_mut(&self, offset: usize, count: usize) -> Result<&mut [T]> {
297+
pub unsafe fn as_slice_mut(&mut self, offset: usize, count: usize) -> Result<&mut [T]> {
298298
self.validate_range(offset, count)?;
299299
// SAFETY:
300300
// - The pointer is valid due to type invariant on `CoherentAllocation`,
@@ -326,7 +326,7 @@ impl<T: AsBytes + FromBytes> CoherentAllocation<T> {
326326
/// unsafe { alloc.write(buf, 0)?; }
327327
/// # Ok::<(), Error>(()) }
328328
/// ```
329-
pub unsafe fn write(&self, src: &[T], offset: usize) -> Result {
329+
pub unsafe fn write(&mut self, src: &[T], offset: usize) -> Result {
330330
self.validate_range(offset, src.len())?;
331331
// SAFETY:
332332
// - The pointer is valid due to type invariant on `CoherentAllocation`

0 commit comments

Comments
 (0)