lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2f42525e678925a803ea4acaeb1e704953e44681.camel@posteo.de>
Date: Sun, 21 Dec 2025 12:41:10 +0000
From: Markus Probst <markus.probst@...teo.de>
To: Dirk Behme <dirk.behme@...il.com>, Rob Herring <robh@...nel.org>, Greg
 Kroah-Hartman <gregkh@...uxfoundation.org>, Jiri Slaby
 <jirislaby@...nel.org>, Miguel Ojeda <ojeda@...nel.org>,  Boqun Feng
 <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
 Björn Roy Baron	 <bjorn3_gh@...tonmail.com>, Benno
 Lossin <lossin@...nel.org>, Andreas Hindborg	 <a.hindborg@...nel.org>,
 Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross	 <tmgross@...ch.edu>,
 Danilo Krummrich <dakr@...nel.org>, Kari Argillander	
 <kari.argillander@...il.com>
Cc: linux-serial@...r.kernel.org, linux-kernel@...r.kernel.org, 
	rust-for-linux@...r.kernel.org
Subject: Re: [PATCH RFC 2/4] rust: add basic serial device bus abstractions

Hi Dirk,

On Sun, 2025-12-21 at 10:19 +0100, Dirk Behme wrote:
> Hi Markus,
> 
> On 20.12.25 19:44, Markus Probst wrote:
> > Implement the basic serial device bus abstractions required to write a
> > serial device bus device driver with or without the need for initial device
> > data. This includes the following data structures:
> > 
> > The `serdev::Driver` trait represents the interface to the driver.
> > 
> > The `serdev::Device` abstraction represents a `struct serdev_device`.
> > 
> > In order to provide the Serdev specific parts to a generic
> > `driver::Registration` the `driver::RegistrationOps` trait is
> > implemented by `serdev::Adapter`.
> > 
> > Co-developed-by: Kari Argillander <kari.argillander@...il.com>
> > Signed-off-by: Kari Argillander <kari.argillander@...il.com>
> > Signed-off-by: Markus Probst <markus.probst@...teo.de>
> > ---
> >  rust/bindings/bindings_helper.h |   1 +
> >  rust/helpers/helpers.c          |   1 +
> >  rust/helpers/serdev.c           |  22 ++
> >  rust/kernel/lib.rs              |   2 +
> >  rust/kernel/serdev.rs           | 815 ++++++++++++++++++++++++++++++++++++++++
> >  5 files changed, 841 insertions(+)
> > 
> ...
> > diff --git a/rust/kernel/serdev.rs b/rust/kernel/serdev.rs
> > new file mode 100644
> > index 000000000000..0f5ef325a054
> > --- /dev/null
> > +++ b/rust/kernel/serdev.rs
> ....
> > +    /// Write data to the serial device until the controller has accepted all the data or has
> > +    /// been interrupted by a timeout or signal.
> > +    ///
> > +    /// Note that any accepted data has only been buffered by the controller. Use
> > +    /// [ Device::wait_until_sent`] to make sure the controller write buffer has actually been
> > +    /// emptied.
> > +    ///
> > +    /// Returns the number of bytes written (less than data if interrupted).
> 
> Should it be "less than data.len"? Instead of just "data"? Same in the
> comment for `write()`below.
Yes.
> 
> 
> > +    /// [`kernel::error::code::ETIMEDOUT`] or [`kernel::error::code::ERESTARTSYS`] if interrupted
> > +    /// before any bytes were written.
> > +    pub fn write_all(&self, data: &[u8], timeout: Timeout) -> Result<usize> {
> > +        // SAFETY:
> > +        // - `self.as_raw()` is guaranteed to be a pointer to a valid `serdev_device`.
> > +        // - `data.as_ptr()` is guaranteed to be a valid array pointer with the size of
> > +        //   `data.len()`.
> > +        let ret = unsafe {
> > +            bindings::serdev_device_write(
> > +                self.as_raw(),
> > +                data.as_ptr(),
> > +                data.len(),
> > +                timeout.into_jiffies(),
> > +            )
> > +        };
> > +        if ret < 0 {
> > +            // CAST: negative return values are guaranteed to be between `-MAX_ERRNO` and `-1`,
> > +            // which always fit into a `i32`.
> > +            Err(Error::from_errno(ret as i32))
> > +        } else {
> > +            Ok(ret.unsigned_abs())
> > +        }
> > +    }
> > +
> > +    /// Write data to the serial device.
> > +    ///
> > +    /// If you want to write until the controller has accepted all the data, use
> > +    /// [`Device::write_all`].
> > +    ///
> > +    /// Note that any accepted data has only been buffered by the controller. Use
> > +    /// [ Device::wait_until_sent`] to make sure the controller write buffer has actually been
> > +    /// emptied.
> > +    ///
> > +    /// Returns the number of bytes written (less than data if interrupted).
> > +    /// [`kernel::error::code::ETIMEDOUT`] or [`kernel::error::code::ERESTARTSYS`] if interrupted
> > +    /// before any bytes were written.
> > +    pub fn write(&self, data: &[u8]) -> Result<u32> {
> > +        // SAFETY:
> > +        // - `self.as_raw()` is guaranteed to be a pointer to a valid `serdev_device`.
> > +        // - `data.as_ptr()` is guaranteed to be a valid array pointer with the size of
> > +        //   `data.len()`.
> > +        let ret =
> > +            unsafe { bindings::serdev_device_write_buf(self.as_raw(), data.as_ptr(), data.len()) };
> > +        if ret < 0 {
> > +            Err(Error::from_errno(ret))
> > +        } else {
> > +            Ok(ret.unsigned_abs())
> > +        }
> > +    }
> 
> Best regards
> 
> Dirk

Thanks
- Markus Probst

Download attachment "signature.asc" of type "application/pgp-signature" (871 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ