Re: [PATCH v4 5/6] rust: platform: add irq accessors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Jun 08, 2025 at 07:51:10PM -0300, Daniel Almeida wrote:
> +macro_rules! gen_irq_accessor {
> +    ($(#[$meta:meta])* $fn_name:ident, $reg_type:ident, $handler_trait:ident, index, $irq_fn:ident) => {
> +        $(#[$meta])*
> +        pub fn $fn_name<T: irq::$handler_trait + 'static>(
> +            &self,
> +            index: u32,
> +            flags: irq::flags::Flags,
> +            name: &'static CStr,
> +            handler: T,
> +        ) -> Result<impl PinInit<irq::$reg_type<T>, Error> + '_> {
> +            // SAFETY: `self.as_raw` returns a valid pointer to a `struct platform_device`.
> +            let irq = unsafe { bindings::$irq_fn(self.as_raw(), index) };
> +
> +            if irq < 0 {
> +                return Err(Error::from_errno(irq));
> +            }
> +
> +            Ok(irq::$reg_type::<T>::register(
> +                self.as_ref(),
> +                irq as u32,
> +                flags,
> +                name,
> +                handler,
> +            ))
> +        }
> +    };
> +
> +    ($(#[$meta:meta])* $fn_name:ident, $reg_type:ident, $handler_trait:ident, name, $irq_fn:ident) => {
> +        $(#[$meta])*
> +        pub fn $fn_name<T: irq::$handler_trait + 'static>(
> +            &self,
> +            name: &'static CStr,
> +            flags: irq::flags::Flags,
> +            handler: T,
> +        ) -> Result<impl PinInit<irq::$reg_type<T>, Error> + '_> {
> +            // SAFETY: `self.as_raw` returns a valid pointer to a `struct platform_device`.
> +            let irq = unsafe { bindings::$irq_fn(self.as_raw(), name.as_char_ptr()) };

Do we always want to force that this name is the same name as...

> +
> +            if irq < 0 {
> +                return Err(Error::from_errno(irq));
> +            }
> +
> +            Ok(irq::$reg_type::<T>::register(
> +                self.as_ref(),
> +                irq as u32,
> +                flags,
> +                name,

...this name?

> +                handler,
> +            ))
> +        }
> +    };
> +}

Please split this in two macros, define_request_irq_by_index!() and
define_request_irq_by_name!() and keep the order of arguments the same between
the two.




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux