Thread (19 messages) 19 messages, 4 authors, 2026-01-16

Re: [PATCH 6/6] rust: driver: drop device private data post unbind

From: "Danilo Krummrich" <dakr@kernel.org>
Date: 2026-01-12 14:27:14
Also in: linux-i2c, linux-pci, linux-usb, lkml
Subsystem: driver core, kobjects, debugfs and sysfs, rust, the rest · Maintainers: Greg Kroah-Hartman, "Rafael J. Wysocki", Danilo Krummrich, Miguel Ojeda, Linus Torvalds

On Wed Jan 7, 2026 at 3:54 PM CET, Greg KH wrote:
I say name it with "rust_" and take out the #ifdef, that makes it
simpler/easier to understand.
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 2d9871503614..bea8da5f8a3a 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -548,10 +548,8 @@ static DEVICE_ATTR_RW(state_synced);
 static void device_unbind_cleanup(struct device *dev)
 {
        devres_release_all(dev);
-#ifdef CONFIG_RUST
-       if (dev->driver->p_cb.post_unbind)
-               dev->driver->p_cb.post_unbind(dev);
-#endif
+       if (dev->driver->p_cb.post_unbind_rust)
+               dev->driver->p_cb.post_unbind_rust(dev);
        arch_teardown_dma_ops(dev);
        kfree(dev->dma_range_map);
        dev->dma_range_map = NULL;
diff --git a/include/linux/device/driver.h b/include/linux/device/driver.h
index 51a9ebdd8a2d..bbc67ec513ed 100644
--- a/include/linux/device/driver.h
+++ b/include/linux/device/driver.h
@@ -121,15 +121,13 @@ struct device_driver {
        void (*coredump) (struct device *dev);

        struct driver_private *p;
-#ifdef CONFIG_RUST
        struct {
                /*
                 * Called after remove() and after all devres entries have been
-                * processed.
+                * processed. This is a Rust only callback.
                 */
-               void (*post_unbind)(struct device *dev);
+               void (*post_unbind_rust)(struct device *dev);
        } p_cb;
-#endif
 };

diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs
index 6e32376d4c7c..26095d7bd0d9 100644
--- a/rust/kernel/driver.rs
+++ b/rust/kernel/driver.rs
@@ -207,7 +207,7 @@ fn callbacks_attach(drv: &Opaque<T::DriverType>) {
         let base = base.cast::<bindings::device_driver>();

         // SAFETY: It is safe to set the fields of `struct device_driver` on initialization.
-        unsafe { (*base).p_cb.post_unbind = Some(Self::post_unbind_callback) };
+        unsafe { (*base).p_cb.post_unbind_rust = Some(Self::post_unbind_callback) };
     }

     /// Creates a new instance of the registration object.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help