From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: rust: devres: return reference in `devres::register`
Date: Sun, 12 Apr 2026 08:55:16 +1000 [thread overview]
Message-ID: <review-patch1-20260411-rust_serdev-v4-1-845e960c6627@posteo.de> (raw)
In-Reply-To: <20260411-rust_serdev-v4-1-845e960c6627@posteo.de>
Patch Review
This patch changes `devres::register` from returning `Result` to `Result<&'a T>`, tying the returned reference's lifetime to the `&'a Device<Bound>` argument. This is needed by patch 3 to access `PrivateData` after registration.
**Soundness analysis**: The approach is sound. After `KBox::pin_init`, a raw pointer `data_ptr` is captured before `register_foreign` takes ownership of the `KBox`. The `KBox`'s heap allocation (and thus the pointed-to data) remains valid as long as devres hasn't cleaned it up. Since devres cleanup occurs at unbind time (after `remove`), and `Device<Bound>` references cannot exist after unbind, tying the reference to `'a` is conservative and correct.
However, the SAFETY comment could be improved:
```rust
+ // SAFETY: `dev` is valid for the lifetime of 'a. As long as there is a reference to
+ // `Device<Bound>`, it is guaranteed that the device is not unbound and data has not been
+ // dropped. Thus `data_ptr` is also valid for the lifetime of 'a.
```
This should also mention that `data_ptr` was obtained from the `KBox` before `register_foreign` took ownership, and that `register_foreign` preserves the heap allocation (it transfers ownership to devres, it doesn't move the data).
**Existing callers updated correctly**: `cpufreq.rs` and `drm/driver.rs` now discard the returned reference with `?;` + `Ok(())`. This is correct but slightly awkward -- a `register_void()` helper or a method that explicitly discards the reference would be cleaner. Minor style point, not blocking.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-04-11 22:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-11 15:10 [PATCH v4 0/4] rust: add basic serial device bus abstractions Markus Probst via B4 Relay
2026-04-11 15:10 ` [PATCH v4 1/4] rust: devres: return reference in `devres::register` Markus Probst via B4 Relay
2026-04-11 22:55 ` Claude Code Review Bot [this message]
2026-04-11 15:10 ` [PATCH v4 2/4] serdev: add rust private data to serdev_device Markus Probst via B4 Relay
2026-04-11 22:55 ` Claude review: " Claude Code Review Bot
2026-04-11 15:10 ` [PATCH v4 3/4] rust: add basic serial device bus abstractions Markus Probst via B4 Relay
2026-04-11 22:55 ` Claude review: " Claude Code Review Bot
2026-04-11 15:10 ` [PATCH v4 4/4] samples: rust: add Rust serial device bus sample device driver Markus Probst via B4 Relay
2026-04-11 22:55 ` Claude review: " Claude Code Review Bot
2026-04-11 22:55 ` Claude review: rust: add basic serial device bus abstractions Claude Code Review Bot
-- strict thread matches above, loose matches on Subject: below --
2026-03-13 18:12 [PATCH v3 0/4] " Markus Probst
2026-03-13 18:12 ` [PATCH v3 1/4] rust: devres: return reference in `devres::register` Markus Probst
2026-03-16 2:17 ` Claude review: " Claude Code Review Bot
2026-03-06 19:35 [PATCH v2 0/4] rust: add basic serial device bus abstractions Markus Probst
2026-03-06 19:35 ` [PATCH v2 1/4] rust: devres: return reference in `devres::register` 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-patch1-20260411-rust_serdev-v4-1-845e960c6627@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