devices: irqchip: rewrite if-let-else None with ?

Replace an else block that just returns None with the equivalent use of
the question mark operator, and rewrite the comment that used to be in
the else block to match.

Fixes the clippy warning "this if-let-else may be rewritten with the `?`
operator".

https://rust-lang.github.io/rust-clippy/master/index.html#question_mark

BUG=None
TEST=bin/clippy
TEST=cargo test -p devices

Change-Id: Ifda6d55c16e12fc7939343757d7f2843b4df9b27
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2885784
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
This commit is contained in:
Daniel Verkamp 2021-05-07 13:29:50 -07:00 committed by Commit Bot
parent 3638ae21f8
commit 34d2b36a42
2 changed files with 8 additions and 12 deletions

View file

@ -38,7 +38,6 @@ SUPPRESS=(
missing_safety_doc
needless_range_loop
option_map_unit_fn
question_mark
range_plus_one
redundant_closure
single_match

View file

@ -191,17 +191,14 @@ impl Pic {
/// Determines the external interrupt number that the PIC is prepared to inject, if any.
pub fn get_external_interrupt(&mut self) -> Option<u8> {
self.interrupt_request = false;
let irq_primary = if let Some(irq) = self.get_irq(PicSelect::Primary) {
irq
} else {
// The architecturally correct behavior in this case is to inject a spurious interrupt.
// Although this case only occurs as a result of a race condition where the interrupt
// might also be avoided entirely. Here we return `None` to avoid the interrupt
// entirely. The KVM unit test OS, which several unit tests rely upon, doesn't
// properly handle spurious interrupts. Also spurious interrupts are much more common
// in this code than real hardware because the hardware race is much much much smaller.
return None;
};
// If there is no interrupt request, return `None` to avoid the interrupt entirely.
// The architecturally correct behavior in this case is to inject a spurious interrupt.
// Although this case only occurs as a result of a race condition where the interrupt
// might also be avoided entirely. The KVM unit test OS, which several unit tests rely
// upon, doesn't properly handle spurious interrupts. Also spurious interrupts are much
// more common in this code than real hardware because the hardware race is much much much
// smaller.
let irq_primary = self.get_irq(PicSelect::Primary)?;
self.interrupt_ack(PicSelect::Primary, irq_primary);
let int_num = if irq_primary == PRIMARY_PIC_CASCADE_PIN {