vm-device: bus: Remove unwrap() when upgrading weak reference

Rather return the None to the caller to handle instead. This removes the
source of a potential panic.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-11-24 17:25:02 +00:00 committed by Samuel Ortiz
parent 44b5a19209
commit 9fc2613b41

View File

@ -112,7 +112,7 @@ impl Bus {
.range(..=BusRange { base: addr, len: 1 })
.rev()
.next()?;
Some((*range, dev.upgrade().unwrap().clone()))
dev.upgrade().map(|d| (*range, d.clone()))
}
#[allow(clippy::type_complexity)]