From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claude Code Review Bot To: dri-devel-reviews@example.com Subject: Claude review: rust: add basic serial device bus abstractions Date: Thu, 23 Apr 2026 09:21:38 +1000 Message-ID: In-Reply-To: <20260420-rust_serdev-v5-3-57e8ba0519f3@posteo.de> References: <20260420-rust_serdev-v5-0-57e8ba0519f3@posteo.de> <20260420-rust_serdev-v5-3-57e8ba0519f3@posteo.de> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 Patch Review This is the main patch adding `rust/kernel/serdev.rs` (536 lines). **Typo in `Parity` enum:** ```rust + /// Even partiy. + Even = bindings::serdev_parity_SERDEV_PARITY_EVEN, ``` "partiy" should be "parity". The v5 changelog says "fix typo in documentation", but this one appears to still be present. **Broken doc link in `write` method:** ```rust + /// [ Device::wait_until_sent`] to make sure the controller write buffer has actually been ``` This is malformed -- should be `` [`Device::wait_until_sent`] `` (the opening backtick is missing and there's a spurious space after `[`). Compare with the correct version in `write_all`: ```rust + /// [`Device::wait_until_sent`] to make sure the controller write buffer has actually been ``` **`Timeout` enum documentation:** ```rust +/// Timeout in Jiffies. +pub enum Timeout { ``` The doc says "Timeout in Jiffies" but the enum also supports `Milliseconds` and `Max` variants. This should be something like "Timeout specification for serial device operations." **`Timeout::Max` returning 0:** ```rust + Self::Max => 0, ``` This is correct. The C `serdev_device_write` documentation says "timeout in jiffies, or 0 to wait indefinitely", so `Max => 0` correctly maps to indefinite wait. **Race condition handling in `probe_callback`/`receive_buf_callback`:** The design opens the device *before* completing probe: ```rust + to_result(unsafe { + bindings::devm_serdev_device_open(sdev.as_ref().as_raw(), sdev.as_raw()) + })?; + + let data = T::probe(sdev, id_info); ``` This means `receive_buf_callback` can fire before driver data is set. The `Completion` + `UnsafeCell` pattern handles this correctly: - The receive callback waits on `probe_complete` - After completion, it checks the `error` flag - If probe failed, it consumes all data silently (`return length`) The synchronization is sound because `complete_all()`/`wait_for_completion()` provide the necessary memory barriers for the `UnsafeCell` access. The receive callback documentation says "may sleep", so blocking on the completion is safe. One concern: if `T::probe` returns an error-producing initializer, `set_drvdata` will return `Err(...)`. The code correctly handles this by still calling `complete_all()` after setting the error flag. But if the error happens *before* `set_drvdata` (e.g., `devres::register` or `devm_serdev_device_open` fails), the early `?` return would skip `complete_all()`. This is safe only because client_ops are set before `devm_serdev_device_open`, and if the device isn't opened, the receive callback won't be called. The ordering of operations is correct but fragile -- a future refactor that reorders these calls could introduce a deadlock. **`set_baudrate` return type:** ```rust + pub fn set_baudrate(&self, speed: u32) -> Result<(), u32> { ``` Returning `Result<(), u32>` (where the error value is the actual baudrate achieved) is an unusual but defensible API choice. However, it breaks from the kernel Rust convention where `Result` typically means `Result`. Users who want to know the actual baudrate set on failure must handle the `u32` error, which is a different error type than the rest of the serdev API. **`write_all` return value cast:** ```rust + to_result(ret as i32).map(|()| ret.unsigned_abs()) ``` Where `ret` is `isize` (from `ssize_t`). The comment correctly notes that negative values fit in `i32`. For positive values, `ret as i32` could overflow if writing >2GB, but this is unrealistic for serial devices. **Missing `#[cfg]` guard:** The `serdev.c` helper file is compiled unconditionally (added to `helpers.c`). It should arguably be guarded by `#ifdef CONFIG_RUST_SERIAL_DEV_BUS_ABSTRACTIONS` to avoid compiling unused helpers, matching the pattern used for the Rust module in `lib.rs`: ```rust +#[cfg(CONFIG_RUST_SERIAL_DEV_BUS_ABSTRACTIONS)] +pub mod serdev; ``` **Trailing `//` comments:** ```rust + types::{ + AlwaysRefCounted, + Opaque, // + }, // ``` These trailing `//` comments appear to be rustfmt artifacts to force vertical formatting. This is a known pattern in kernel Rust code but could be noted as intentional. --- Generated by Claude Code Patch Reviewer