Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH v2] rust: kernel: device: Add devm_of_platform_populate/depopulate
@ 2025-04-29 11:39 Ayush Singh
  2025-04-29 12:10 ` Miguel Ojeda
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Ayush Singh @ 2025-04-29 11:39 UTC (permalink / raw)
  To: Jason Kridner, Deepak Khatri, Robert Nelson, Dhruva Gole,
	Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Greg Kroah-Hartman,
	Rafael J. Wysocki
  Cc: rust-for-linux, linux-kernel, Ayush Singh

Add abstractions for devm_of_platform_populate and
devm_of_platform_depopulate.

Can only be used with a bound device.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
---
Allow calling platform_populate/depopulate from Rust code.

To see how the bindings look in usage, see my working tree [0] for a
connector driver  I am working on.

[0]: https://github.com/Ayush1325/linux/commits/b4/beagle-cape/
---
Changes in v2:
- Rename to devm_of_platform_populate/depopulate.
- Add SAFETY comments.
- Implement only for bound device
- Import to_result
- Link to v1: https://lore.kernel.org/r/20250428-rust-of-populate-v1-1-1d33777427c4@beagleboard.org
---
 rust/bindings/bindings_helper.h |  1 +
 rust/kernel/device.rs           | 15 +++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index 8a2add69e5d66d1c2ebed9d2c950380e61c48842..51ec0754960377e5fc6bc0703487bf2086eff0e6 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -25,6 +25,7 @@
 #include <linux/mdio.h>
 #include <linux/miscdevice.h>
 #include <linux/of_device.h>
+#include <linux/of_platform.h>
 #include <linux/pci.h>
 #include <linux/phy.h>
 #include <linux/pid_namespace.h>
diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
index 40c1f549b0bae9fd9aa3f41539ccb69896c2560d..dc52abeb114792fcecce469c11e336c23c4b1c00 100644
--- a/rust/kernel/device.rs
+++ b/rust/kernel/device.rs
@@ -6,6 +6,7 @@
 
 use crate::{
     bindings,
+    error::to_result,
     str::CStr,
     types::{ARef, Opaque},
 };
@@ -209,6 +210,20 @@ pub fn property_present(&self, name: &CStr) -> bool {
     }
 }
 
+impl Device<Bound> {
+    /// Populate platform_devices from device tree data
+    pub fn devm_of_platform_populate(&self) -> crate::error::Result<()> {
+        // SAFETY: self is valid bound Device reference
+        to_result(unsafe { bindings::devm_of_platform_populate(self.as_raw()) })
+    }
+
+    /// Remove devices populated from device tree
+    pub fn devm_of_platform_depopulate(&self) {
+        // SAFETY: self is valid bound Device reference
+        unsafe { bindings::devm_of_platform_depopulate(self.as_raw()) }
+    }
+}
+
 // SAFETY: `Device` is a transparent wrapper of a type that doesn't depend on `Device`'s generic
 // argument.
 kernel::impl_device_context_deref!(unsafe { Device });

---
base-commit: 33035b665157558254b3c21c3f049fd728e72368
change-id: 20250428-rust-of-populate-b2f961783441

Best regards,
-- 
Ayush Singh <ayush@beagleboard.org>


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-04-29 20:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-29 11:39 [PATCH v2] rust: kernel: device: Add devm_of_platform_populate/depopulate Ayush Singh
2025-04-29 12:10 ` Miguel Ojeda
2025-04-29 13:53 ` Danilo Krummrich
2025-04-29 14:31 ` Danilo Krummrich
2025-04-29 14:37   ` Greg Kroah-Hartman
2025-04-29 14:44     ` Danilo Krummrich
2025-04-29 14:57       ` Greg Kroah-Hartman
2025-04-29 16:07         ` Ayush Singh
2025-04-29 16:39           ` Greg Kroah-Hartman
2025-04-29 16:56             ` Ayush Singh
2025-04-29 20:55           ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox