* [PATCH 0/4] rust: serdev: trivial fixes
@ 2026-07-18 11:36 Markus Probst
2026-07-18 11:36 ` [PATCH 1/4] rust: serdev: fix typo in rustdoc Markus Probst
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Markus Probst @ 2026-07-18 11:36 UTC (permalink / raw)
To: Greg Kroah-Hartman, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan
Cc: linux-serial, rust-for-linux, linux-kernel, Markus Probst,
kernel test robot
Those are small fixes discovered by the kernel test robot and Gary Guo
after the serdev rust abstraction have already been merged.
This includes
- a fix for a documentation typo
- adding missing `#[inline]` attributes
- a small structual change for timeout
There is no urgency to merge this.
Signed-off-by: Markus Probst <markus.probst@posteo.de>
---
Markus Probst (4):
rust: serdev: fix typo in rustdoc
rust: serdev: mark small functions as `#[inline]`
rust: serdev: document `PrivateData::active`
rust: serdev: remove `serdev::Timeout`
rust/kernel/serdev.rs | 80 +++++++++++++++++++++++++++------------------------
1 file changed, 43 insertions(+), 37 deletions(-)
---
base-commit: 25acf039a5dbb40b6865d9392e05be8e713a39f3
change-id: 20260717-rust_serdev_fixes-9baf5f310278
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] rust: serdev: fix typo in rustdoc
2026-07-18 11:36 [PATCH 0/4] rust: serdev: trivial fixes Markus Probst
@ 2026-07-18 11:36 ` Markus Probst
2026-07-18 11:36 ` [PATCH 2/4] rust: serdev: mark small functions as `#[inline]` Markus Probst
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Markus Probst @ 2026-07-18 11:36 UTC (permalink / raw)
To: Greg Kroah-Hartman, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan
Cc: linux-serial, rust-for-linux, linux-kernel, Markus Probst,
kernel test robot
Fix trivial typo
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202607172113.hLDQgD4l-lkp@intel.com/
Signed-off-by: Markus Probst <markus.probst@posteo.de>
---
rust/kernel/serdev.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rust/kernel/serdev.rs b/rust/kernel/serdev.rs
index 0ffcef1849d2..47ca57966abf 100644
--- a/rust/kernel/serdev.rs
+++ b/rust/kernel/serdev.rs
@@ -515,7 +515,7 @@ pub fn write_all(&self, data: &[u8], timeout: Timeout) -> Result<usize> {
/// [`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
+ /// [`Device::wait_until_sent`] to make sure the controller write buffer has actually been
/// emptied.
///
/// Returns the number of bytes written (less than `data.len()` if not enough room in the
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] rust: serdev: mark small functions as `#[inline]`
2026-07-18 11:36 [PATCH 0/4] rust: serdev: trivial fixes Markus Probst
2026-07-18 11:36 ` [PATCH 1/4] rust: serdev: fix typo in rustdoc Markus Probst
@ 2026-07-18 11:36 ` Markus Probst
2026-07-18 11:36 ` [PATCH 3/4] rust: serdev: document `PrivateData::active` Markus Probst
2026-07-18 11:36 ` [PATCH 4/4] rust: serdev: remove `serdev::Timeout` Markus Probst
3 siblings, 0 replies; 5+ messages in thread
From: Markus Probst @ 2026-07-18 11:36 UTC (permalink / raw)
To: Greg Kroah-Hartman, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan
Cc: linux-serial, rust-for-linux, linux-kernel, Markus Probst
These methods should be inlined for optimization reasons.
Suggested-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/rust-for-linux/DK0SX3P5K1J6.1OV4ETJMXW83R@garyguo.net/
Signed-off-by: Markus Probst <markus.probst@posteo.de>
---
rust/kernel/serdev.rs | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/rust/kernel/serdev.rs b/rust/kernel/serdev.rs
index 47ca57966abf..79d61c6ceeec 100644
--- a/rust/kernel/serdev.rs
+++ b/rust/kernel/serdev.rs
@@ -440,6 +440,7 @@ pub struct Device<Ctx: device::DeviceContext = device::Normal>(
);
impl<Ctx: device::DeviceContext> Device<Ctx> {
+ #[inline]
fn as_raw(&self) -> *mut bindings::serdev_device {
self.0.get()
}
@@ -451,6 +452,7 @@ impl Device<device::Bound> {
/// Common baudrates are 115200, 9600, 19200, 57600, 4800.
///
/// Use [`Device::write_flush`] before calling this if you have written data prior to this call.
+ #[inline]
pub fn set_baudrate(&self, speed: u32) -> Result<(), u32> {
// SAFETY: `self.as_raw()` is guaranteed to be a pointer to a valid `serdev_device`.
let ret = unsafe { bindings::serdev_device_set_baudrate(self.as_raw(), speed) };
@@ -464,6 +466,7 @@ pub fn set_baudrate(&self, speed: u32) -> Result<(), u32> {
/// Set if flow control should be enabled.
///
/// Use [`Device::write_flush`] before calling this if you have written data prior to this call.
+ #[inline]
pub fn set_flow_control(&self, enable: bool) {
// SAFETY: `self.as_raw()` is guaranteed to be a pointer to a valid `serdev_device`.
unsafe { bindings::serdev_device_set_flow_control(self.as_raw(), enable) };
@@ -472,6 +475,7 @@ pub fn set_flow_control(&self, enable: bool) {
/// Set parity to use.
///
/// Use [`Device::write_flush`] before calling this if you have written data prior to this call.
+ #[inline]
pub fn set_parity(&self, parity: Parity) -> Result {
// SAFETY: `self.as_raw()` is guaranteed to be a pointer to a valid `serdev_device`.
to_result(unsafe { bindings::serdev_device_set_parity(self.as_raw(), parity as u32) })
@@ -487,6 +491,7 @@ pub fn set_parity(&self, parity: Parity) -> Result {
/// Returns the number of bytes written (less than `data.len()` if interrupted).
/// [`kernel::error::code::ETIMEDOUT`] or [`kernel::error::code::ERESTARTSYS`] if interrupted
/// before any bytes were written.
+ #[inline]
pub fn write_all(&self, data: &[u8], timeout: Timeout) -> Result<usize> {
if data.len() > i32::MAX as usize {
return Err(EINVAL);
@@ -520,6 +525,7 @@ pub fn write_all(&self, data: &[u8], timeout: Timeout) -> Result<usize> {
///
/// Returns the number of bytes written (less than `data.len()` if not enough room in the
/// write buffer).
+ #[inline]
pub fn write(&self, data: &[u8]) -> Result<u32> {
if data.len() > i32::MAX as usize {
return Err(EINVAL);
@@ -539,6 +545,7 @@ pub fn write(&self, data: &[u8]) -> Result<u32> {
///
/// Note that this doesn't guarantee that the data has been transmitted.
/// Use [`Device::wait_until_sent`] for this purpose.
+ #[inline]
pub fn write_flush(&self) {
// SAFETY: `self.as_raw()` is guaranteed to be a pointer to a valid `serdev_device`.
unsafe { bindings::serdev_device_write_flush(self.as_raw()) };
@@ -547,6 +554,7 @@ pub fn write_flush(&self) {
/// Wait for the data to be sent.
///
/// After this function, the write buffer of the controller should be empty.
+ #[inline]
pub fn wait_until_sent(&self, timeout: Timeout) {
// SAFETY: `self.as_raw()` is guaranteed to be a pointer to a valid `serdev_device`.
unsafe { bindings::serdev_device_wait_until_sent(self.as_raw(), timeout.into_jiffies()) };
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] rust: serdev: document `PrivateData::active`
2026-07-18 11:36 [PATCH 0/4] rust: serdev: trivial fixes Markus Probst
2026-07-18 11:36 ` [PATCH 1/4] rust: serdev: fix typo in rustdoc Markus Probst
2026-07-18 11:36 ` [PATCH 2/4] rust: serdev: mark small functions as `#[inline]` Markus Probst
@ 2026-07-18 11:36 ` Markus Probst
2026-07-18 11:36 ` [PATCH 4/4] rust: serdev: remove `serdev::Timeout` Markus Probst
3 siblings, 0 replies; 5+ messages in thread
From: Markus Probst @ 2026-07-18 11:36 UTC (permalink / raw)
To: Greg Kroah-Hartman, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan
Cc: linux-serial, rust-for-linux, linux-kernel, Markus Probst
Gary pointed out that it isn't clear for what the mutex is used for,
thus adding documentation comments for it.
Suggested-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/rust-for-linux/DK0SX3P5K1J6.1OV4ETJMXW83R@garyguo.net/
Signed-off-by: Markus Probst <markus.probst@posteo.de>
---
rust/kernel/serdev.rs | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/rust/kernel/serdev.rs b/rust/kernel/serdev.rs
index 79d61c6ceeec..3556fe066ace 100644
--- a/rust/kernel/serdev.rs
+++ b/rust/kernel/serdev.rs
@@ -132,6 +132,23 @@ pub struct PrivateData<'bound, T: Driver> {
#[pin]
driver: UnsafeCell<MaybeUninit<T::Data<'bound>>>,
open: UnsafeCell<bool>,
+ /// Whether `receive_buf_callback` is allowed to call `Driver::receive_buf`.
+ ///
+ /// If locked, the receive_buf_callback will be blocked on data receival.
+ /// This is the case while the driver is being probed or while [`PrivateData`] is being dropped.
+ /// This is necessary, because we need to open the serdev device before the driver has been
+ /// probed in order to allow it to be configured, which allows [`Adapter::receive_buf_callback`]
+ /// to be called. Thus we need to block data until probe completes and the driver data becomes
+ /// initialized.
+ ///
+ /// If unlocked and true, the receive_buf_callback will forward the data to
+ /// `Driver::receive_buf`. This is the normal state of operation.
+ ///
+ /// If unlocked and false, the receive_buf_callback will throw away the data.
+ /// This is only the case, if the serdev device is open and
+ /// - the driver returned an error in probe
+ /// or
+ /// - the driver data already has been dropped, because it was unbound.
#[pin]
active: Mutex<bool>,
}
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] rust: serdev: remove `serdev::Timeout`
2026-07-18 11:36 [PATCH 0/4] rust: serdev: trivial fixes Markus Probst
` (2 preceding siblings ...)
2026-07-18 11:36 ` [PATCH 3/4] rust: serdev: document `PrivateData::active` Markus Probst
@ 2026-07-18 11:36 ` Markus Probst
3 siblings, 0 replies; 5+ messages in thread
From: Markus Probst @ 2026-07-18 11:36 UTC (permalink / raw)
To: Greg Kroah-Hartman, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan
Cc: linux-serial, rust-for-linux, linux-kernel, Markus Probst
Instead of relying on its own timeout types, the abstraction should make
use of `impl Into<Jiffies>`.
Suggested-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/rust-for-linux/DK0SX3P5K1J6.1OV4ETJMXW83R@garyguo.net/
Signed-off-by: Markus Probst <markus.probst@posteo.de>
---
rust/kernel/serdev.rs | 53 +++++++++++++++++----------------------------------
1 file changed, 17 insertions(+), 36 deletions(-)
diff --git a/rust/kernel/serdev.rs b/rust/kernel/serdev.rs
index 3556fe066ace..b35f20f24bcd 100644
--- a/rust/kernel/serdev.rs
+++ b/rust/kernel/serdev.rs
@@ -20,11 +20,7 @@
aref::AlwaysRefCounted,
Mutex, //
},
- time::{
- msecs_to_jiffies,
- Jiffies,
- Msecs, //
- },
+ time::Jiffies,
types::{
Opaque,
ScopeGuard, //
@@ -35,7 +31,6 @@
cell::UnsafeCell,
marker::PhantomData,
mem::{offset_of, MaybeUninit},
- num::NonZero,
ptr::NonNull, //
};
@@ -50,30 +45,6 @@ pub enum Parity {
Odd = bindings::serdev_parity_SERDEV_PARITY_ODD,
}
-/// Timeout in Jiffies.
-pub enum Timeout {
- /// Wait for a specific amount of [`Jiffies`].
- Jiffies(NonZero<Jiffies>),
- /// Wait for a specific amount of [`Msecs`].
- Milliseconds(NonZero<Msecs>),
- /// Wait as long as possible.
- ///
- /// This is equivalent to [`kernel::task::MAX_SCHEDULE_TIMEOUT`].
- Max,
-}
-
-impl Timeout {
- fn into_jiffies(self) -> isize {
- match self {
- Self::Jiffies(value) => value.get().try_into().unwrap_or_default(),
- Self::Milliseconds(value) => {
- msecs_to_jiffies(value.get()).try_into().unwrap_or_default()
- }
- Self::Max => 0,
- }
- }
-}
-
/// An adapter for the registration of serial device bus device drivers.
pub struct Adapter<T: Driver>(T);
@@ -505,11 +476,13 @@ pub fn set_parity(&self, parity: Parity) -> Result {
/// [`Device::wait_until_sent`] to make sure the controller write buffer has actually been
/// emptied.
///
+ /// Use a timeout of 0 to wait indefinitely.
+ ///
/// Returns the number of bytes written (less than `data.len()` if interrupted).
/// [`kernel::error::code::ETIMEDOUT`] or [`kernel::error::code::ERESTARTSYS`] if interrupted
- /// before any bytes were written.
+ /// before any bytes were written. [`kernel::error::code::EINVAL`] if `data.len() > i32::MAX`.
#[inline]
- pub fn write_all(&self, data: &[u8], timeout: Timeout) -> Result<usize> {
+ pub fn write_all(&self, data: &[u8], timeout: impl Into<Jiffies>) -> Result<usize> {
if data.len() > i32::MAX as usize {
return Err(EINVAL);
}
@@ -523,7 +496,7 @@ pub fn write_all(&self, data: &[u8], timeout: Timeout) -> Result<usize> {
self.as_raw(),
data.as_ptr(),
data.len(),
- timeout.into_jiffies(),
+ isize::try_from(timeout.into()).unwrap_or_default(),
)
};
// CAST: negative return values are guaranteed to be between `-MAX_ERRNO` and `-1`,
@@ -570,11 +543,19 @@ pub fn write_flush(&self) {
/// Wait for the data to be sent.
///
- /// After this function, the write buffer of the controller should be empty.
+ /// After this function, the write buffer of the controller should be empty or the timeout
+ /// elapsed.
+ ///
+ /// Use a timeout of 0 to wait indefinitely.
#[inline]
- pub fn wait_until_sent(&self, timeout: Timeout) {
+ pub fn wait_until_sent(&self, timeout: impl Into<Jiffies>) {
// SAFETY: `self.as_raw()` is guaranteed to be a pointer to a valid `serdev_device`.
- unsafe { bindings::serdev_device_wait_until_sent(self.as_raw(), timeout.into_jiffies()) };
+ unsafe {
+ bindings::serdev_device_wait_until_sent(
+ self.as_raw(),
+ isize::try_from(timeout.into()).unwrap_or_default(),
+ )
+ };
}
}
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-18 11:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-18 11:36 [PATCH 0/4] rust: serdev: trivial fixes Markus Probst
2026-07-18 11:36 ` [PATCH 1/4] rust: serdev: fix typo in rustdoc Markus Probst
2026-07-18 11:36 ` [PATCH 2/4] rust: serdev: mark small functions as `#[inline]` Markus Probst
2026-07-18 11:36 ` [PATCH 3/4] rust: serdev: document `PrivateData::active` Markus Probst
2026-07-18 11:36 ` [PATCH 4/4] rust: serdev: remove `serdev::Timeout` Markus Probst
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox