Skip to content

Commit 3a142d2

Browse files
Danilo Krummrichgregkh
authored andcommitted
rust: revocable: indicate whether data has been revoked already
commit 4b76faf upstream. Return a boolean from Revocable::revoke() and Revocable::revoke_nosync() to indicate whether the data has been revoked already. Return true if the data hasn't been revoked yet (i.e. this call revoked the data), false otherwise. This is required by Devres in order to synchronize the completion of the revoke process. Reviewed-by: Benno Lossin <lossin@kernel.org> Acked-by: Miguel Ojeda <ojeda@kernel.org> Link: https://lore.kernel.org/r/20250612121817.1621-3-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c0687ec commit 3a142d2

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

rust/kernel/revocable.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ impl<T> Revocable<T> {
126126
/// # Safety
127127
///
128128
/// Callers must ensure that there are no more concurrent users of the revocable object.
129-
unsafe fn revoke_internal<const SYNC: bool>(&self) {
130-
if self.is_available.swap(false, Ordering::Relaxed) {
129+
unsafe fn revoke_internal<const SYNC: bool>(&self) -> bool {
130+
let revoke = self.is_available.swap(false, Ordering::Relaxed);
131+
132+
if revoke {
131133
if SYNC {
132134
// SAFETY: Just an FFI call, there are no further requirements.
133135
unsafe { bindings::synchronize_rcu() };
@@ -137,17 +139,22 @@ impl<T> Revocable<T> {
137139
// `compare_exchange` above that takes `is_available` from `true` to `false`.
138140
unsafe { drop_in_place(self.data.get()) };
139141
}
142+
143+
revoke
140144
}
141145

142146
/// Revokes access to and drops the wrapped object.
143147
///
144148
/// Access to the object is revoked immediately to new callers of [`Revocable::try_access`],
145149
/// expecting that there are no concurrent users of the object.
146150
///
151+
/// Returns `true` if `&self` has been revoked with this call, `false` if it was revoked
152+
/// already.
153+
///
147154
/// # Safety
148155
///
149156
/// Callers must ensure that there are no more concurrent users of the revocable object.
150-
pub unsafe fn revoke_nosync(&self) {
157+
pub unsafe fn revoke_nosync(&self) -> bool {
151158
// SAFETY: By the safety requirement of this function, the caller ensures that nobody is
152159
// accessing the data anymore and hence we don't have to wait for the grace period to
153160
// finish.
@@ -161,7 +168,10 @@ impl<T> Revocable<T> {
161168
/// If there are concurrent users of the object (i.e., ones that called
162169
/// [`Revocable::try_access`] beforehand and still haven't dropped the returned guard), this
163170
/// function waits for the concurrent access to complete before dropping the wrapped object.
164-
pub fn revoke(&self) {
171+
///
172+
/// Returns `true` if `&self` has been revoked with this call, `false` if it was revoked
173+
/// already.
174+
pub fn revoke(&self) -> bool {
165175
// SAFETY: By passing `true` we ask `revoke_internal` to wait for the grace period to
166176
// finish.
167177
unsafe { self.revoke_internal::<true>() }

0 commit comments

Comments
 (0)