]> Gentwo Git Trees - linux/.git/commitdiff
gpu: nova-core: Simplify `DmaObject::from_data` in nova-core/dma.rs
authorDaniel del Castillo <delcastillodelarosadaniel@gmail.com>
Tue, 4 Nov 2025 19:37:50 +0000 (20:37 +0100)
committerAlexandre Courbot <acourbot@nvidia.com>
Fri, 7 Nov 2025 14:10:44 +0000 (23:10 +0900)
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>

drivers/gpu/nova-core/dma.rs

index 5b117aefdb15f51b8567a8d50a7f6f80d88297ee..7215398969da6e88e85711961f63c8154c00c9a0 100644 (file)
@@ -30,20 +30,11 @@ pub(crate) fn new(dev: &device::Device<device::Bound>, len: usize) -> Result<Sel
     }
 
     pub(crate) fn from_data(dev: &device::Device<device::Bound>, data: &[u8]) -> Result<Self> {
-        Self::new(dev, data.len()).map(|mut dma_obj| {
-            // TODO[COHA]: replace with `CoherentAllocation::write()` once available.
-            // SAFETY:
-            // - `dma_obj`'s size is at least `data.len()`.
-            // - We have just created this object and there is no other user at this stage.
-            unsafe {
-                core::ptr::copy_nonoverlapping(
-                    data.as_ptr(),
-                    dma_obj.dma.start_ptr_mut(),
-                    data.len(),
-                );
-            }
-
-            dma_obj
+        Self::new(dev, data.len()).and_then(|mut dma_obj| {
+            // SAFETY: We have just allocated the DMA memory, we are the only users and
+            // we haven't made the device aware of the handle yet.
+            unsafe { dma_obj.write(data, 0)? }
+            Ok(dma_obj)
         })
     }
 }