Linux Serial subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Markus Probst" <markus.probst@posteo.de>
Cc: linux-serial@vger.kernel.org, ojeda@kernel.org, gary@garyguo.net
Subject: Re: [PATCH v2 3/3] rust: serdev: Simplify callbacks
Date: Sun, 20 Sep 2026 14:44:42 +0000	[thread overview]
Message-ID: <20260920144442.83A6A1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260920-rust_serdev_probe_refactor-v2-3-43b855162f5d@posteo.de>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] serdev: compilation error in OpenGuard initialization due to type mismatch
- [Low] serdev: missing #[inline] attribute on OpenGuard::drop
--

commit 9ef182dba6207d4d0437751e74011a0c64fbd6e3
Author: Markus Probst <markus.probst@posteo.de>

rust: serdev: Simplify callbacks

Initialize the driver's private data directly on PrivateData.

Introduce OpenGuard for resource cleanup.

> diff --git a/rust/kernel/serdev.rs b/rust/kernel/serdev.rs
> index c16d6593a8d2d..3f9165e167764 100644
> --- a/rust/kernel/serdev.rs
> +++ b/rust/kernel/serdev.rs
[ ... ]
> +struct OpenGuard<'bound> {
> +    sdev: &'bound Device<device::Bound>,
> +}
> +
> +impl Drop for OpenGuard<'_> {
> +    fn drop(&mut self) {

[Severity: Low]
Does this function need an #[inline] attribute?

According to the kernel coding guidelines, small functions in abstractions
(like the kernel crate) that forward to a C binding should be annotated
with #[inline].

> +        // SAFETY:
> +        // - `self.sdev.as_raw()` is guaranteed to be a pointer to a valid
> +        //   `struct serdev_device`.
> +        // - The existence of self proves that the device is open.
> +        unsafe { bindings::serdev_device_close(self.sdev.as_raw()) };
> +    }
> +}
[ ... ]
> @@ -134,46 +142,30 @@ extern "C" fn probe_callback(sdev: *mut bindings::serdev_device) -> kernel::ffi:
>  
>          from_result(|| {
>              sdev.as_ref().set_drvdata(try_pin_init!(PrivateData::<T> {
> -                sdev: &**sdev,
> -                driver: MaybeUninit::<T::Data<'_>>::zeroed().into(),
> -                open: false.into(),
> +                open: {
> +                    // SAFETY:
> +                    // - `sdev.as_raw()` is guaranteed to be a valid pointer to
> +                    //   `serdev_device`.
> +                    // - It is safe to call before open.
> +                    unsafe { bindings::serdev_device_set_client_ops(sdev.as_raw(), Self::OPS) };
> +
> +                    // SAFETY: `sdev.as_raw()` is guaranteed to be a valid pointer to
> +                    // `serdev_device`.
> +                    unsafe { bindings::serdev_device_pause_rx(sdev.as_raw()) };
> +
> +                    // SAFETY: `sdev.as_raw()` is guaranteed to be a valid pointer to
> +                    // `serdev_device`.
> +                    to_result(unsafe { bindings::serdev_device_open(sdev.as_raw()) })?;
> +
> +                    OpenGuard { sdev }

[Severity: Medium]
Will this compile successfully?

It looks like sdev is explicitly typed as &Device<device::CoreInternal<'_>>
in probe_callback, but the newly introduced OpenGuard struct expects
sdev: &'bound Device<device::Bound>.

Since Rust struct field initialization does not perform auto-deref coercions,
OpenGuard { sdev } seems to cause a type mismatch compilation error.

Would it be necessary to explicitly dereference it, like
OpenGuard { sdev: &**sdev }?

> +                },
> +                driver <- T::probe(sdev, info),
>              }))?;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260920-rust_serdev_probe_refactor-v2-0-43b855162f5d@posteo.de?part=3

      reply	other threads:[~2026-09-20 14:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-20 14:29 [PATCH v2 0/3] rust: serdev: Refactor Markus Probst
2026-09-20 14:29 ` [PATCH v2 1/3] tty: serdev: Export functions to pause receive_buf callback calls Markus Probst
2026-09-20 14:40   ` sashiko-bot
2026-09-23 10:36     ` Greg KH
2026-09-23 10:35   ` Greg Kroah-Hartman
2026-09-23 13:31     ` Markus Probst
2026-09-23 13:52       ` Gary Guo
2026-09-23 15:06         ` Markus Probst
2026-09-23 14:26       ` Greg Kroah-Hartman
2026-09-23 15:03         ` Markus Probst
2026-09-20 14:30 ` [PATCH v2 2/3] rust: serdev: Replace `active` mutex with receive pause Markus Probst
2026-09-20 14:39   ` sashiko-bot
2026-09-20 14:30 ` [PATCH v2 3/3] rust: serdev: Simplify callbacks Markus Probst
2026-09-20 14:44   ` sashiko-bot [this message]

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=20260920144442.83A6A1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-serial@vger.kernel.org \
    --cc=markus.probst@posteo.de \
    --cc=ojeda@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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