Skip to content

uefi: Clean up some Status -> Result conversions #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions uefi/src/proto/network/pxe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ impl BaseCode {
false,
)
};
Result::from(status)?;

Ok(buffer_size)
status.into_with_val(|| buffer_size)
}

/// Reads a file located on a TFTP server.
Expand Down Expand Up @@ -193,9 +191,7 @@ impl BaseCode {
dont_use_buffer,
)
};
Result::from(status)?;

Ok(buffer_size)
status.into_with_val(|| buffer_size)
}

/// Writes to a file located on a TFTP server.
Expand Down Expand Up @@ -324,9 +320,7 @@ impl BaseCode {
false,
)
};
Result::from(status)?;

Ok(buffer_size)
status.into_with_val(|| buffer_size)
}

/// Reads a file located on a MTFTP server.
Expand Down Expand Up @@ -358,9 +352,7 @@ impl BaseCode {
dont_use_buffer,
)
};
Result::from(status)?;

Ok(buffer_size)
status.into_with_val(|| buffer_size)
}

/// Reads a directory listing of a directory on a MTFTP server.
Expand Down Expand Up @@ -530,9 +522,7 @@ impl BaseCode {
(&mut buffer[0] as *mut u8).cast(),
)
};
Result::from(status)?;

Ok(buffer_size)
status.into_with_val(|| buffer_size)
}

/// Updates the IP receive filters of a network device and enables software
Expand Down
15 changes: 5 additions & 10 deletions uefi/src/proto/network/snp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,14 @@ impl SimpleNetwork {
let mut stats_table: NetworkStats = Default::default();
let mut stats_size = core::mem::size_of::<NetworkStats>();
let status = (self.statistics)(self, false, Some(&mut stats_size), Some(&mut stats_table));
Result::from(status)?;
Ok(stats_table)
status.into_with_val(|| stats_table)
}

/// Convert a multicast IP address to a multicast HW MAC Address.
pub fn mcast_ip_to_mac(&self, ipv6: bool, ip: IpAddress) -> Result<MacAddress> {
let mut mac_address = MacAddress([0; 32]);
let status = (self.mcast_ip_to_mac)(self, ipv6, &ip, &mut mac_address);
Result::from(status)?;
Ok(mac_address)
status.into_with_val(|| mac_address)
}

/// Perform read operations on the NVRAM device attached to
Expand Down Expand Up @@ -194,17 +192,15 @@ impl SimpleNetwork {
pub fn get_interrupt_status(&self) -> Result<InterruptStatus> {
let mut interrupt_status = InterruptStatus::empty();
let status = (self.get_status)(self, Some(&mut interrupt_status), None);
Result::from(status)?;
Ok(interrupt_status)
status.into_with_val(|| interrupt_status)
}

/// Read the current recycled transmit buffer status from a
/// network interface.
pub fn get_recycled_transmit_buffer_status(&self) -> Result<Option<NonNull<u8>>> {
let mut tx_buf: *mut c_void = ptr::null_mut();
let status = (self.get_status)(self, None, Some(&mut tx_buf));
Result::from(status)?;
Ok(NonNull::new(tx_buf.cast()))
status.into_with_val(|| NonNull::new(tx_buf.cast()))
}

/// Place a packet in the transmit queue of a network interface.
Expand Down Expand Up @@ -249,8 +245,7 @@ impl SimpleNetwork {
dest_addr,
protocol,
);
Result::from(status)?;
Ok(buffer_size)
status.into_with_val(|| buffer_size)
}

/// Event that fires once a packet is available to be received.
Expand Down