From 9fc2613b416d107b539c70cf24a19c393b8d689b Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 24 Nov 2020 17:25:02 +0000 Subject: [PATCH] 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 --- vm-device/src/bus.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm-device/src/bus.rs b/vm-device/src/bus.rs index 20e5d3e8f..c9240d134 100644 --- a/vm-device/src/bus.rs +++ b/vm-device/src/bus.rs @@ -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)]