From: Danilo Krummrich <dakr@kernel.org>
To: Rahul Rameshbabu <sergeantsagara@protonmail.com>
Cc: "Benjamin Tissoires" <bentiss@kernel.org>,
"Jiri Kosina" <jikos@kernel.org>,
linux-input@vger.kernel.org, rust-for-linux@vger.kernel.org,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Daniel Brooks" <db48x@db48x.net>
Subject: Re: [PATCH v1 2/3] rust: core abstractions for HID drivers
Date: Sat, 5 Jul 2025 12:54:42 +0200 [thread overview]
Message-ID: <aGkEcrKJsvFelWju@pollux> (raw)
In-Reply-To: <87frfbksam.fsf@protonmail.com>
On Sat, Jul 05, 2025 at 07:31:21AM +0000, Rahul Rameshbabu wrote:
> In parallel, I am thinking about how to design a Drop trait for handling
> HID device unplug instead of needing a C style remove callback. This
> will be crucial for implementing sophisticated leaf drivers.
Please have a look at how other bus abstractions are implemented, e.g. platform,
pci, auxiliary.
They all have a probe() function in the Driver trait, which returns a
Pin<KBox<Self>>, i.e. the drivers private data.
This ForeignOwnable is then stored in the private data pointer of the C struct
device, which I'm adding generic accessors for in [1].
On driver remove() this ForeignOwnable is extracted back into a Pin<KBox<Self>>
and dropped.
This means there's already Driver::drop() which is called on device unplug.
However, this is not sufficient, because Driver::drop() only gives you a &mut
self, i.e. a reference to Pin<KBox<Self>>, but not a Core context reference to
the Device, i.e. &Device<Core>. Hence you need a separate Driver::unbind()
callback. Please see [2] for that.
[1] https://lore.kernel.org/all/20250621195118.124245-3-dakr@kernel.org/
[2] https://lore.kernel.org/all/20250621195118.124245-7-dakr@kernel.org/
next prev parent reply other threads:[~2025-07-05 10:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-29 4:51 [PATCH v1 0/3] Initial work for Rust abstraction for HID device driver development Rahul Rameshbabu
2025-06-29 4:51 ` [PATCH v1 1/3] HID: core: Change hid_driver to use a const char* for name Rahul Rameshbabu
2025-06-29 4:51 ` [PATCH v1 2/3] rust: core abstractions for HID drivers Rahul Rameshbabu
2025-06-29 8:45 ` Danilo Krummrich
2025-07-03 6:37 ` Jiri Kosina
2025-07-03 8:01 ` Benjamin Tissoires
2025-07-03 8:20 ` Danilo Krummrich
2025-07-05 7:31 ` Rahul Rameshbabu
2025-07-05 10:41 ` Miguel Ojeda
2025-07-06 3:03 ` Rahul Rameshbabu
2025-07-05 10:54 ` Danilo Krummrich [this message]
2025-06-29 4:51 ` [PATCH v1 3/3] rust: hid: Glorious Gaming PC Race Model O and O- mice reference driver Rahul Rameshbabu
2025-06-29 9:22 ` Danilo Krummrich
2025-07-03 10:36 ` Peter Hutterer
2025-07-05 13:01 ` [PATCH v1 0/3] Initial work for Rust abstraction for HID device driver development Aditya Garg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aGkEcrKJsvFelWju@pollux \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bentiss@kernel.org \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=db48x@db48x.net \
--cc=gary@garyguo.net \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sergeantsagara@protonmail.com \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).