lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <2026010941-giddy-economic-d786@gregkh>
Date: Fri, 9 Jan 2026 12:08:05 +0100
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: pengfuyuan <pengfuyuan@...inos.cn>
Cc: "Rafael J . Wysocki" <rafael@...nel.org>,
	Danilo Krummrich <dakr@...nel.org>, Miguel Ojeda <ojeda@...nel.org>,
	Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
	Björn Roy Baron <bjorn3_gh@...tonmail.com>,
	Benno Lossin <lossin@...nel.org>,
	Andreas Hindborg <a.hindborg@...nel.org>,
	Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
	rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 v2 1/1] rust: device: add platdata accessors

On Fri, Jan 09, 2026 at 04:05:28PM +0800, pengfuyuan wrote:
> Implement generic accessors for the platform data of a device.

There is only one "accessor" being added here.

> Platform data is typically set by platform code when creating the device (e.g.
> via `platform_device_add_data()`). Drivers may use it to obtain per-device,
> platform-provided configuration.

No rust binding to set this?  Who would be setting this data but not
reading it?  Or can you already call platform_device_add_data() from a
rust driver?

> The accessor is `unsafe` because the caller must ensure that the chosen `T`
> matches the actual object referenced by `platform_data`.
> 
> Platform data is generally a C type, so the method returns `&Opaque<T>` to
> avoid creating a Rust reference to potentially uninitialised or otherwise
> invalid C data. Drivers can then perform the FFI dereference behind an explicit
> `unsafe` block.
> 
> The method is implemented for `Device<Ctx>` so it is available in all device
> states. If no platform data is present, `-ENOENT` is returned.
> 
> Signed-off-by: pengfuyuan <pengfuyuan@...inos.cn>
> ---
>  rust/kernel/device.rs | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
> index c79be2e2bfe3..90ccc433dfe7 100644
> --- a/rust/kernel/device.rs
> +++ b/rust/kernel/device.rs
> @@ -483,6 +483,37 @@ pub fn fwnode(&self) -> Option<&property::FwNode> {
>          // defined as a `#[repr(transparent)]` wrapper around `fwnode_handle`.
>          Some(unsafe { &*fwnode_handle.cast() })
>      }
> +
> +    /// Access the platform data for this device.
> +    ///
> +    /// Platform data is typically set by platform code when creating the device and is expected
> +    /// to remain valid while the device is alive.
> +    ///
> +    /// Returns a reference to the opaque platform data, or [`ENOENT`] if no platform data
> +    /// is set.
> +    ///
> +    /// # Safety
> +    ///
> +    /// Callers must ensure that:
> +    /// - If platform data is set (i.e., `platform_data` is not null), the pointer points to valid,
> +    ///   properly aligned storage for `T` and remains valid for the lifetime of the returned
> +    ///   reference.
> +    /// - The type `T` matches the type of the platform data structure set by platform code.
> +    pub unsafe fn platdata<T>(&self) -> Result<&Opaque<T>> {
> +        // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`.
> +        let ptr = unsafe { (*self.as_raw()).platform_data };

Why isn't dev_get_platdata() being used here?

Also, we still need to see a user of this before we can properly review
it.

thanks,

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ