mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-11 04:26:38 +00:00
devices: console: simplify handle_input()
Instead of handling special conditions by setting a variable and breaking from the loop into the error handling code, just return the right error code directly. BUG=None TEST=serial console input works. Change-Id: I02c9b8fd4bc64e4e0f16308d65cd05ace41c5756 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3565299 Reviewed-by: Junichi Uekawa <uekawa@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org> Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
This commit is contained in:
parent
566f42655e
commit
dba517d0ef
1 changed files with 5 additions and 17 deletions
|
@ -63,23 +63,17 @@ pub fn handle_input<I: SignalableInterrupt>(
|
|||
buffer: &mut VecDeque<u8>,
|
||||
receive_queue: &mut Queue,
|
||||
) -> result::Result<(), ConsoleError> {
|
||||
let mut exhausted_queue = false;
|
||||
|
||||
loop {
|
||||
let desc = match receive_queue.peek(mem) {
|
||||
Some(d) => d,
|
||||
None => {
|
||||
exhausted_queue = true;
|
||||
break;
|
||||
}
|
||||
};
|
||||
let desc = receive_queue
|
||||
.peek(mem)
|
||||
.ok_or(ConsoleError::RxDescriptorsExhausted)?;
|
||||
let desc_index = desc.index;
|
||||
// TODO(morg): Handle extra error cases as Err(ConsoleError) instead of just returning.
|
||||
let mut writer = match Writer::new(mem.clone(), desc) {
|
||||
Ok(w) => w,
|
||||
Err(e) => {
|
||||
error!("console: failed to create Writer: {}", e);
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -103,15 +97,9 @@ pub fn handle_input<I: SignalableInterrupt>(
|
|||
}
|
||||
|
||||
if bytes_written == 0 {
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
if exhausted_queue {
|
||||
Err(ConsoleError::RxDescriptorsExhausted)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Processes the data taken from the given transmit queue into the output sink.
|
||||
|
|
Loading…
Reference in a new issue