kata_object_alloc_in_cnode: misc fixups

- optimize CNode size calc
- remove an extranous map_err that hid the true error

Change-Id: I63a43dff7c242d49f2f968abdde4134ac300d0b1
GitOrigin-RevId: 9e8e9ec4b3bb33dca53ee45aed231836dec7d6e4
This commit is contained in:
Sam Leffler 2022-06-23 03:13:34 +00:00
parent 9920153e10
commit b0d1b6efac

View File

@ -424,18 +424,14 @@ pub fn kata_object_alloc_in_cnode(
objs: Vec<ObjDesc>, objs: Vec<ObjDesc>,
) -> Result<ObjDescBundle, MemoryManagerError> { ) -> Result<ObjDescBundle, MemoryManagerError> {
fn next_log2(value: usize) -> usize { fn next_log2(value: usize) -> usize {
let mut size_bits = 0; // NB: BITS & leading_zeros return u32
while value > (1 << size_bits) { (1 + usize::BITS - usize::leading_zeros(value)) as usize
size_bits += 1;
}
size_bits
} }
// NB: CNode size depends on how many objects are requested. // NB: CNode size depends on how many objects are requested.
let cnode_depth = next_log2(objs.iter().map(|od| od.count).sum()); let cnode_depth = next_log2(objs.iter().map(|od| od.count).sum());
// Request a top-level CNode. // Request a top-level CNode.
let cnode = kata_cnode_alloc(cnode_depth) let cnode = kata_cnode_alloc(cnode_depth)?;
.map_err(|_| MemoryManagerError::MmeAllocFailed)?;
// Now construct the request for |objs| with |cnode| as the container. // Now construct the request for |objs| with |cnode| as the container.
let request = ObjDescBundle::new( let request = ObjDescBundle::new(