From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: rust: add basic serial device bus abstractions
Date: Thu, 04 Jun 2026 15:18:43 +1000 [thread overview]
Message-ID: <review-patch3-20260530-rust_serdev-v10-3-65d1d5db876c@posteo.de> (raw)
In-Reply-To: <20260530-rust_serdev-v10-3-65d1d5db876c@posteo.de>
Patch Review
This is the main patch at 553 lines. Several observations:
**1. Typo in `Parity` enum:**
```rust
+ /// Even partiy.
+ Even = bindings::serdev_parity_SERDEV_PARITY_EVEN,
```
"partiy" should be "parity".
**2. `Timeout::into_jiffies` and the `Max` variant:**
```rust
+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,
+ }
+ }
+}
```
`Timeout::Max` returns 0, which works because the C `serdev_device_write()` treats `timeout == 0` as `MAX_SCHEDULE_TIMEOUT`. However, `serdev_device_wait_until_sent()` passes this timeout directly to `tty_wait_until_sent()`, which calls `schedule_timeout()`. For `schedule_timeout()`, a timeout of 0 means "don't wait at all" — the opposite of "wait forever." So `Timeout::Max` passed to `wait_until_sent()` would result in no waiting, which is a bug.
This should be documented or handled differently. Consider mapping `Max` to `isize::MAX` (which is `LONG_MAX` = `MAX_SCHEDULE_TIMEOUT` on the C side) and only keeping the special 0 mapping for `write_all` if that's what's intended, or making `Timeout` method-specific.
**3. `unwrap_or_default()` for overflow:**
```rust
+ Self::Jiffies(value) => value.get().try_into().unwrap_or_default(),
```
If the conversion from `Jiffies` (likely `u64`) to `isize` overflows, it silently becomes 0. Combined with `serdev_device_write`'s treatment of 0 as `MAX_SCHEDULE_TIMEOUT`, an overflow would silently become an infinite wait. This is surprising — a saturating conversion to `isize::MAX` would be safer.
**4. Probe callback and `PrivateData` registration:**
```rust
+ extern "C" fn probe_callback(sdev: *mut bindings::serdev_device) -> kernel::ffi::c_int {
+ let sdev = unsafe { &*sdev.cast::<Device<device::CoreInternal<'_>>>() };
+ ...
+ let private_data = devres::register(
+ sdev.as_ref(),
+ try_pin_init!(PrivateData {
+ active <- new_mutex!(false),
+ }),
+ GFP_KERNEL,
+ )?;
+ let mut active = private_data.active.lock();
+ ...
+ unsafe {
+ (*sdev.as_raw()).rust_private_data =
+ (&raw const *private_data).cast::<c_void>().cast_mut()
+ };
```
The `PrivateData` is registered via `devres::register`, so it will be cleaned up when the device is unregistered. The pointer is stored in `rust_private_data` after registration. The mutex is locked before `set_drvdata` to synchronize with `receive_buf_callback`, which is good.
However, the sequencing is important: `serdev_device_set_client_ops` is called *after* storing `rust_private_data`, so there's no race window where `receive_buf` could fire with `rust_private_data` unset. Good.
**5. `remove_callback` synchronization with `receive_buf`:**
```rust
+ let private_data = unsafe { &*(*sdev.as_raw()).rust_private_data.cast::<PrivateData>() };
+ *private_data.active.lock() = false;
+ T::unbind(sdev, data);
```
The `active` flag is set to `false` under the mutex before calling `unbind`. In `receive_buf_callback`, the mutex is held while checking `active` and calling `T::receive`. This ensures `receive` won't be called after `remove_callback` starts. However, there's a subtlety: `drvdata_borrow` is called *before* the `active` check in `remove_callback`, but *after* it in `receive_buf_callback`. In `remove_callback`, `drvdata_borrow` is called before setting `active = false` — this is fine since the driver data hasn't been dropped yet. The ordering looks correct.
**6. `write_all` return value handling:**
```rust
+ pub fn write_all(&self, data: &[u8], timeout: Timeout) -> Result<usize> {
+ let ret = unsafe {
+ bindings::serdev_device_write(...)
+ };
+ to_result(ret as i32).map(|()| ret.unsigned_abs())
+ }
```
`serdev_device_write` returns `ssize_t`. Casting to `i32` could truncate on platforms where `ssize_t` is 64-bit. If a write succeeds with more than `i32::MAX` bytes (theoretically), the cast could produce a negative value and falsely trigger an error. In practice serdev writes won't be that large, but the cast is technically lossy. The `ret.unsigned_abs()` on the return is also on the original `ssize_t`, which correctly preserves the full value. The issue is only in the error check path.
**7. `write` return type is `Result<u32>`:**
```rust
+ pub fn write(&self, data: &[u8]) -> Result<u32> {
```
The C function `serdev_device_write_buf` returns `int`. Returning `u32` for the count is fine since successful values are non-negative, but the same `ret as i32` cast concern applies since `ret` comes from an `int` which is already `i32`-sized in practice on Linux, so this one is actually fine.
**8. Missing `[ ` bracket in doc comment:**
```rust
+ /// 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
```
There's a broken rustdoc link: `[ Device::wait_until_sent`]` should be `[`Device::wait_until_sent`]` (missing backtick after `[`).
**9. `set_baudrate` returns `Result<(), u32>`:**
```rust
+ pub fn set_baudrate(&self, speed: u32) -> Result<(), u32> {
```
This is unusual — most Rust-for-Linux abstractions use `Result` (i.e., `Result<T, Error>`). Returning `Err(actual_baudrate)` when the requested baudrate isn't exactly matched is potentially confusing, as the C `serdev_device_set_baudrate` returns the actual baudrate set (which might be close but not exact). The sample driver treats any mismatch as `EINVAL`. Consider whether a baudrate mismatch (e.g., requesting 115200 and getting 115201) should really be an error or just a warning. This is arguably a design choice that should be documented.
**10. `set_baudrate` and other config methods on `Device<Bound>` only:**
All the configuration methods are on `impl Device<device::Bound>`, but in the sample driver, `probe` receives `&'bound serdev::Device<Core<'_>>`. The sample calls `sdev.set_baudrate(...)` directly, which means `Device<Core>` must deref to `Device<Bound>` (via `impl_device_context_deref!`). This works, but it's worth noting that `Core` impls `Bound` methods through deref.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-06-04 5:18 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-30 19:25 [PATCH v10 0/5] rust: add basic serial device bus abstractions Markus Probst
2026-05-30 19:25 ` [PATCH v10 1/5] rust: devres: return reference in `devres::register` Markus Probst
2026-06-04 5:18 ` Claude review: " Claude Code Review Bot
2026-05-30 19:25 ` [PATCH v10 2/5] serdev: add rust private data to serdev_device Markus Probst
2026-06-04 5:18 ` Claude review: " Claude Code Review Bot
2026-05-30 19:25 ` [PATCH v10 3/5] rust: add basic serial device bus abstractions Markus Probst
2026-06-04 5:18 ` Claude Code Review Bot [this message]
2026-05-30 19:25 ` [PATCH v10 4/5] samples: rust: add Rust serial device bus sample device driver Markus Probst
2026-06-04 5:18 ` Claude review: " Claude Code Review Bot
2026-05-30 19:25 ` [PATCH v10 5/5] MAINTAINERS: serdev: Add self for serdev Markus Probst
2026-06-04 5:18 ` Claude review: " Claude Code Review Bot
2026-06-04 5:18 ` Claude review: rust: add basic serial device bus abstractions Claude Code Review Bot
-- strict thread matches above, loose matches on Subject: below --
2026-06-03 15:56 [PATCH v12 0/3] " Markus Probst via B4 Relay
2026-06-03 15:56 ` [PATCH v12 1/3] " Markus Probst via B4 Relay
2026-06-04 1:33 ` Claude review: " Claude Code Review Bot
2026-06-04 1:33 ` Claude Code Review Bot
2026-05-30 22:51 [PATCH v11 0/3] " Markus Probst via B4 Relay
2026-05-30 22:51 ` [PATCH v11 1/3] " Markus Probst via B4 Relay
2026-06-04 5:07 ` Claude review: " Claude Code Review Bot
2026-06-04 5:07 ` Claude Code Review Bot
2026-05-30 17:36 [PATCH v9 0/3] " Markus Probst
2026-05-30 17:36 ` [PATCH v9 1/3] " Markus Probst
2026-06-04 5:28 ` Claude review: " Claude Code Review Bot
2026-06-04 5:28 ` Claude Code Review Bot
2026-05-30 1:13 [PATCH v8 0/5] " Markus Probst via B4 Relay
2026-05-30 1:13 ` [PATCH v8 3/5] " Markus Probst via B4 Relay
2026-06-04 5:57 ` Claude review: " Claude Code Review Bot
2026-06-04 5:57 ` Claude Code Review Bot
2026-04-29 18:21 [PATCH v7 0/4] " Markus Probst via B4 Relay
2026-04-29 18:21 ` [PATCH v7 3/4] " Markus Probst via B4 Relay
2026-05-05 1:18 ` Claude review: " Claude Code Review Bot
2026-05-05 1:18 ` Claude Code Review Bot
2026-04-27 18:05 [PATCH v6 0/4] " Markus Probst via B4 Relay
2026-04-27 18:05 ` [PATCH v6 3/4] " Markus Probst via B4 Relay
2026-04-28 4:14 ` Claude review: " Claude Code Review Bot
2026-04-28 4:14 ` Claude Code Review Bot
2026-04-20 20:07 [PATCH v5 0/4] " Markus Probst
2026-04-20 20:07 ` [PATCH v5 3/4] " Markus Probst
2026-04-22 23:21 ` Claude review: " Claude Code Review Bot
2026-04-22 23:21 ` Claude Code Review Bot
2026-04-11 15:10 [PATCH v4 0/4] " Markus Probst via B4 Relay
2026-04-11 15:10 ` [PATCH v4 3/4] " Markus Probst via B4 Relay
2026-04-11 22:55 ` Claude review: " Claude Code Review Bot
2026-04-11 22:55 ` Claude Code Review Bot
2026-03-13 18:12 [PATCH v3 0/4] " Markus Probst
2026-03-13 18:12 ` [PATCH v3 3/4] " Markus Probst
2026-03-16 2:17 ` Claude review: " Claude Code Review Bot
2026-03-16 2:17 ` Claude Code Review Bot
2026-03-06 19:35 [PATCH v2 0/4] " Markus Probst
2026-03-08 22:21 ` Claude review: " Claude Code Review Bot
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=review-patch3-20260530-rust_serdev-v10-3-65d1d5db876c@posteo.de \
--to=claude-review@example.com \
--cc=dri-devel-reviews@example.com \
/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