From: Daniel Almeida <daniel.almeida@collabora.com>
To: Alexandru Radovici <alexandru.radovici@wyliodrin.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Rafael J. Wysocki" <rafael@kernel.org>,
linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev
Subject: Re: [PATCH RFC v2 1/4] rust: usb: add endpoint abstraction
Date: Thu, 1 Oct 2026 20:31:57 -0300 [thread overview]
Message-ID: <0BD94D14-E5CB-4260-8B3C-AC49AF340CD4@collabora.com> (raw)
In-Reply-To: <20260811-rust-usb_control_msg-v2-1-ef79c92bd898@wyliodrin.com>
Hi Alexandru,
I think the typestate should go away in favor of something simpler:
#[derive(Clone, Copy)]
pub struct Endpoint(u8); <------- private constructor
Drivers ask the Rust layer for their endpoints at probe time, through a
wrapper around the C helpers, e.g. usb_find_common_endpoints()
or similar
pub fn find_bulk_endpoints(&self) -> Result<(Endpoint, Endpoint)>
Unlike your current &HostEndpoint, an Endpoint can be stored in the
driver's data, since it’s just a u8.
Also, perhaps the control endpoint should be its own type, i.e.:
/// # Invariants
///
/// The wrapped [`Endpoint`] is a control endpoint of the device.
#[derive(Clone, Copy)]
pub struct ControlEndpoint(Endpoint);
impl Deref for ControlEndpoint {
type Target = Endpoint;
fn deref(&self) -> &Endpoint {
&self.0
}
}
impl Interface<device::Bound> {
pub fn control_endpoint(&self) -> ControlEndpoint {
// INVARIANT: Endpoint 0 is always a control endpoint.
ControlEndpoint(Endpoint(0))
}
pub fn control_message_send(&self, ep: ControlEndpoint, ...) -> Result
pub fn control_message_receive(&self, ep: ControlEndpoint, ...) -> Result
}
By the way, the alternate setting accessors and making usb::Device
public don't have a user, not even a planned one, so I'd drop them.
-- Daniel
next prev parent reply other threads:[~2026-10-01 23:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 9:42 [PATCH RFC v2 0/4] rust: usb: abstractions towards the port of usbsevseg.c to Rust Alexandru Radovici
2026-08-11 9:42 ` [PATCH RFC v2 1/4] rust: usb: add endpoint abstraction Alexandru Radovici
2026-10-01 23:31 ` Daniel Almeida [this message]
2026-08-11 9:42 ` [PATCH RFC v2 2/4] rust: usb: add control message send and receive Alexandru Radovici
2026-08-11 9:42 ` [PATCH RFC v2 3/4] rust: sysfs: add abstractions for device attributes Alexandru Radovici
2026-08-11 9:42 ` [PATCH RFC v2 4/4] rust: usb: allow drivers to expose sysfs attributes Alexandru Radovici
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=0BD94D14-E5CB-4260-8B3C-AC49AF340CD4@collabora.com \
--to=daniel.almeida@collabora.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=alexandru.radovici@wyliodrin.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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
all inboxes | Powered by JetHome®