[PATCH] rust: device: Replace CString with CStr in property_present()

From: Viresh Kumar
Date: Thu Jan 16 2025 - 00:26:51 EST


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 <viresh.kumar@xxxxxxxxxx>
---
Adapted with Rob's version a little.

rust/kernel/device.rs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
index e8c4cda5aacc..c775266ae164 100644
--- a/rust/kernel/device.rs
+++ b/rust/kernel/device.rs
@@ -6,7 +6,7 @@

use crate::{
bindings,
- str::CString,
+ str::CStr,
types::{ARef, Opaque},
};
use core::{fmt, ptr};
@@ -183,8 +183,8 @@ 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.
+ pub fn property_present(&self, name: &CStr) -> bool {
+ // SAFETY: By the invariant of `CStr`, `name` is null-terminated.
unsafe { bindings::device_property_present(self.as_raw().cast_const(), name.as_ptr() as *const _) }
}
}
--
2.31.1.272.g89b43f80a514