Skip to contentSkip to conversation

rust: simplify `Adapter::id_info`

PATCH Superseded Onur Özkan 3 participants 8 messages Jun 25, 2025 – Jun 26, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Onur Özkan

author reviewer
#0 lore raw

PATCH 1/1 rust: simplify `Adapter::id_info`

It was obviously unnecessary to check if id is Some.

---
 rust/kernel/driver.rs | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
rust/kernel/driver.rs +1 -6
index ec9166cedfa7..1036755cb27d 100644
@@ -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
+        Self::of_id_info(dev)
     }
 }

--
2.50.0

maintainer
#1 lore raw
Quoted 12 lines · Onur Özkan

It was obviously unnecessary to check if id is Some.

---
 rust/kernel/driver.rs | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
rust/kernel/driver.rs +0 -0
index ec9166cedfa7..1036755cb27d 100644

rust/kernel/driver.rs fn of_id_info(_dev: &device::Device) -> Option<&'static Self::IdInfo> { · line 186

Quoted 9 lines
rust/kernel/driver.rs +0 -6
@@ -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/[email protected]/

Quoted 6 lines
rust/kernel/driver.rs +1 -1
+        Self::of_id_info(dev)
     }
 }
--

2.50.0

author reviewer
#2 lore raw
Quoted 26 lines · On Wed, 25 Jun 2025 10:22:48 +0200 Danilo Krummrich <[email protected]> wrote:
Quoted 16 lines · Onur Özkan

It was obviously unnecessary to check if id is Some.

---
 rust/kernel/driver.rs | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
rust/kernel/driver.rs +0 -0
index ec9166cedfa7..1036755cb27d 100644
@@ -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> {

rust/kernel/driver.rs fn of_id_info(_dev: &device::Device) -> Option<&'static Self::IdInfo> { · line 186

Quoted 6 lines
rust/kernel/driver.rs +0 -6
-        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. :)

Quoted 9 lines

[1]
https://lore.kernel.org/lkml/[email protected]/

Quoted 6 lines

+ 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))
}
maintainer
#3 lore raw
Quoted 11 lines · Onur

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)
}
Quoted 5 lines

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))
}

That's fair, can you please rebase your patch onto [1]?

[1] https://lore.kernel.org/lkml/[email protected]/

author reviewer
#4 lore raw
Quoted 14 lines · On Wed, 25 Jun 2025 10:39:47 +0200 Danilo Krummrich <[email protected]> wrote:
Quoted 13 lines · Onur

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:

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

That's fair, can you please rebase your patch onto [1]?

[1]
https://lore.kernel.org/lkml/[email protected]/

HEAD: e0b49ca268d4a0d2b97d5820420d5a78b67d2537 currently doesn't pass clippy. Should I send an additional change for the clippy fix or would you prefer to fix it yourself first?

Here is the output of make LLVM=1 -j $(nproc) CLIPPY=1:

```
  DESCEND objtool
  CALL    scripts/checksyscalls.sh
  INSTALL libsubcmd_headers
  CLIPPY L rust/kernel.o
error: unneeded `return` statement
   --> rust/kernel/driver.rs:188:13
    |
188 |             return None;
    |             ^^^^^^^^^^^
    |
    = help: for further information visit
https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
= note: `-D clippy::needless-return` implied by `-D warnings` = help:
to override `-D warnings` add `#[allow(clippy::needless_return)]` help:
remove `return` |
188 -             return None;
188 +             None
    |

error: aborting due to 1 previous error

make[2]: *** [rust/Makefile:538: rust/kernel.o] Error 1
make[1]: *** [/home/nimda/devspace/onur-ozkan/linux/Makefile:1280:
prepare] Error 2 make: *** [Makefile:248: __sub-make] Error 2
```
#5 lore raw
Quoted 4 lines · Onur

HEAD: e0b49ca268d4a0d2b97d5820420d5a78b67d2537 currently doesn't pass clippy. Should I send an additional change for the clippy fix or would you prefer to fix it yourself first?

Where is that commit coming from?

Thanks!

Cheers,
Miguel

maintainer
#6 lore raw
Quoted 5 lines · Miguel Ojeda
Quoted 4 lines · Onur

HEAD: e0b49ca268d4a0d2b97d5820420d5a78b67d2537 currently doesn't pass clippy. Should I send an additional change for the clippy fix or would you prefer to fix it yourself first?

Indeed, this is the case for #[cfg(not(CONFIG_OF))], I'm going to fix this up at my end when I apply the series. Don't worry about it.

Quoted 1 line

Where is that commit coming from?

https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=rust/acpi

It's a temporary branch containing patches that are staged for applying them to the driver-core tree.

#7 lore raw
Quoted 3 lines · Danilo Krummrich

It's a temporary branch containing patches that are staged for applying them to the driver-core tree.

Ah, that explains it -- I checked driver-core but didn't see anything there.

Thanks!

Cheers,
Miguel