Use C string literals not cstr!
Since Rust 1.77.0 the language has supported C string literals, so the
`cstr!` macro is no longer needed. Replace existing usages with the
equivalent literal.
See https://doc.rust-lang.org/reference/tokens.html#c-string-literals.
I believe that the two are equivalent:
- Escapes are handled the same way;
- Both allow arbitrary Unicode, which is mapped to UTF-8 (I don't
think we made any use of this);
- Both treat any embedded NUL character as a compile time error.
This is of no significance whatsoever, but it does make the code a
tiny bit simpler. It should not change the compiled code at all, so
no flagging should be needed.
I'm not deleting the macro in this CL; I'll do a follow-up for that,
since there may be usages I can't see, and it has greater chance of
accidental conflict.
Test: TH
Change-Id: I4354b3b0a0c53fbec0c2d78b4182786e4e2d0ce8
diff --git a/libs/libfdt/src/lib.rs b/libs/libfdt/src/lib.rs
index c969749..0dcd31a 100644
--- a/libs/libfdt/src/lib.rs
+++ b/libs/libfdt/src/lib.rs
@@ -31,7 +31,6 @@
use core::ffi::{c_void, CStr};
use core::ops::Range;
-use cstr::cstr;
use libfdt::get_slice_at_ptr;
use zerocopy::IntoBytes as _;
@@ -167,12 +166,12 @@
/// Returns the standard (deprecated) device_type <string> property.
pub fn device_type(&self) -> Result<Option<&CStr>> {
- self.getprop_str(cstr!("device_type"))
+ self.getprop_str(c"device_type")
}
/// Returns the standard reg <prop-encoded-array> property.
pub fn reg(&self) -> Result<Option<RegIterator<'a>>> {
- if let Some(cells) = self.getprop_cells(cstr!("reg"))? {
+ if let Some(cells) = self.getprop_cells(c"reg")? {
let parent = self.parent()?;
let addr_cells = parent.address_cells()?;
@@ -186,7 +185,7 @@
/// Returns the standard ranges property.
pub fn ranges<A, P, S>(&self) -> Result<Option<RangesIterator<'a, A, P, S>>> {
- if let Some(cells) = self.getprop_cells(cstr!("ranges"))? {
+ if let Some(cells) = self.getprop_cells(c"ranges")? {
let parent = self.parent()?;
let addr_cells = self.address_cells()?;
let parent_addr_cells = parent.address_cells()?;
@@ -320,9 +319,9 @@
/// Returns the phandle
pub fn get_phandle(&self) -> Result<Option<Phandle>> {
// This rewrites the fdt_get_phandle() because it doesn't return error code.
- if let Some(prop) = self.getprop_u32(cstr!("phandle"))? {
+ if let Some(prop) = self.getprop_u32(c"phandle")? {
Ok(Some(prop.try_into()?))
- } else if let Some(prop) = self.getprop_u32(cstr!("linux,phandle"))? {
+ } else if let Some(prop) = self.getprop_u32(c"linux,phandle")? {
Ok(Some(prop.try_into()?))
} else {
Ok(None)
@@ -693,8 +692,8 @@
///
/// NOTE: This does not support individual "/memory@XXXX" banks.
pub fn memory(&self) -> Result<MemRegIterator> {
- let node = self.root().subnode(cstr!("memory"))?.ok_or(FdtError::NotFound)?;
- if node.device_type()? != Some(cstr!("memory")) {
+ let node = self.root().subnode(c"memory")?.ok_or(FdtError::NotFound)?;
+ if node.device_type()? != Some(c"memory") {
return Err(FdtError::BadValue);
}
node.reg()?.ok_or(FdtError::BadValue).map(MemRegIterator::new)
@@ -707,12 +706,12 @@
/// Returns the standard /chosen node.
pub fn chosen(&self) -> Result<Option<FdtNode>> {
- self.root().subnode(cstr!("chosen"))
+ self.root().subnode(c"chosen")
}
/// Returns the standard /chosen node as mutable.
pub fn chosen_mut(&mut self) -> Result<Option<FdtNodeMut>> {
- self.node_mut(cstr!("/chosen"))
+ self.node_mut(c"/chosen")
}
/// Returns the root node of the tree.
@@ -722,12 +721,12 @@
/// Returns the standard /__symbols__ node.
pub fn symbols(&self) -> Result<Option<FdtNode>> {
- self.root().subnode(cstr!("__symbols__"))
+ self.root().subnode(c"__symbols__")
}
/// Returns the standard /__symbols__ node as mutable
pub fn symbols_mut(&mut self) -> Result<Option<FdtNodeMut>> {
- self.node_mut(cstr!("/__symbols__"))
+ self.node_mut(c"/__symbols__")
}
/// Returns a tree node by its full path.