Skip to content

Commit

Permalink
xde detach panicked on Arc::try_unwrap (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzezeski committed Jul 11, 2022
1 parent 92a3ae2 commit 0e78c72
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions xde/src/xde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,13 +937,33 @@ unsafe extern "C" fn xde_detach(
_cmd: ddi_detach_cmd_t,
) -> c_int {
assert!(!xde_dip.is_null());

if xde_devs.read().len() > 0 {
warn!("failed to detach: outstanding ports");
return DDI_FAILURE;
}

let rstate = ddi_get_driver_private(xde_dip);
assert!(!rstate.is_null());
let state = Box::from_raw(rstate as *mut XdeState);
let underlay = state.underlay.into_inner();

match underlay {
Some(underlay) => {
// These next two checks shouldn't be necessary if the
// above check for zero Ports is cleared. However, we play
// it safe, making sure there is only 1 reference before
// attempting to unwrap the underlay from the Arc.
if Arc::strong_count(&underlay.u1) > 1 {
warn!("failed to deatch: underlay u1 has outstanding refs");
return DDI_FAILURE;
}

if Arc::strong_count(&underlay.u2) > 1 {
warn!("failed to deatch: underlay u2 has outstanding refs");
return DDI_FAILURE;
}

let u1 = Arc::try_unwrap(underlay.u1).unwrap();
let u2 = Arc::try_unwrap(underlay.u2).unwrap();

Expand Down

0 comments on commit 0e78c72

Please sign in to comment.