]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rust: device: Add property_present()
authorViresh Kumar <viresh.kumar@linaro.org>
Mon, 13 Jan 2025 11:22:59 +0000 (16:52 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 15 Jan 2025 17:22:34 +0000 (18:22 +0100)
This implements Device::property_present(), which calls C APIs
device_property_present() helper.

The new helper will be used by Rust based cpufreq drivers.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Link: https://lore.kernel.org/r/f43fe3f7b3151a89c261ad728b0f3bb2fc24caef.1736766672.git.viresh.kumar@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
rust/bindings/bindings_helper.h
rust/kernel/device.rs

index e9fdceb568b8f94e602ee498323e5768a40a6cba..55354e4dec14e9859ace33a6b0afb6d9a6653ea1 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/pid_namespace.h>
 #include <linux/platform_device.h>
 #include <linux/poll.h>
+#include <linux/property.h>
 #include <linux/refcount.h>
 #include <linux/sched.h>
 #include <linux/security.h>
index c926e0c2b8528c289ebd0f9849c04e1b6eec30a4..eadc6160a4be23546761c4678de4bc07d457e906 100644 (file)
@@ -6,6 +6,7 @@
 
 use crate::{
     bindings,
+    str::CString,
     types::{ARef, Opaque},
 };
 use core::{fmt, ptr};
@@ -180,6 +181,12 @@ impl Device {
             )
         };
     }
+
+    /// Checks if property is present or not.
+    pub fn property_present(&self, name: &CString) -> bool {
+        // SAFETY: By the invariant of `CString`, `name` is null-terminated.
+        unsafe { bindings::device_property_present(self.as_raw().cast_const(), name.as_ptr() as *const _) }
+    }
 }
 
 // SAFETY: Instances of `Device` are always reference-counted.