[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <D8A2W9JIGFX3.20YC7NQRET0XG@proton.me>
Date: Fri, 07 Mar 2025 13:46:32 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Andreas Hindborg <a.hindborg@...nel.org>
Cc: Miguel Ojeda <ojeda@...nel.org>, Anna-Maria Behnsen <anna-maria@...utronix.de>, Frederic Weisbecker <frederic@...nel.org>, Thomas Gleixner <tglx@...utronix.de>, Danilo Krummrich <dakr@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>, Lyude Paul <lyude@...hat.com>, Guangbo Cui <2407018371@...com>, Dirk Behme <dirk.behme@...il.com>, Daniel Almeida <daniel.almeida@...labora.com>, Tamir Duberstein <tamird@...il.com>, Markus Elfring <Markus.Elfring@....de>, rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v10 01/13] rust: hrtimer: introduce hrtimer support
On Fri Mar 7, 2025 at 2:10 PM CET, Andreas Hindborg wrote:
> "Benno Lossin" <benno.lossin@...ton.me> writes:
>> On Fri Mar 7, 2025 at 11:11 AM CET, Andreas Hindborg wrote:
>>> +/// Use to implement the [`HasHrTimer<T>`] trait.
>>> +///
>>> +/// See [`module`] documentation for an example.
>>> +///
>>> +/// [`module`]: crate::time::hrtimer
>>> +#[macro_export]
>>> +macro_rules! impl_has_hr_timer {
>>> + (
>>> + impl$({$($generics:tt)*})?
>>> + HasHrTimer<$timer_type:ty>
>>> + for $self:ty
>>> + { self.$field:ident }
>>> + $($rest:tt)*
>>> + ) => {
>>> + // SAFETY: This implementation of `raw_get_timer` only compiles if the
>>> + // field has the right type.
>>> + unsafe impl$(<$($generics)*>)? $crate::time::hrtimer::HasHrTimer<$timer_type> for $self {
>>> +
>>> + #[inline]
>>> + unsafe fn raw_get_timer(this: *const Self) ->
>>> + *const $crate::time::hrtimer::HrTimer<$timer_type>
>>> + {
>>> + // SAFETY: The caller promises that the pointer is not dangling.
>>> + unsafe {
>>> + ::core::ptr::addr_of!((*this).$field)
>>> + }
>>> + }
>>> +
>>> + #[inline]
>>> + unsafe fn timer_container_of(ptr: *mut $crate::time::hrtimer::HrTimer<$timer_type>) ->
>>> + *mut Self
>>
>> This formatting looks a bit weird, (macro formatting is annoying, I
>> know).
>
> How would you change it?
Just use `rustfmt` (copy the macro arm, replace all `$` with `_` in
names and remove repetitions, `rustfmt` and then revert. You're lucky,
since you only have one repetition that doesn't cause the line to go
over the 100 column threshold):
// SAFETY: This implementation of `raw_get_timer` only compiles if the
// field has the right type.
unsafe impl$(<$($generics)*>)? $crate::time::hrtimer::HasHrTimer<$timer_type> for $self {
#[inline]
unsafe fn raw_get_timer(
this: *const Self,
) -> *const $crate::time::hrtimer::HrTimer<$timer_type> {
// SAFETY: The caller promises that the pointer is not dangling.
unsafe { ::core::ptr::addr_of!((*this).$field) }
}
#[inline]
unsafe fn timer_container_of(
ptr: *mut $crate::time::hrtimer::HrTimer<$timer_type>,
) -> *mut Self {
// SAFETY: As per the safety requirement of this function, `ptr`
// is pointing inside a `$timer_type`.
unsafe { ::kernel::container_of!(ptr, $timer_type, $field).cast_mut() }
}
}
---
Cheers,
Benno
Powered by blists - more mailing lists