pvmfw: Avoid panic if OPP table too large
As ArrayVec::push() panics if called on a full instance, ensure that it
is only called up to the capacity of the array and print a warning if
more entries are received.
Functionally, this will boot with fewer OPPs than actually supported
i.e. a potential performance impact but which is preferable to
preventing guests from booting altogether.
Bug: 335130218
Test: m pvmfw && TH
Change-Id: I7e064d87202170e670f3855c4c949b68c6429610
diff --git a/pvmfw/src/fdt.rs b/pvmfw/src/fdt.rs
index d847ca2..9dca8af 100644
--- a/pvmfw/src/fdt.rs
+++ b/pvmfw/src/fdt.rs
@@ -199,11 +199,16 @@
opp_node: FdtNode,
) -> libfdt::Result<ArrayVec<[u64; CpuInfo::MAX_OPPTABLES]>> {
let mut table = ArrayVec::new();
- for subnode in opp_node.subnodes()? {
+ let mut opp_nodes = opp_node.subnodes()?;
+ for subnode in opp_nodes.by_ref().take(table.capacity()) {
let prop = subnode.getprop_u64(cstr!("opp-hz"))?.ok_or(FdtError::NotFound)?;
table.push(prop);
}
+ if opp_nodes.next().is_some() {
+ warn!("OPP table has more than {} entries: discarding extra nodes.", table.capacity());
+ }
+
Ok(table)
}