Merge "vmbase: Replace flatten() with slice::as_flattened" into main
diff --git a/guest/pvmfw/src/fdt.rs b/guest/pvmfw/src/fdt.rs
index f667d60..823c61e 100644
--- a/guest/pvmfw/src/fdt.rs
+++ b/guest/pvmfw/src/fdt.rs
@@ -49,7 +49,6 @@
use vmbase::hyp;
use vmbase::layout::{crosvm::MEM_START, MAX_VIRT_ADDR};
use vmbase::memory::SIZE_4KB;
-use vmbase::util::flatten;
use vmbase::util::RangeExt as _;
use zerocopy::AsBytes as _;
@@ -726,7 +725,7 @@
node.setprop_inplace(
cstr!("ranges"),
- flatten(&[pci_info.ranges[0].to_cells(), pci_info.ranges[1].to_cells()]),
+ [pci_info.ranges[0].to_cells(), pci_info.ranges[1].to_cells()].as_flattened(),
)
}
@@ -923,7 +922,7 @@
let mut node =
fdt.root_mut().next_compatible(cstr!("arm,gic-v3"))?.ok_or(FdtError::NotFound)?;
- node.setprop_inplace(cstr!("reg"), flatten(&value))
+ node.setprop_inplace(cstr!("reg"), value.as_flattened())
}
fn patch_timer(fdt: &mut Fdt, num_cpus: usize) -> libfdt::Result<()> {
@@ -1327,7 +1326,7 @@
let addr: u64 = addr.try_into().unwrap();
let size: u64 = size.try_into().unwrap();
- node.setprop_inplace(cstr!("reg"), flatten(&[addr.to_be_bytes(), size.to_be_bytes()]))
+ node.setprop_inplace(cstr!("reg"), [addr.to_be_bytes(), size.to_be_bytes()].as_flattened())
}
fn empty_or_delete_prop(
diff --git a/libs/libvmbase/src/util.rs b/libs/libvmbase/src/util.rs
index e52ac8e..6142cb3 100644
--- a/libs/libvmbase/src/util.rs
+++ b/libs/libvmbase/src/util.rs
@@ -17,15 +17,6 @@
use aarch64_paging::paging::MemoryRegion;
use core::ops::Range;
-/// Flatten [[T; N]] into &[T]
-/// TODO: use slice::flatten when it graduates from experimental
-pub fn flatten<T, const N: usize>(original: &[[T; N]]) -> &[T] {
- // SAFETY: no overflow because original (whose size is len()*N) is already in memory
- let len = original.len() * N;
- // SAFETY: [T] has the same layout as [T;N]
- unsafe { core::slice::from_raw_parts(original.as_ptr().cast(), len) }
-}
-
/// Computes the largest multiple of the provided alignment smaller or equal to the address.
///
/// Note: the result is undefined if alignment isn't a power of two.