Skip to content

Commit

Permalink
kernel: process binary: simplify error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Mar 6, 2024
1 parent eb75ed0 commit ddf21e1
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions kernel/src/process_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,13 @@ impl ProcessBinary {
require_kernel_version: bool,
) -> Result<Self, ProcessBinaryError> {
// Get a slice for just the app header.
let header_flash = match app_flash.get(0..header_length) {
Some(h) => h,
None => return Err(ProcessBinaryError::NotEnoughFlash),
};
let header_flash = app_flash
.get(0..header_length)
.ok_or(ProcessBinaryError::NotEnoughFlash)?;

// Parse the full TBF header to see if this is a valid app. If the
// header can't parse, we will error right here.
let tbf_header = match tock_tbf::parse::parse_tbf_header(header_flash, tbf_version) {
Ok(h) => h,
Err(err) => return Err(err.into()),
};
let tbf_header = tock_tbf::parse::parse_tbf_header(header_flash, tbf_version)?;

// If this isn't an app (i.e. it is padding) then we can skip it and do
// not create a `ProcessBinary` object.
Expand Down Expand Up @@ -222,10 +218,9 @@ impl ProcessBinary {

// End of the portion of the application binary covered by integrity.
// Now handle footers.
let footer_region = match app_flash.get(binary_end..total_size) {
Some(f) => f,
None => return Err(ProcessBinaryError::NotEnoughFlash),
};
let footer_region = app_flash
.get(binary_end..total_size)
.ok_or(ProcessBinaryError::NotEnoughFlash)?;

// Check that the process is at the correct location in flash if the TBF
// header specified a fixed address. If there is a mismatch we catch
Expand Down

0 comments on commit ddf21e1

Please sign in to comment.