rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: miscdevice: clarify invariant for `MiscDeviceRegistration`
@ 2025-06-22 11:06 Shankari Anand
  2025-06-22 20:26 ` Miguel Ojeda
  0 siblings, 1 reply; 3+ messages in thread
From: Shankari Anand @ 2025-06-22 11:06 UTC (permalink / raw)
  To: rust-for-linux
  Cc: alex.gaynor, boqun.feng, gary, ossin, a.hindborg, bjorn3_gh,
	Shankari Anand, Benno Lossin

Reword and expand the invariant documentation for `MiscDeviceRegistration`
to clarify what it means for the inner device to be "registered".
It expands to explain:
- `inner` points to a `miscdevice` registered via `misc_register`.
- This registration stays valid for the entire lifetime of the object.
- Deregistration is guaranteed on `Drop`, via `misc_deregister`.

Reported-by: Benno Lossin <lossin@kernel.org>
Closes: https://github.com/Rust-for-Linux/linux/issues/1168
Fixes: f893691e7426 ("rust: miscdevice: add base miscdevice abstraction")
Signed-off-by: Shankari Anand <shankari.ak0208@gmail.com>
---
 rust/kernel/miscdevice.rs | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs
index 939278bc7b03..5df98dce019a 100644
--- a/rust/kernel/miscdevice.rs
+++ b/rust/kernel/miscdevice.rs
@@ -45,7 +45,15 @@ pub const fn into_raw<T: MiscDevice>(self) -> bindings::miscdevice {
 ///
 /// # Invariants
 ///
-/// `inner` is a registered misc device.
+/// The `inner` field contains a `struct miscdevice` that has been registered with
+/// the kernel using `misc_register()`.
+/// This registration remains valid for the entire lifetime of the `MiscDeviceRegistration`
+/// instance.
+/// Deregistration is guaranteed to occur exactly once, during the [`Drop`] implementation, via
+/// a call to `misc_deregister()`.
+/// The `inner` pointer is never null and always points to a valid, pinned `miscdevice` instance
+/// initialized via `MiscDeviceOptions::into_raw`.
+
 #[repr(transparent)]
 #[pin_data(PinnedDrop)]
 pub struct MiscDeviceRegistration<T> {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-22 20:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-22 11:06 [PATCH] rust: miscdevice: clarify invariant for `MiscDeviceRegistration` Shankari Anand
2025-06-22 20:26 ` Miguel Ojeda
2025-06-22 20:32   ` Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).