[PATCH v8 1/9] rust: device: implement FwNode::is_of_node()

Igor Korotin posted 9 patches 3 months, 2 weeks ago
[PATCH v8 1/9] rust: device: implement FwNode::is_of_node()
Posted by Igor Korotin 3 months, 2 weeks ago
From: Danilo Krummrich <dakr@kernel.org>

Implement FwNode::is_of_node() in order to check whether a FwNode
instance is embedded in a struct device_node.

Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
---
 MAINTAINERS                    | 1 +
 rust/helpers/helpers.c         | 1 +
 rust/helpers/of.c              | 8 ++++++++
 rust/kernel/device/property.rs | 7 +++++++
 4 files changed, 17 insertions(+)
 create mode 100644 rust/helpers/of.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 9f724cd556f4..1e918319cff4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -18579,6 +18579,7 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git
 F:	Documentation/ABI/testing/sysfs-firmware-ofw
 F:	drivers/of/
 F:	include/linux/of*.h
+F:	rust/helpers/of.c
 F:	rust/kernel/of.rs
 F:	scripts/dtc/
 F:	tools/testing/selftests/dt/
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index ed00695af971..041a8112eb9e 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -26,6 +26,7 @@
 #include "kunit.c"
 #include "mm.c"
 #include "mutex.c"
+#include "of.c"
 #include "page.c"
 #include "platform.c"
 #include "pci.c"
diff --git a/rust/helpers/of.c b/rust/helpers/of.c
new file mode 100644
index 000000000000..86b51167c913
--- /dev/null
+++ b/rust/helpers/of.c
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/of.h>
+
+bool rust_helper_is_of_node(const struct fwnode_handle *fwnode)
+{
+	return is_of_node(fwnode);
+}
diff --git a/rust/kernel/device/property.rs b/rust/kernel/device/property.rs
index 838509111e57..63fe4b6ee6bc 100644
--- a/rust/kernel/device/property.rs
+++ b/rust/kernel/device/property.rs
@@ -61,6 +61,13 @@ pub(crate) fn as_raw(&self) -> *mut bindings::fwnode_handle {
         self.0.get()
     }
 
+    /// Returns `true` if `&self` is an OF node, `false` otherwise.
+    pub fn is_of_node(&self) -> bool {
+        // SAFETY: The type invariant of `Self` guarantees that `self.as_raw() is a pointer to a
+        // valid `struct fwnode_handle`.
+        unsafe { bindings::is_of_node(self.as_raw()) }
+    }
+
     /// Returns an object that implements [`Display`](core::fmt::Display) for
     /// printing the name of a node.
     ///
-- 
2.43.0
Re: [PATCH v8 1/9] rust: device: implement FwNode::is_of_node()
Posted by Rob Herring 3 months, 2 weeks ago
On Fri, Jun 20, 2025 at 10:17 AM Igor Korotin
<igor.korotin.linux@gmail.com> wrote:
>
> From: Danilo Krummrich <dakr@kernel.org>
>
> Implement FwNode::is_of_node() in order to check whether a FwNode
> instance is embedded in a struct device_node.
>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
> ---
>  MAINTAINERS                    | 1 +
>  rust/helpers/helpers.c         | 1 +
>  rust/helpers/of.c              | 8 ++++++++
>  rust/kernel/device/property.rs | 7 +++++++
>  4 files changed, 17 insertions(+)
>  create mode 100644 rust/helpers/of.c

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Re: [PATCH v8 1/9] rust: device: implement FwNode::is_of_node()
Posted by Danilo Krummrich 3 months, 2 weeks ago
On Fri, Jun 20, 2025 at 04:15:04PM +0100, Igor Korotin wrote:
> From: Danilo Krummrich <dakr@kernel.org>
> 
> Implement FwNode::is_of_node() in order to check whether a FwNode
> instance is embedded in a struct device_node.
> 
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
> ---
>  MAINTAINERS                    | 1 +
>  rust/helpers/helpers.c         | 1 +
>  rust/helpers/of.c              | 8 ++++++++
>  rust/kernel/device/property.rs | 7 +++++++
>  4 files changed, 17 insertions(+)
>  create mode 100644 rust/helpers/of.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 9f724cd556f4..1e918319cff4 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -18579,6 +18579,7 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git
>  F:	Documentation/ABI/testing/sysfs-firmware-ofw
>  F:	drivers/of/
>  F:	include/linux/of*.h
> +F:	rust/helpers/of.c

@Rob: Any concerns about adding the OF Rust helpers to the OF entry?
Re: [PATCH v8 1/9] rust: device: implement FwNode::is_of_node()
Posted by Danilo Krummrich 3 months, 2 weeks ago
On Sat, Jun 21, 2025 at 12:40:02AM +0200, Danilo Krummrich wrote:
> On Fri, Jun 20, 2025 at 04:15:04PM +0100, Igor Korotin wrote:
> > From: Danilo Krummrich <dakr@kernel.org>
> > 
> > Implement FwNode::is_of_node() in order to check whether a FwNode
> > instance is embedded in a struct device_node.
> > 
> > Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> > Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
> > ---
> >  MAINTAINERS                    | 1 +
> >  rust/helpers/helpers.c         | 1 +
> >  rust/helpers/of.c              | 8 ++++++++
> >  rust/kernel/device/property.rs | 7 +++++++
> >  4 files changed, 17 insertions(+)
> >  create mode 100644 rust/helpers/of.c
> > 
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 9f724cd556f4..1e918319cff4 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -18579,6 +18579,7 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git
> >  F:	Documentation/ABI/testing/sysfs-firmware-ofw
> >  F:	drivers/of/
> >  F:	include/linux/of*.h
> > +F:	rust/helpers/of.c
> 
> @Rob: Any concerns about adding the OF Rust helpers to the OF entry?

Given that you proposed to use is_of_node() and rust/kernel/of.rs is under your
MAINTAINERS entry as well, I assume this is fine.

If not, please let me know.