Message ID | f43fe3f7b3151a89c261ad728b0f3bb2fc24caef.1736766672.git.viresh.kumar@linaro.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Rust bindings for cpufreq and OPP core + sample driver | expand |
On Mon, Jan 13, 2025 at 04:52:59PM +0530, Viresh Kumar wrote: > 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> > --- > rust/bindings/bindings_helper.h | 1 + > rust/kernel/device.rs | 7 +++++++ > 2 files changed, 8 insertions(+) > > diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h > index d63e7f6d10ea..fda1e0d8f376 100644 > --- a/rust/bindings/bindings_helper.h > +++ b/rust/bindings/bindings_helper.h > @@ -27,6 +27,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> > diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs > index d5e6a19ff6b7..e8c4cda5aacc 100644 > --- a/rust/kernel/device.rs > +++ b/rust/kernel/device.rs > @@ -6,6 +6,7 @@ > > use crate::{ > bindings, > + str::CString, > types::{ARef, Opaque}, > }; > use core::{fmt, ptr}; > @@ -180,6 +181,12 @@ unsafe fn printk(&self, klevel: &[u8], msg: fmt::Arguments<'_>) { > ) > }; > } > + > + /// 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 _) } > + } > } Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
On Mon, Jan 13, 2025 at 04:52:59PM +0530, Viresh Kumar wrote: > 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> > --- > rust/bindings/bindings_helper.h | 1 + > rust/kernel/device.rs | 7 +++++++ > 2 files changed, 8 insertions(+) Want me to take this in my driver-core tree now for 6.14-rc1? thanks, greg k-h
On 14-01-25, 19:42, Greg Kroah-Hartman wrote: > On Mon, Jan 13, 2025 at 04:52:59PM +0530, Viresh Kumar wrote: > > 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> > > --- > > rust/bindings/bindings_helper.h | 1 + > > rust/kernel/device.rs | 7 +++++++ > > 2 files changed, 8 insertions(+) > > Want me to take this in my driver-core tree now for 6.14-rc1? Sure, Thanks.
+Rob/Dirk, On 15-01-25, 12:45, Viresh Kumar wrote: > On 14-01-25, 19:42, Greg Kroah-Hartman wrote: > > On Mon, Jan 13, 2025 at 04:52:59PM +0530, Viresh Kumar wrote: > > > 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> > > > --- > > > rust/bindings/bindings_helper.h | 1 + > > > rust/kernel/device.rs | 7 +++++++ > > > 2 files changed, 8 insertions(+) > > > > Want me to take this in my driver-core tree now for 6.14-rc1? > > Sure, Thanks. I now see that Rob/Dirk have sent [1] a bigger patch earlier which adds this functionality along with other DT bindings. Though it isn't merged yet.
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index d63e7f6d10ea..fda1e0d8f376 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -27,6 +27,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> diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs index d5e6a19ff6b7..e8c4cda5aacc 100644 --- a/rust/kernel/device.rs +++ b/rust/kernel/device.rs @@ -6,6 +6,7 @@ use crate::{ bindings, + str::CString, types::{ARef, Opaque}, }; use core::{fmt, ptr}; @@ -180,6 +181,12 @@ unsafe fn printk(&self, klevel: &[u8], msg: fmt::Arguments<'_>) { ) }; } + + /// 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.
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> --- rust/bindings/bindings_helper.h | 1 + rust/kernel/device.rs | 7 +++++++ 2 files changed, 8 insertions(+)