From: "Danilo Krummrich" <dakr@kernel.org>
To: "Ke Sun" <sunke@kylinos.cn>
Cc: "Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"Greg KH" <gregkh@linuxfoundation.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>,
linux-rtc@vger.kernel.org, rust-for-linux@vger.kernel.org,
"Alvin Sun" <sk.alvin.x@gmail.com>
Subject: Re: [RFC PATCH v2 1/5] rtc: migrate driver data to RTC device
Date: Thu, 15 Jan 2026 00:48:59 +0100 [thread overview]
Message-ID: <DFOPQ45F1X6O.12KGJHFREKNED@kernel.org> (raw)
In-Reply-To: <f426f19d-a14c-4d9c-8587-2f7b4290024a@kylinos.cn>
On Thu Jan 15, 2026 at 12:23 AM CET, Ke Sun wrote:
> RTC ops callbacks receive struct device * as the first parameter.
> Traditionally this is rtc->dev.parent (the physical bus device), but Rust
> drivers store driver data on rtc->dev itself,
This is not only about Rust. Class device private data should be stored in the
driver_data field of the struct device embedded in the class device in general.
> so callbacks need &rtc->dev to access it.
Class device callbacks should just carry the class device itself, rather than
the embedded struct device.
> We considered switching all callbacks to use rtc->dev directly, but that would
> require modifying 182 RTC drivers and extensive testing/validation work.
I don't know if it's that bad, the change would be trivial. You just need to
repeat it pretty often. :) Tools like Coccinelle [1] can help a lot with such
refactorings.
> Instead, we propose an alternative approach:
>
> - Added RTC_OPS_USE_RTC_DEV flag (currently stored in rtc->features bitmap)
> - Created rtc_ops_dev() helper that returns &rtc->dev if flag is set,
> otherwise
> rtc->dev.parent. Default behavior (returning rtc->dev.parent) maintains
> backward compatibility
> - Updated all rtc->ops->callback call sites to use rtc_ops_dev(rtc)
Not sure if that intermediate step is needed, but it doesn't seem unreasonable
to me.
While eventually this is up to the RTC subsystem maintainer, from a driver-core
perspective this refactoring is encouraged:
Drivers should generally distinguish between stuff that is stored in the private
data of the bus device and private data of the class device, e.g. since they
have independent lifecycles and not all data might be relevant in all scopes.
Forcing drivers to also store the class device private data in the parent bus
device private data can be considered an anti-pattern.
[1] https://docs.kernel.org/dev-tools/coccinelle.html
next prev parent reply other threads:[~2026-01-14 23:49 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-07 14:37 [RFC PATCH v2 0/5] rust: Add RTC driver support Ke Sun
2026-01-07 14:37 ` [RFC PATCH v2 1/5] rtc: migrate driver data to RTC device Ke Sun
2026-01-07 14:41 ` Ke Sun
2026-01-07 16:12 ` Greg KH
2026-01-07 23:18 ` Ke Sun
2026-01-08 0:24 ` Ke Sun
2026-01-08 11:06 ` Danilo Krummrich
2026-01-08 5:46 ` Greg KH
2026-01-08 9:02 ` Ke Sun
2026-01-08 9:10 ` Greg KH
2026-01-08 11:12 ` Danilo Krummrich
2026-01-08 13:45 ` Ke Sun
2026-01-08 13:52 ` Danilo Krummrich
2026-01-08 14:01 ` Ke Sun
2026-01-08 14:01 ` Alexandre Belloni
2026-01-08 14:06 ` Danilo Krummrich
2026-02-20 23:19 ` Alexandre Belloni
2026-01-14 23:23 ` Ke Sun
2026-01-14 23:48 ` Danilo Krummrich [this message]
2026-01-07 14:37 ` [RFC PATCH v2 2/5] rust: add AMBA bus driver support Ke Sun
2026-01-08 11:29 ` Danilo Krummrich
2026-01-07 14:37 ` [RFC PATCH v2 3/5] rust: add device wakeup capability support Ke Sun
2026-01-07 14:57 ` Greg KH
2026-01-07 23:35 ` Ke Sun
2026-01-07 14:37 ` [RFC PATCH v2 4/5] rust: add RTC core abstractions and data structures Ke Sun
2026-01-08 11:50 ` Danilo Krummrich
2026-01-08 13:17 ` Ke Sun
2026-01-08 13:49 ` Miguel Ojeda
2026-01-08 13:56 ` Ke Sun
2026-01-08 23:31 ` Kari Argillander
2026-01-07 14:37 ` [RFC PATCH v2 5/5] rust: add PL031 RTC driver Ke Sun
2026-01-08 11:57 ` Danilo Krummrich
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=DFOPQ45F1X6O.12KGJHFREKNED@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-rtc@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sk.alvin.x@gmail.com \
--cc=sunke@kylinos.cn \
--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