Skip to content

Commit

Permalink
Merge pull request torvalds#612 from wedsonaf/revocable-mutex-drop
Browse files Browse the repository at this point in the history
rust: fix drop in `RevocableMutex`
  • Loading branch information
wedsonaf authored Jan 10, 2022
2 parents 8856b56 + ee3cea3 commit 7739ad0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rust/kernel/sync/revocable_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use core::{
mem::ManuallyDrop,
ops::{Deref, DerefMut},
pin::Pin,
ptr::drop_in_place,
};

/// The state within a `RevocableMutex` that is protected by a mutex.
Expand Down Expand Up @@ -138,10 +137,11 @@ impl<T: ?Sized> RevocableMutex<T> {
return;
}

// SAFETY: We know `inner.data` is valid because `is_available` is set to true. We'll drop
// it here and set it to false so it isn't dropped again.
unsafe { drop_in_place(&mut inner.data) };
inner.is_available = false;

// SAFETY: We know `inner.data` is valid because `is_available` was true. We'll drop it
// here, and given that we set `is_available` to false above, it won't be dropped again.
unsafe { ManuallyDrop::drop(&mut inner.data) };
}
}

Expand Down

0 comments on commit 7739ad0

Please sign in to comment.