On Sun May 17, 2026 at 1:01 AM BST, Danilo Krummrich wrote:
> Rename the generic lifetime parameter from 'a to 'bound in pci,
> platform, i2c and devres. This makes it explicit that the lifetime
> represents the device binding scope, consistent with the convention
> established by the HRT series.
>
> Signed-off-by: Danilo Krummrich <[email protected]>
> ---
>  rust/kernel/devres.rs   | 14 +++++++++-----
>  rust/kernel/i2c.rs      |  6 +++---
>  rust/kernel/pci/irq.rs  | 38 +++++++++++++++++++-------------------
>  rust/kernel/platform.rs | 18 +++++++++---------
>  4 files changed, 40 insertions(+), 36 deletions(-)
>
> diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs
> index ec63317665f4..58efe80474bd 100644
> --- a/rust/kernel/devres.rs
> +++ b/rust/kernel/devres.rs
> @@ -280,10 +280,11 @@ pub fn device(&self) -> &Device {
>          &self.dev
>      }
>  
> -    /// Obtain `&'a T`, bypassing the [`Revocable`].
> +    /// Obtain `&'bound T`, bypassing the [`Revocable`].
>      ///
> -    /// This method allows to directly obtain a `&'a T`, bypassing the 
> [`Revocable`], by presenting
> -    /// a `&'a Device<Bound>` of the same [`Device`] this [`Devres`] 
> instance has been created with.
> +    /// This method allows to directly obtain a `&'bound T`, bypassing the
> +    /// [`Revocable`], by presenting a `&'bound Device<Bound>` of the same
> +    /// [`Device`] this [`Devres`] instance has been created with.
>      ///
>      /// # Errors
>      ///
> @@ -316,7 +317,7 @@ pub fn device(&self) -> &Device {
>      ///     Ok(())
>      /// }
>      /// ```
> -    pub fn access<'a>(&'a self, dev: &'a Device<Bound>) -> Result<&'a T> {
> +    pub fn access<'bound>(&'bound self, dev: &'bound Device<Bound>) -> 
> Result<&'bound T> {
>          if self.dev.as_raw() != dev.as_raw() {
>              return Err(EINVAL);
>          }

For the same reason that I outlined in the other email, I think this should keep
the generic `'a` name as this is not the actual lifetime of `'bound`, just a
shortened one.

> @@ -338,7 +339,10 @@ pub fn try_access_with<R, F: FnOnce(&T) -> R>(&self, f: 
> F) -> Option<R> {
>      }
>  
>      /// [`Devres`] accessor for [`Revocable::try_access_with_guard`].
> -    pub fn try_access_with_guard<'a>(&'a self, guard: &'a rcu::Guard) -> 
> Option<&'a T> {
> +    pub fn try_access_with_guard<'bound>(
> +        &'bound self,
> +        guard: &'bound rcu::Guard,
> +    ) -> Option<&'bound T> {
>          self.data().try_access_with_guard(guard)
>      }
>  }
> diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs
> index 7b92d42a2b98..2bb7e54922e5 100644
> --- a/rust/kernel/i2c.rs
> +++ b/rust/kernel/i2c.rs
> @@ -566,11 +566,11 @@ unsafe impl Sync for I2cClient {}
>  
>  impl Registration {
>      /// The C `i2c_new_client_device` function wrapper for manual I2C client 
> creation.
> -    pub fn new<'a>(
> +    pub fn new<'bound>(
>          i2c_adapter: &I2cAdapter,
>          i2c_board_info: &I2cBoardInfo,
> -        parent_dev: &'a device::Device<device::Bound>,
> -    ) -> impl PinInit<Devres<Self>, Error> + 'a {
> +        parent_dev: &'bound device::Device<device::Bound>,
> +    ) -> impl PinInit<Devres<Self>, Error> + 'bound {

This really shouldn't be `'bound`. The lifetime here is just a technical one,
due to the reason `impl Trait` is used.

This whole function is conceptually

    pub init fn new(i2c_adapter: &I2cAdapter, i2c_board: &I2cboardInfo, 
parent_dev: &Device<Bound>) -> Result<DevRes<Self>, Error>;

and note that the lifetime does not appear anywhere.

If we follow the desugaring used by async, the desugared version is

    pub fn new<'init>(
        i2c_adapter: &'init I2cAdapter,
        i2c_board_info: &'init I2cBoardInfo,
        parent_dev: &'init device::Device<device::Bound>,
    ) -> impl PinInit<Devres<Self>, Error> + 'init {

Notably, the returned `PinInit` can (and should) capture all lifetime parameters
to the function so they can be used in the init process.

BTW, if you do need explicit bound lifetime, then it looks like

    pub fn new<'init, 'bound>(
        i2c_adapter: &'init I2cAdapter,
        i2c_board_info: &'init I2cBoardInfo,
        parent_dev: &'bound device::Device<device::Bound>,
    ) -> impl PinInit<Devres<Self>, Error> + 'init
    where
        'bound: 'init

Best,
Gary

Reply via email to