From: sashiko-bot@kernel.org
To: "Gary Guo" <gary@garyguo.net>
Cc: robh@kernel.org, devicetree@vger.kernel.org,
linux-pci@vger.kernel.org, "Danilo Krummrich" <dakr@kernel.org>,
conor+dt@kernel.org, dri-devel@lists.freedesktop.org,
"Alexandre Courbot" <acourbot@nvidia.com>,
ojeda@kernel.org
Subject: Re: [PATCH v2 09/11] rust: driver: remove open-coded matching logic
Date: Tue, 30 Jun 2026 12:40:20 +0000 [thread overview]
Message-ID: <20260630124021.3E2281F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260629-id_info-v2-9-56fccbe9c5ef@garyguo.net>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Data race and NULL pointer dereference due to lockless access of `dev->driver` in `Adapter::id_info`.
--
commit 228e0cfe9ec1514c36d9085e1b3070934920f9ab
Author: Gary Guo <gary@garyguo.net>
rust: driver: remove open-coded matching logic
This commit replaces the open-coded ACPI and OF matching logic in the Rust
driver abstractions with a single call to device_get_match_data(). It removes
the acpi_of_match_device() helper and updates the Adapter::id_info() function
to use the C API directly.
> diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs
> index 824899d76fed2..c9c74c4dde8fa 100644
> --- a/rust/kernel/driver.rs
> +++ b/rust/kernel/driver.rs
[ ... ]
> @@ -325,117 +304,23 @@ pub trait Adapter {
[ ... ]
> - fn id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
[ ... ]
> + /// Returns the driver's private data from the matching entry of any of the ID tables, if any.
> + ///
> + /// If this returns `None`, it means that there is no match in any of the ID tables directly
> + /// associated with a [`device::Device`].
> + ///
> + /// # Safety
> + ///
> + /// The caller must ensure that the `dev` matched data is of type `Self::IdInfo`.
> + #[inline]
> + unsafe fn id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
> + // SAFETY: `dev` is guaranteed to be valid while it's alive, and so is `dev.as_raw()`.
> + let data = unsafe { bindings::device_get_match_data(dev.as_raw()) };
[Severity: High]
Does this introduce a potential NULL pointer dereference if dev->driver is
not set?
Previously, id_info() performed a table lookup that did not depend on the
device being bound to a driver. By switching to device_get_match_data(), the
underlying C implementations (such as of_device_get_match_data() or
acpi_device_get_match_data()) will unconditionally dereference dev->driver.
If a Rust driver calls Adapter::id_info() on a device::Device that is not
currently bound (for example, from a concurrent sysfs attribute or a
workqueue), could this lead to a panic?
Should this lifecycle precondition (that the device must be bound to a driver)
be explicitly documented in the # Safety contract to prevent unsoundness, or
should we ensure dev->driver is valid before calling this function?
> +
> + // SAFETY: Per safety requirement, `data` is of type `Self::IdInfo`.
> + unsafe { data.cast::<Self::IdInfo>().as_ref() }
> }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260629-id_info-v2-0-56fccbe9c5ef@garyguo.net?part=9
next prev parent reply other threads:[~2026-06-30 12:40 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 12:39 [PATCH v2 00/11] rust: driver: use pointers instead of indices for ID info Gary Guo
2026-06-29 12:39 ` [PATCH v2 01/11] rust: driver: remove `IdTable::id` Gary Guo
2026-06-30 12:40 ` sashiko-bot
2026-06-29 12:39 ` [PATCH v2 02/11] rust: driver: simplify `IdArray::new_without_index` Gary Guo
2026-06-30 12:40 ` sashiko-bot
2026-06-29 12:39 ` [PATCH v2 03/11] rust: pci: use `Option<&IdInfo>` for device ID info Gary Guo
2026-06-30 12:40 ` sashiko-bot
2026-06-29 12:39 ` [PATCH v2 04/11] rust: usb: " Gary Guo
2026-06-30 12:40 ` sashiko-bot
2026-06-29 12:39 ` [PATCH v2 05/11] rust: net/phy: remove expansion from doc Gary Guo
2026-06-30 12:40 ` sashiko-bot
2026-06-29 12:39 ` [PATCH v2 06/11] rust: driver: centralize device ID handling Gary Guo
2026-06-30 12:40 ` sashiko-bot
2026-06-29 12:39 ` [PATCH v2 07/11] rust: driver: remove `$module_table_name` from `module_device_table` Gary Guo
2026-06-30 12:40 ` sashiko-bot
2026-06-29 12:39 ` [PATCH v2 08/11] rust: driver: store pointers in `DeviceId` Gary Guo
2026-06-30 12:40 ` sashiko-bot
2026-06-29 12:39 ` [PATCH v2 09/11] rust: driver: remove open-coded matching logic Gary Guo
2026-06-30 12:40 ` sashiko-bot [this message]
2026-06-29 12:39 ` [PATCH v2 10/11] rust: driver: remove duplicate ID table Gary Guo
2026-06-30 12:40 ` sashiko-bot
2026-06-29 12:39 ` [PATCH v2 11/11] RFC: rust: driver: support map-like syntax for " Gary Guo
2026-06-30 12:40 ` sashiko-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=20260630124021.3E2281F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=acourbot@nvidia.com \
--cc=conor+dt@kernel.org \
--cc=dakr@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=linux-pci@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=robh@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.