Skip to contentSkip to conversation

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

PATCH Superseded Klara Modin 5 participants 9 messages Sep 8 – Sep 9

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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 None-initializations.

Fixes b67d2d039f64 ("drm/gem: Add callback for when handle count goes to 0")
---
 rust/kernel/drm/gem/mod.rs | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
rust/kernel/drm/gem/mod.rs +1 -11
index 80d8f524f9d5..af8274134a71 100644
@@ -266,18 +266,8 @@ 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.
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Incomplete fix: missing `handle_free` field in conditionally compiled `shmem.rs`. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Incomplete fix: missing handle_free field in conditionally compiled shmem.rs. --

commit b5b83bb373847c99ca6d286c268d2e0ffab299f0
Author: Klara Modin <[email protected]>

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

This commit updates the drm_gem_object_funcs struct initialization in the DRM GEM module to use pin_init::zeroed() instead of explicitly assigning None to unused callbacks. This fixes a build failure caused by a newly added callback field in the C structure.

Quoted 12 lines
rust/kernel/drm/gem/mod.rs +0 -4
index e1ebad77ebe2a..c63b0fe5a15e1 100644
@@ -266,18 +266,8 @@ 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,

rust/kernel/drm/gem/mod.rs impl<T: DriverObject, Ctx: DeviceContext> Object<T, Ctx> { · line 271

Quoted 10 lines
rust/kernel/drm/gem/mod.rs +1 -7
-        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()
     };

[Severity: Medium]
Does this commit miss a similar update in rust/kernel/drm/gem/shmem.rs?

The VTABLE initialization in shmem.rs explicitly lists fields without using pin_init::zeroed(), similar to what was fixed here. When compiling with CONFIG_RUST_DRM_GEM_SHMEM_HELPER=y, won't this cause a missing field error for the newly added handle_free callback?

rust/kernel/drm/gem/shmem.rs:

    const VTABLE: bindings::drm_gem_object_funcs = bindings::drm_gem_object_funcs {
        free: Some(Self::free_callback),
        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,
    };
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
Quoted 42 lines · On 2026-09-08 18:05:54 +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Incomplete fix: missing handle_free field in conditionally compiled shmem.rs. --

commit b5b83bb373847c99ca6d286c268d2e0ffab299f0
Author: Klara Modin <[email protected]>

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

This commit updates the drm_gem_object_funcs struct initialization in the DRM GEM module to use pin_init::zeroed() instead of explicitly assigning None to unused callbacks. This fixes a build failure caused by a newly added callback field in the C structure.

Quoted 12 lines
rust/kernel/drm/gem/mod.rs +0 -4
index e1ebad77ebe2a..c63b0fe5a15e1 100644
@@ -266,18 +266,8 @@ 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,

rust/kernel/drm/gem/mod.rs impl<T: DriverObject, Ctx: DeviceContext> Object<T, Ctx> { · line 271

Quoted 10 lines
rust/kernel/drm/gem/mod.rs +1 -7
-        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()
     };

[Severity: Medium]-
Does this commit miss a similar update in rust/kernel/drm/gem/shmem.rs?

Quoted 4 lines

The VTABLE initialization in shmem.rs explicitly lists fields without using pin_init::zeroed(), similar to what was fixed here. When compiling with CONFIG_RUST_DRM_GEM_SHMEM_HELPER=y, won't this cause a missing field error for the newly added handle_free callback?

Sure, but it should probably be a different patch in that case. The current patch fixes an issue to a currently existing build failure, while the issue mentioned here has not manifested yet.

Regards,
Klara Modin

Quoted 24 lines

rust/kernel/drm/gem/shmem.rs:

    const VTABLE: bindings::drm_gem_object_funcs = bindings::drm_gem_object_funcs {
        free: Some(Self::free_callback),
        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,
    };
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw
Quoted 43 lines · Klara Modin
Quoted 42 lines · On 2026-09-08 18:05:54 +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Incomplete fix: missing handle_free field in conditionally compiled shmem.rs. --

commit b5b83bb373847c99ca6d286c268d2e0ffab299f0
Author: Klara Modin <[email protected]>

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

This commit updates the drm_gem_object_funcs struct initialization in the DRM GEM module to use pin_init::zeroed() instead of explicitly assigning None to unused callbacks. This fixes a build failure caused by a newly added callback field in the C structure.

Quoted 12 lines
rust/kernel/drm/gem/mod.rs +0 -4
index e1ebad77ebe2a..c63b0fe5a15e1 100644
@@ -266,18 +266,8 @@ 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,

rust/kernel/drm/gem/mod.rs impl<T: DriverObject, Ctx: DeviceContext> Object<T, Ctx> { · line 271

Quoted 10 lines
rust/kernel/drm/gem/mod.rs +1 -7
-        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()
     };

[Severity: Medium]-
Does this commit miss a similar update in rust/kernel/drm/gem/shmem.rs?

Quoted 8 lines
Quoted 4 lines

The VTABLE initialization in shmem.rs explicitly lists fields without using pin_init::zeroed(), similar to what was fixed here. When compiling with CONFIG_RUST_DRM_GEM_SHMEM_HELPER=y, won't this cause a missing field error for the newly added handle_free callback?

Sure, but it should probably be a different patch in that case. The current patch fixes an issue to a currently existing build failure, while the issue mentioned here has not manifested yet.

On second thought, this is seems to be using the same binding so this might be accurate.

Quoted 28 lines

Regards,
Klara Modin

Quoted 24 lines

rust/kernel/drm/gem/shmem.rs:

    const VTABLE: bindings::drm_gem_object_funcs = bindings::drm_gem_object_funcs {
        free: Some(Self::free_callback),
        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,
    };
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#4 lore raw
Quoted 49 lines · Klara Modin
Quoted 48 lines · Klara Modin
Quoted 46 lines · On 2026-09-08 18:05:54 +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Incomplete fix: missing handle_free field in conditionally compiled shmem.rs. --

commit b5b83bb373847c99ca6d286c268d2e0ffab299f0
Author: Klara Modin <[email protected]>

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

This commit updates the drm_gem_object_funcs struct initialization in the DRM GEM module to use pin_init::zeroed() instead of explicitly assigning None to unused callbacks. This fixes a build failure caused by a newly added callback field in the C structure.

Quoted 12 lines
rust/kernel/drm/gem/mod.rs +0 -4
index e1ebad77ebe2a..c63b0fe5a15e1 100644
@@ -266,18 +266,8 @@ 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,

rust/kernel/drm/gem/mod.rs impl<T: DriverObject, Ctx: DeviceContext> Object<T, Ctx> { · line 271

Quoted 10 lines
rust/kernel/drm/gem/mod.rs +1 -7
-        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()
     };

[Severity: Medium]-
Does this commit miss a similar update in rust/kernel/drm/gem/shmem.rs?

The VTABLE initialization in shmem.rs explicitly lists fields without using pin_init::zeroed(), similar to what was fixed here. When compiling with CONFIG_RUST_DRM_GEM_SHMEM_HELPER=y, won't this cause a missing field error for the newly added handle_free callback?

Quoted 6 lines
Quoted 3 lines

Sure, but it should probably be a different patch in that case. The current patch fixes an issue to a currently existing build failure, while the issue mentioned here has not manifested yet.

On second thought, this is seems to be using the same binding so this might be accurate.

Confirmed, on an arm64 build with the Tyr driver enabled:

error[E0063]: missing field handle_free in initializer of drm_gem_object_funcs

    --> /home/klara/git/linux/trees/next-local/rust/kernel/drm/gem/shmem.rs:130:52
     |
 130 |     const VTABLE: bindings::drm_gem_object_funcs = bindings::drm_gem_object_funcs {
     |                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `handle_free`

error: aborting due to 1 previous error

For more information about this error, try rustc --explain E0063.

I'll wait a while for other thoughts and otherwise respin with this included.

Quoted 29 lines
Quoted 29 lines

Regards,
Klara Modin

Quoted 24 lines

rust/kernel/drm/gem/shmem.rs:

    const VTABLE: bindings::drm_gem_object_funcs = bindings::drm_gem_object_funcs {
        free: Some(Self::free_callback),
        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,
    };
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
reviewer
#5 lore raw
In reply to Klara Modin
Quoted 24 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 None-initializations.

Fixes b67d2d039f64 ("drm/gem: Add callback for when handle count goes to 0")
---
 rust/kernel/drm/gem/mod.rs | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
rust/kernel/drm/gem/mod.rs +0 -0
index 80d8f524f9d5..af8274134a71 100644
@@ -266,18 +266,8 @@ impl<T: DriverObject, Ctx: DeviceContext> Object<T, Ctx> {
         free: Some(Self::free_callback),
         open: Some(open_callback::<T>),
         close: Some(close_callback::<T>),

rust/kernel/drm/gem/mod.rs impl<T: DriverObject, Ctx: DeviceContext> Object<T, Ctx> { · line 269

Quoted 10 lines
rust/kernel/drm/gem/mod.rs +0 -9
-        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(),

This line can be gone too.

Best,
Gary

Quoted 6 lines
rust/kernel/drm/gem/mod.rs +1 -2
-        evict: None,
-        rss: None,
+        ..pin_init::zeroed()
     };
 
     /// Returns the `Device` that owns this GEM object.
#6 lore raw
In reply to Klara Modin

Hi

Am 08.09.26 um 19:54 schrieb Klara Modin:

Quoted 7 lines

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 None-initializations.

Quoted 5 lines
Fixes b67d2d039f64 ("drm/gem: Add callback for when handle count goes to 0")

Please see my bug report at [1].  This patch fixes half of it. I still get

error[E0063]: missing field handle_free in initializer of drm_gem_object_funcs --> /home/tzimmermann/Projekte/linux/rust/kernel/drm/gem/shmem.rs:130:52 |
130 |     const VTABLE: bindings::drm_gem_object_funcs = bindings::drm_gem_object_funcs { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing handle_free

error: aborting due to 1 previous error

[1] https://lore.kernel.org/dri-devel/CANiq72mUW5d1dOQDgpYjuKoUaZAi-im7j3v30Wd4KTDznmM9zw@mail.gmail.com/T/#r8f10eefc91d3bbce58869433b8258882c2d19ff5

Best regards
Thomas

Quoted 28 lines
---
  rust/kernel/drm/gem/mod.rs | 12 +-----------
  1 file changed, 1 insertion(+), 11 deletions(-)
rust/kernel/drm/gem/mod.rs +1 -11
index 80d8f524f9d5..af8274134a71 100644
@@ -266,18 +266,8 @@ 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.
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
#8 lore raw

Hi

Am 09.09.26 um 10:05 schrieb Miguel Ojeda:

Quoted 5 lines · Thomas Zimmermann
Quoted 1 line

Please see my bug report at [1]. This patch fixes half of it. I still get

I think fixing that is the respin that Klara meant in

https://lore.kernel.org/rust-for-linux/[email protected]/

Sure. I do have Tyr enabled FTR.

Best regards
Thomas

Quoted 3 lines

Cheers,
Miguel

Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)