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

gpu: nova-core: Simplify `DmaObject::from_data` in nova-core/dma.rs

This patch solves one of the existing mentions of COHA, a task
in the Nova task list about improving the `CoherentAllocation` API.
It uses the `write` method from `CoherentAllocation`.

Signed-off-by: Daniel del Castillo <delcastillodelarosadaniel@gmail.com>
[acourbot@nvidia.com: set prefix to "gpu: nova-core:".]
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Message-ID: <20251104193756.57726-3-delcastillodelarosadaniel@gmail.com>

authored by

Daniel del Castillo and committed by
Alexandre Courbot
3577e265 571ce401

+5 -14
+5 -14
drivers/gpu/nova-core/dma.rs
··· 30 30 } 31 31 32 32 pub(crate) fn from_data(dev: &device::Device<device::Bound>, data: &[u8]) -> Result<Self> { 33 - Self::new(dev, data.len()).map(|mut dma_obj| { 34 - // TODO[COHA]: replace with `CoherentAllocation::write()` once available. 35 - // SAFETY: 36 - // - `dma_obj`'s size is at least `data.len()`. 37 - // - We have just created this object and there is no other user at this stage. 38 - unsafe { 39 - core::ptr::copy_nonoverlapping( 40 - data.as_ptr(), 41 - dma_obj.dma.start_ptr_mut(), 42 - data.len(), 43 - ); 44 - } 45 - 46 - dma_obj 33 + Self::new(dev, data.len()).and_then(|mut dma_obj| { 34 + // SAFETY: We have just allocated the DMA memory, we are the only users and 35 + // we haven't made the device aware of the handle yet. 36 + unsafe { dma_obj.write(data, 0)? } 37 + Ok(dma_obj) 47 38 }) 48 39 } 49 40 }