From: "Boqun Feng" <boqun.feng@gmail.com>
To: "FUJITA Tomonori" <fujita.tomonori@gmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
alex.gaynor@gmail.com, "Miguel Ojeda" <ojeda@kernel.org>
Cc: "Alice Ryhl" <aliceryhl@google.com>,
"Anna-Maria Gleixner" <anna-maria@linutronix.de>,
bjorn3_gh@protonmail.com, "Danilo Krummrich" <dakr@kernel.org>,
"Frederic Weisbecker" <frederic@kernel.org>,
"Gary Guo" <gary@garyguo.net>, "John Stultz" <jstultz@google.com>,
linux-kernel@vger.kernel.org, lossin@kernel.org,
"Lyude Paul" <lyude@redhat.com>,
rust-for-linux@vger.kernel.org, "Stephen Boyd" <sboyd@kernel.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Trevor Gross" <tmgross@umich.edu>
Subject: Re: [PATCH] rust: time: Seal the HrTimerMode trait
Date: Wed, 18 Jun 2025 17:28:45 -0700 [thread overview]
Message-ID: <cdb12bc6-2372-43b3-b4e9-a1e31e5f9903@app.fastmail.com> (raw)
In-Reply-To: <20250617232806.3950141-1-fujita.tomonori@gmail.com>
On Tue, Jun 17, 2025, at 4:28 PM, FUJITA Tomonori wrote:
> Prevent downstream crates or drivers from implementing `HrTimerMode`
> for arbitrary types, which could otherwise leads to unsupported
> behavior.
>
> Introduce a `private::Sealed` trait and implement it for all types
> that implement `HrTimerMode`.
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Thanks!
Regards,
Boqun
> ---
> rust/kernel/time/hrtimer.rs | 21 ++++++++++++++++++++-
> 1 file changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
> index a6468bc50e57..0028720cb4e9 100644
> --- a/rust/kernel/time/hrtimer.rs
> +++ b/rust/kernel/time/hrtimer.rs
> @@ -442,8 +442,27 @@ fn into_nanos(self) -> i64 {
> }
> }
>
> +mod private {
> + use crate::time::ClockSource;
> +
> + pub trait Sealed {}
> +
> + impl<C: ClockSource> Sealed for super::AbsoluteMode<C> {}
> + impl<C: ClockSource> Sealed for super::RelativeMode<C> {}
> + impl<C: ClockSource> Sealed for super::AbsolutePinnedMode<C> {}
> + impl<C: ClockSource> Sealed for super::RelativePinnedMode<C> {}
> + impl<C: ClockSource> Sealed for super::AbsoluteSoftMode<C> {}
> + impl<C: ClockSource> Sealed for super::RelativeSoftMode<C> {}
> + impl<C: ClockSource> Sealed for super::AbsolutePinnedSoftMode<C> {}
> + impl<C: ClockSource> Sealed for super::RelativePinnedSoftMode<C> {}
> + impl<C: ClockSource> Sealed for super::AbsoluteHardMode<C> {}
> + impl<C: ClockSource> Sealed for super::RelativeHardMode<C> {}
> + impl<C: ClockSource> Sealed for super::AbsolutePinnedHardMode<C> {}
> + impl<C: ClockSource> Sealed for super::RelativePinnedHardMode<C> {}
> +}
> +
> /// Operational mode of [`HrTimer`].
> -pub trait HrTimerMode {
> +pub trait HrTimerMode: private::Sealed {
> /// The C representation of hrtimer mode.
> const C_MODE: bindings::hrtimer_mode;
>
>
> base-commit: 994393295c89711531583f6de8f296a30b0d944a
> --
> 2.43.0
next prev parent reply other threads:[~2025-06-19 0:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-17 23:28 FUJITA Tomonori
2025-06-19 0:28 ` Boqun Feng [this message]
2025-06-30 12:07 ` Andreas Hindborg
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=cdb12bc6-2372-43b3-b4e9-a1e31e5f9903@app.fastmail.com \
--to=boqun.feng@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=anna-maria@linutronix.de \
--cc=bjorn3_gh@protonmail.com \
--cc=dakr@kernel.org \
--cc=frederic@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=tglx@linutronix.de \
--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
all inboxes | Powered by JetHome®