public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "pengfuyuan" <pengfuyuan@kylinos.cn>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J . Wysocki" <rafael@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] rust: device: add platdata accessors
Date: Thu, 08 Jan 2026 11:55:09 +0100	[thread overview]
Message-ID: <DFJ5ICRD3YFF.XCSV3CJCDORA@kernel.org> (raw)
In-Reply-To: <20260108085545.333676-1-pengfuyuan@kylinos.cn>

On Thu Jan 8, 2026 at 9:55 AM CET, pengfuyuan wrote:
> Implement generic accessors for the platform data of a device.

As Greg already mentioned, please provide provide a user for the API. Even an
RFC is fine for me as long as it is not too far from an upstreamable state and
the corresponding subsystem maintainers show willingness to take the code.

> Platform data is typically set by platform code when creating the device
> and points to platform-specific data structures. The accessor provides
> type-safe access to this data without requiring unsafe code at the call
> site.

That seems wrong; at least with the current implementation this method is unsafe
for two reasons:

  (1) The caller has to assert that T is in fact the type of the data set by the
      platform code.

  (2) T is (most likely) a C type, which does not guarantee that it is valid to
      create a reference, i.e. &T, of. For instance, it might not be properly
      initialized.

I think (1) is not fixable (at least as long as the platform code is in C), so
it unfortunately has to be unsafe.

As for (2), I'd just return an &Opaque<T> instead and then have an FFI wrapper
in the driver.

> The accessor is implemented for Device<Bound>, allowing drivers to access
> platform data during probe() and other device lifecycle callbacks. Unlike
> drvdata, platform data is managed by platform code and has a lifetime
> tied to the device itself.

I don't think this accessor has to be on Device<Bound>, as you say platform data
is always valid.

- Danilo

  parent reply	other threads:[~2026-01-08 10:55 UTC|newest]

Thread overview: 11+ 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 [this message]
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
  -- strict thread matches above, loose matches on Subject: below --
2026-01-08  7:42 [PATCH] " 1064094935
2026-01-08  7:57 ` Greg Kroah-Hartman
     [not found]   ` <tencent_7AC5B74D51D3BA562D760B2E583115A06B07@qq.com>
2026-01-08  9:09     ` Greg Kroah-Hartman

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=DFJ5ICRD3YFF.XCSV3CJCDORA@kernel.org \
    --to=dakr@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --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