From: Danilo Krummrich <dakr@xxxxxxxxxx> 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@xxxxxxxxxx> Signed-off-by: Igor Korotin <igor.korotin.linux@xxxxxxxxx> --- 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