Re: [PATCH] rust: simplify `Adapter::id_info`

From: Onur
Date: Wed Jun 25 2025 - 04:44:40 EST


On Wed, 25 Jun 2025 10:22:48 +0200
Danilo Krummrich <dakr@xxxxxxxxxx> wrote:

> On Wed, Jun 25, 2025 at 07:36:30AM +0300, Onur Özkan wrote:
> > It was obviously unnecessary to check if `id` is `Some`.
> >
> > Signed-off-by: Onur Özkan <work@xxxxxxxxxxxxx>
> > ---
> > rust/kernel/driver.rs | 7 +------
> > 1 file changed, 1 insertion(+), 6 deletions(-)
> >
> > diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs
> > index ec9166cedfa7..1036755cb27d 100644
> > --- a/rust/kernel/driver.rs
> > +++ b/rust/kernel/driver.rs
> > @@ -178,11 +178,6 @@ fn of_id_info(_dev: &device::Device) ->
> > Option<&'static Self::IdInfo> { /// If this returns `None`, it
> > means that there is no match in any of the ID tables directly ///
> > associated with a [`device::Device`]. fn id_info(dev:
> > &device::Device) -> Option<&'static Self::IdInfo> {
> > - let id = Self::of_id_info(dev);
> > - if id.is_some() {
> > - return id;
> > - }
> > -
> > - None
>
> This was intentional, since I anticipated we'll get [1] eventually. :)
>
> [1]
> https://lore.kernel.org/lkml/20250620153914.295679-1-igor.korotin.linux@xxxxxxxxx/
>
> > + Self::of_id_info(dev)
> > }
> > }
> > --
> > 2.50.0
> >

Even with that, it can be something like this:

fn id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
let id = Self::acpi_id_info(dev);
if id.is_some() {
return id;
}

Self::of_id_info(dev)
}

or maybe even this:

fn id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
Self::acpi_id_info(dev).or_else(|| Self::of_id_info(dev))
}