]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gpu: nova-core: simplify and_then with condition to filter
authorEliot Courtney <ecourtney@nvidia.com>
Thu, 23 Apr 2026 07:11:44 +0000 (16:11 +0900)
committerAlice Ryhl <aliceryhl@google.com>
Mon, 27 Apr 2026 18:40:54 +0000 (18:40 +0000)
This code is more simply expressed using Option::filter instead of the
and_then with conditional.

This fixes the following warning with latest nightly Rust clippy build:

warning: manual implementation of `Option::filter`
   --> drivers/gpu/nova-core/firmware.rs:391:14
    |
391 |               .and_then(|hdr| {
    |  ______________^
392 | |                 if hdr.bin_magic == BIN_MAGIC {
393 | |                     Some(hdr)
394 | |                 } else {
...   |
397 | |             })
    | |______________^ help: try: `filter(|hdr| hdr.bin_magic == BIN_MAGIC)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter
    = note: `-D clippy::manual-filter` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::manual_filter)]`

Cc: stable@vger.kernel.org
Fixes: d6cb7319e64e ("gpu: nova-core: firmware: add support for common firmware header")
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/20260423-fix-filter-v1-1-b3b197c65daf@nvidia.com
[aliceryhl: add Fixes: tag and quote the warning it fixes]
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
drivers/gpu/nova-core/firmware.rs

index 6c2ab69cb605e641b355b58bdc83214295bc4f0b..3aac073efee2bbe3e5d70dbfdd776202a9a8b4ad 100644 (file)
@@ -388,13 +388,7 @@ impl<'a> BinFirmware<'a> {
             // Extract header.
             .and_then(BinHdr::from_bytes_copy)
             // Validate header.
-            .and_then(|hdr| {
-                if hdr.bin_magic == BIN_MAGIC {
-                    Some(hdr)
-                } else {
-                    None
-                }
-            })
+            .filter(|hdr| hdr.bin_magic == BIN_MAGIC)
             .map(|hdr| Self { hdr, fw })
             .ok_or(EINVAL)
     }