Skip to content

Commit e1cd24a

Browse files
vireshkgregkh
authored andcommitted
rust: device: Replace CString with CStr in property_present()
The property_present() method expects a &CString currently and will work only with heap allocated C strings. In order to make it work with compile-time string constants too, change the argument type to &CStr. Signed-off-by: Viresh Kumar <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/e97dcbe0418cc1053fb4bcfac65cc02a0afcdf78.1737005078.git.viresh.kumar@linaro.org Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2485f8e commit e1cd24a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

rust/kernel/device.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use crate::{
88
bindings,
9-
str::CString,
9+
str::CStr,
1010
types::{ARef, Opaque},
1111
};
1212
use core::{fmt, ptr};
@@ -183,8 +183,8 @@ impl Device {
183183
}
184184

185185
/// Checks if property is present or not.
186-
pub fn property_present(&self, name: &CString) -> bool {
187-
// SAFETY: By the invariant of `CString`, `name` is null-terminated.
186+
pub fn property_present(&self, name: &CStr) -> bool {
187+
// SAFETY: By the invariant of `CStr`, `name` is null-terminated.
188188
unsafe { bindings::device_property_present(self.as_raw().cast_const(), name.as_ptr() as *const _) }
189189
}
190190
}

0 commit comments

Comments
 (0)