]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rust: device: implement FwNode::is_of_node()
authorDanilo Krummrich <dakr@kernel.org>
Fri, 20 Jun 2025 15:15:04 +0000 (16:15 +0100)
committerDanilo Krummrich <dakr@kernel.org>
Wed, 25 Jun 2025 16:10:12 +0000 (18:10 +0200)
Implement FwNode::is_of_node() in order to check whether a FwNode
instance is embedded in a struct device_node.

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
Link: https://lore.kernel.org/r/20250620151504.278766-1-igor.korotin.linux@gmail.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
MAINTAINERS
rust/helpers/helpers.c
rust/helpers/of.c [new file with mode: 0644]
rust/kernel/device/property.rs

index 68d2a32759ec576953893db87f936d04d92797f5..ac68531befed9d535693098b55eb63db0e7c376f 100644 (file)
@@ -18580,6 +18580,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/
index 393ad201befb80a9ae39866a725744ab88620fbb..0b09bd0e3561c7bf80bf79faf1aebd7eeb851984 100644 (file)
@@ -28,6 +28,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 (file)
index 0000000..86b5116
--- /dev/null
@@ -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);
+}
index 2f6f3ef17db7b06e76a5f8450b75a40a19e97b70..49ee12a906dbadbe932e207fc7a0d1d622125f5f 100644 (file)
@@ -61,6 +61,13 @@ impl FwNode {
         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.
     ///