Skip to content

Commit fc38b7f

Browse files
fujitaAndreas Hindborg
authored andcommitted
rust: time: Seal the HrTimerMode trait
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> Link: https://lore.kernel.org/r/20250617232806.3950141-1-fujita.tomonori@gmail.com Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
1 parent 69f66cf commit fc38b7f

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

rust/kernel/time/hrtimer.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,27 @@ impl HrTimerExpires for Delta {
444444
}
445445
}
446446

447+
mod private {
448+
use crate::time::ClockSource;
449+
450+
pub trait Sealed {}
451+
452+
impl<C: ClockSource> Sealed for super::AbsoluteMode<C> {}
453+
impl<C: ClockSource> Sealed for super::RelativeMode<C> {}
454+
impl<C: ClockSource> Sealed for super::AbsolutePinnedMode<C> {}
455+
impl<C: ClockSource> Sealed for super::RelativePinnedMode<C> {}
456+
impl<C: ClockSource> Sealed for super::AbsoluteSoftMode<C> {}
457+
impl<C: ClockSource> Sealed for super::RelativeSoftMode<C> {}
458+
impl<C: ClockSource> Sealed for super::AbsolutePinnedSoftMode<C> {}
459+
impl<C: ClockSource> Sealed for super::RelativePinnedSoftMode<C> {}
460+
impl<C: ClockSource> Sealed for super::AbsoluteHardMode<C> {}
461+
impl<C: ClockSource> Sealed for super::RelativeHardMode<C> {}
462+
impl<C: ClockSource> Sealed for super::AbsolutePinnedHardMode<C> {}
463+
impl<C: ClockSource> Sealed for super::RelativePinnedHardMode<C> {}
464+
}
465+
447466
/// Operational mode of [`HrTimer`].
448-
pub trait HrTimerMode {
467+
pub trait HrTimerMode: private::Sealed {
449468
/// The C representation of hrtimer mode.
450469
const C_MODE: bindings::hrtimer_mode;
451470

0 commit comments

Comments
 (0)