Unbinding happens on pinned data, but some of our methods still take
mutable references. Right now we can rely on the fact that `Gpu` is
`Unpin` to get a mutable reference to its members, but this is going to
change when e.g. mutexes are introduced.

Take advantage of the `project` method of pin-init to obtain
pin-projected data, and update our methods signature to work with pinned
data when relevant.

Signed-off-by: Alexandre Courbot <[email protected]>
---
 drivers/gpu/nova-core/driver.rs | 4 ++--
 drivers/gpu/nova-core/gpu.rs    | 8 +++++---
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs
index b0e3e41ae9d8..c53e96173890 100644
--- a/drivers/gpu/nova-core/driver.rs
+++ b/drivers/gpu/nova-core/driver.rs
@@ -98,7 +98,7 @@ fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> 
impl PinInit<Self, E
         })
     }
 
-    fn unbind(pdev: &pci::Device<Core>, this: Pin<KBox<Self>>) {
-        this.gpu.unbind(pdev.as_ref());
+    fn unbind(pdev: &pci::Device<Core>, mut this: Pin<KBox<Self>>) {
+        this.as_mut().project().gpu.unbind(pdev.as_ref());
     }
 }
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index e16d3c2a6b38..ef6ceced350e 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -292,11 +292,13 @@ pub(crate) fn new<'a>(
     /// Called when the corresponding [`Device`](device::Device) is unbound.
     ///
     /// Note: This method must only be called from `Driver::unbind`.
-    pub(crate) fn unbind(&self, dev: &device::Device<device::Core>) {
-        let Ok(bar) = kernel::warn_on_err!(self.bar.access(dev)) else {
+    pub(crate) fn unbind(self: Pin<&mut Self>, dev: 
&device::Device<device::Core>) {
+        let this = self.project();
+
+        let Ok(bar) = kernel::warn_on_err!(this.bar.access(dev)) else {
             return;
         };
 
-        self.sysmem_flush.unregister(bar);
+        this.sysmem_flush.unregister(bar);
     }
 }

-- 
2.52.0

Reply via email to