Skip to contentSkip to conversation

rust/drm/gem: initialize callbacks with ..pin_init::zeroed()

PATCH Applied Klara Modin 2 participants 2 messages Sep 9 – Sep 10

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rust/drm/gem: initialize callbacks with ..pin_init::zeroed()

When the commit b67d2d039f64 ("drm/gem: Add callback for when handle count goes to 0") added the handle_free callback, it did not update the rust abstraction, which will cause a build failure when that is enabled. Rather than just adding another None initializer, use ..pin_init::zeroed() to make all unlisted callbacks None, and remove the existing zero-initializations.

---
v2:
- also remove initialization of vm_ops, which is also handled by ..pin_init::zeroed() (thanks Gary)
- fix the same issue in the shmem helper (thanks Thomas, also reported by Sashiko)
- v1: https://lore.kernel.org/lkml/[email protected]

---
 rust/kernel/drm/gem/mod.rs   | 13 +------------
 rust/kernel/drm/gem/shmem.rs |  5 +----
 2 files changed, 2 insertions(+), 16 deletions(-)
rust/kernel/drm/gem/mod.rs +1 -12
index 80d8f524f9d5..9d4280002765 100644
@@ -266,18 +266,7 @@ impl<T: DriverObject, Ctx: DeviceContext> Object<T, Ctx> {
         free: Some(Self::free_callback),
         open: Some(open_callback::<T>),
         close: Some(close_callback::<T>),
-        print_info: None,
-        export: None,
-        pin: None,
-        unpin: None,
-        get_sg_table: None,
-        vmap: None,
-        vunmap: None,
-        mmap: None,
-        status: None,
-        vm_ops: core::ptr::null_mut(),
-        evict: None,
-        rss: None,
+        ..pin_init::zeroed()
     };
 
     /// Returns the `Device` that owns this GEM object.
rust/kernel/drm/gem/shmem.rs +1 -4
index a687d46d170d..24cb5343e0db 100644
@@ -132,19 +132,16 @@ impl<T: DriverObject> Object<T> {
         open: Some(super::open_callback::<T>),
         close: Some(super::close_callback::<T>),
         print_info: Some(bindings::drm_gem_shmem_object_print_info),
-        export: None,
         pin: Some(bindings::drm_gem_shmem_object_pin),
         unpin: Some(bindings::drm_gem_shmem_object_unpin),
         get_sg_table: Some(bindings::drm_gem_shmem_object_get_sg_table),
         vmap: Some(bindings::drm_gem_shmem_object_vmap),
         vunmap: Some(bindings::drm_gem_shmem_object_vunmap),
         mmap: Some(bindings::drm_gem_shmem_object_mmap),
-        status: None,
-        rss: None,
         #[allow(unused_unsafe, reason = "Safe since Rust 1.82.0")]
         // SAFETY: `drm_gem_shmem_vm_ops` is a valid, static const on the C side.
         vm_ops: unsafe { &raw const bindings::drm_gem_shmem_vm_ops },
-        evict: None,
+        ..pin_init::zeroed()
     };
 
     /// Return a raw pointer to the embedded drm_gem_shmem_object.
Signature · 1 line
2.55.0
Applied
#1 lore raw

Applied. Thanks.

Alex

Quoted 79 lines · Klara Modin

When the commit b67d2d039f64 ("drm/gem: Add callback for when handle count goes to 0") added the handle_free callback, it did not update the rust abstraction, which will cause a build failure when that is enabled. Rather than just adding another None initializer, use ..pin_init::zeroed() to make all unlisted callbacks None, and remove the existing zero-initializations.

---
v2:
- also remove initialization of vm_ops, which is also handled by ..pin_init::zeroed() (thanks Gary)
- fix the same issue in the shmem helper (thanks Thomas, also reported by Sashiko)
- v1: https://lore.kernel.org/lkml/[email protected]

---
 rust/kernel/drm/gem/mod.rs   | 13 +------------
 rust/kernel/drm/gem/shmem.rs |  5 +----
 2 files changed, 2 insertions(+), 16 deletions(-)
rust/kernel/drm/gem/mod.rs +1 -12
index 80d8f524f9d5..9d4280002765 100644
@@ -266,18 +266,7 @@ impl<T: DriverObject, Ctx: DeviceContext> Object<T, Ctx> {
         free: Some(Self::free_callback),
         open: Some(open_callback::<T>),
         close: Some(close_callback::<T>),
-        print_info: None,
-        export: None,
-        pin: None,
-        unpin: None,
-        get_sg_table: None,
-        vmap: None,
-        vunmap: None,
-        mmap: None,
-        status: None,
-        vm_ops: core::ptr::null_mut(),
-        evict: None,
-        rss: None,
+        ..pin_init::zeroed()
     };
 
     /// Returns the `Device` that owns this GEM object.
rust/kernel/drm/gem/shmem.rs +1 -5
index a687d46d170d..24cb5343e0db 100644
@@ -132,19 +132,16 @@ impl<T: DriverObject> Object<T> {
         open: Some(super::open_callback::<T>),
         close: Some(super::close_callback::<T>),
         print_info: Some(bindings::drm_gem_shmem_object_print_info),
-        export: None,
         pin: Some(bindings::drm_gem_shmem_object_pin),
         unpin: Some(bindings::drm_gem_shmem_object_unpin),
         get_sg_table: Some(bindings::drm_gem_shmem_object_get_sg_table),
         vmap: Some(bindings::drm_gem_shmem_object_vmap),
         vunmap: Some(bindings::drm_gem_shmem_object_vunmap),
         mmap: Some(bindings::drm_gem_shmem_object_mmap),
-        status: None,
-        rss: None,
         #[allow(unused_unsafe, reason = "Safe since Rust 1.82.0")]
         // SAFETY: `drm_gem_shmem_vm_ops` is a valid, static const on the C side.
         vm_ops: unsafe { &raw const bindings::drm_gem_shmem_vm_ops },
-        evict: None,
+        ..pin_init::zeroed()
     };
 
     /// Return a raw pointer to the embedded drm_gem_shmem_object.
--

2.55.0