public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: pengfuyuan <pengfuyuan@kylinos.cn>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 v2 1/1] rust: device: add platdata accessors
Date: Fri, 9 Jan 2026 12:08:05 +0100	[thread overview]
Message-ID: <2026010941-giddy-economic-d786@gregkh> (raw)
In-Reply-To: <20260109080528.478731-2-pengfuyuan@kylinos.cn>

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@kylinos.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

      reply	other threads:[~2026-01-09 11:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-08  8:55 [PATCH] rust: device: add platdata accessors pengfuyuan
2026-01-08  9:09 ` Greg Kroah-Hartman
2026-01-08 10:46 ` Miguel Ojeda
2026-01-08 10:55   ` Miguel Ojeda
2026-01-08 10:55 ` Danilo Krummrich
2026-01-09  8:05   ` [PATCH v2 v2 0/1] Implement generic accessors for the platform data of a device pengfuyuan
2026-01-09  8:05     ` [PATCH v2 v2 1/1] rust: device: add platdata accessors pengfuyuan
2026-01-09 11:08       ` Greg Kroah-Hartman [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=2026010941-giddy-economic-d786@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=pengfuyuan@kylinos.cn \
    --cc=rafael@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /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