rust: simplify `Adapter::id_info`
Subsystems (2)
Onur Özkan
reviewerPATCH 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
@@ -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 <&'staticSelf ::IdInfo > { -let id =Self ::of_id_info (dev); -if id.is_some () { -return id; - } - -None +Self ::of_id_info (dev) } }
--
2.50.0
Danilo Krummrich
maintainerQuoted 12 lines · Onur Özkan
It was obviously unnecessary to check if
idisSome.Signed-off-by Onur Özkan <[email protected]>--- rust/kernel/driver.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)rust/kernel/driver.rs +0
-0
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 <&'staticSelf ::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. :)
Quoted 6 lines
rust/kernel/driver.rs +1
-1+Self ::of_id_info (dev) } } --2.50.0
Onur
reviewerQuoted 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
idisSome.Signed-off-by Onur Özkan <[email protected]>--- rust/kernel/driver.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)rust/kernel/driver.rs +0
-0@@ -178,11 +178,6 @@ fn of_id_info(_dev: &device::Device) ->Option<&'static
Self::IdInfo> { /// If this returnsNone, 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<&'staticSelf::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))
}Danilo Krummrich
maintainerQuoted 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]?
Onur
reviewerQuoted 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]?
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
```Quoted 4 lines · Onur
HEAD:
e0b49ca268d4a0d2b97d5820420d5a78b67d2537currently 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
Danilo Krummrich
maintainerQuoted 5 lines · Miguel Ojeda
Quoted 4 lines · Onur
HEAD:
e0b49ca268d4a0d2b97d5820420d5a78b67d2537currently 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.
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