Skip to content

Commit

Permalink
Fix errors reported by Clippy (part 2 - manual)
Browse files Browse the repository at this point in the history
Warnings that weren't fixed automatically by the previous are fixed by
this commit.

Signed-off-by: Costin Lupu <[email protected]>
  • Loading branch information
clupuishere committed Jan 8, 2024
1 parent 8f40182 commit d9354e1
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion driver-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
#![allow(missing_docs)]
#![allow(non_camel_case_types)]

mod bindings;
pub mod bindings;
pub use self::bindings::*;
2 changes: 1 addition & 1 deletion src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ mod tests {

const TMP_DIR_STR: &str = "./tmp_sock_dir";

fn unset_envvar(varname: &String) {
fn unset_envvar(varname: &str) {
unsafe {
libc::unsetenv(varname.as_ptr() as *const c_char);
};
Expand Down
2 changes: 1 addition & 1 deletion src/enclave_proc/connection_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ mod tests {
const THREADS_STR: &str = "Threads:";
const TMP_DIR: &str = "./npe";

fn unset_envvar(varname: &String) {
fn unset_envvar(varname: &str) {
unsafe { libc::unsetenv(varname.as_ptr() as *const c_char) };
}

Expand Down
8 changes: 4 additions & 4 deletions src/enclave_proc/resource_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl ResourceAllocator {
// Always allocate larger pages first, to reduce fragmentation and page count.
// Once an allocation of a given page size fails, proceed to the next smaller
// page size and retry.
for (_, page_info) in HUGE_PAGE_MAP.iter().enumerate() {
for page_info in HUGE_PAGE_MAP.iter() {
while needed_mem >= page_info.1 as i64 {
match MemoryRegion::new(page_info.0) {
Ok(value) => {
Expand All @@ -389,7 +389,7 @@ impl ResourceAllocator {
// need to allocate in increasing order of page size in order to reduce wastage).

if needed_mem > 0 {
for (_, page_info) in HUGE_PAGE_MAP.iter().rev().enumerate() {
for page_info in HUGE_PAGE_MAP.iter().rev() {
while needed_mem > 0 {
match MemoryRegion::new(page_info.0) {
Ok(value) => {
Expand Down Expand Up @@ -420,7 +420,7 @@ impl ResourceAllocator {
.sort_by(|reg1, reg2| reg2.mem_size.cmp(&reg1.mem_size));

needed_mem = self.requested_mem as i64;
for (_, region) in self.mem_regions.iter().enumerate() {
for region in self.mem_regions.iter() {
if needed_mem <= 0 {
break;
}
Expand All @@ -434,7 +434,7 @@ impl ResourceAllocator {
self.mem_regions.drain(split_index..);

// Generate a summary of the allocated memory.
for (_, region) in self.mem_regions.iter().enumerate() {
for region in self.mem_regions.iter() {
if let Some(page_count) = allocated_pages.get_mut(&region.mem_size) {
*page_count += 1;
} else {
Expand Down
13 changes: 6 additions & 7 deletions tests/test_dev_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use nitro_cli::enclave_proc::resource_manager::{
NE_START_ENCLAVE,
};
use nitro_cli::enclave_proc::utils::MiB;
use driver_bindings::bindings::ne_enclave_start_info;

const ENCLAVE_MEM_2MB_CHUNKS: u64 = 48;
#[cfg(target_arch = "aarch64")]
Expand Down Expand Up @@ -201,12 +202,12 @@ impl CheckDmesg {
];
let lines = self.get_dmesg_lines().unwrap();

for i in self.recorded_line..lines.len() {
let upper_line = lines[i].to_uppercase();
for line in lines.iter().skip(self.recorded_line) {
let upper_line = line.to_uppercase();
for word in checks.iter() {
if upper_line.contains(&word.to_uppercase()) {
return Err(NitroCliFailure::new()
.add_subaction(format!("Dmesg line: {} contains: {}", lines[i], word))
.add_subaction(format!("Dmesg line: {} contains: {}", line, word))
.set_error_code(NitroCliErrorEnum::IoctlFailure)
.set_file_and_line(file!(), line!()));
}
Expand Down Expand Up @@ -536,14 +537,12 @@ mod test_dev_driver {
assert!(result.is_ok());

// Start with an invalid flag.
let mut enclave_start_info = EnclaveStartInfo::default();
enclave_start_info.flags = 1234;
let enclave_start_info = ne_enclave_start_info { flags: 1234, ..Default::default() };
let result = enclave.start(enclave_start_info);
assert!(result.is_err());

// Start with an invalid CID.
let mut enclave_start_info = EnclaveStartInfo::default();
enclave_start_info.enclave_cid = VMADDR_CID_LOCAL as u64;
let mut enclave_start_info = ne_enclave_start_info { enclave_cid: VMADDR_CID_LOCAL as u64, ..Default::default() };
let result = enclave.start(enclave_start_info);
assert!(result.is_err());

Expand Down
2 changes: 1 addition & 1 deletion vsock_proxy/src/starter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn check_allowlist(
// Obtain the remote server's IP address.
let mut addrs = Proxy::parse_addr(remote_host, only_4, only_6)
.map_err(|err| format!("Could not parse remote address: {}", err))?;
let remote_addr = *addrs.get(0).ok_or("No IP address found")?;
let remote_addr = *addrs.first().ok_or("No IP address found")?;

for raw_service in services {
let addr = raw_service["address"].as_str().ok_or("No address field")?;
Expand Down

0 comments on commit d9354e1

Please sign in to comment.