Skip to content

Commit 48ce8fc

Browse files
committed
Fix warnings; reformat code
1 parent 1410d2f commit 48ce8fc

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

src/lib/efivar/efi_variable_attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ pub fn parse_attributes<'a>(value: u32) -> HashSet<&'a EfiVariableAttribute> {
3333
if u32::from(*attr) & value != 0 {
3434
set.insert(*attr);
3535
}
36-
};
36+
}
3737
return set;
3838
}

src/lib/efivar/efivar/efi_variables.rs

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::efivarfs;
21
use crate::efi_variable_attributes::parse_attributes;
2+
use crate::efivarfs;
33
use crate::types::{EfiGuid, EfiVariable};
44
use crate::MIN_VAR_FILE_NAME_LEN;
55
use std::boxed::Box;
@@ -24,9 +24,12 @@ impl Default for EfiVariables {
2424
path: EFIVARS_PATH.into(),
2525
platform_size: 0,
2626
};
27-
variables.set_firmware_platform_size(
28-
EfiVariables::get_firmware_platform_size(EFIVARS_FW_PLATFORM_SZ_PATH.into()).unwrap(),
29-
);
27+
variables
28+
.set_firmware_platform_size(
29+
EfiVariables::get_firmware_platform_size(EFIVARS_FW_PLATFORM_SZ_PATH.into())
30+
.unwrap(),
31+
)
32+
.unwrap();
3033
return variables;
3134
}
3235
}
@@ -142,16 +145,20 @@ impl EfiVariables {
142145
.join("raw_var");
143146
let efi_variable = self.parse_payload(&full_path)?;
144147
if *efi_variable.name != *prefix {
145-
return Err::<EfiVariable, Box<dyn Error>>("Corrupt variable. Reported name does not match name".into());
148+
return Err::<EfiVariable, Box<dyn Error>>(
149+
"Corrupt variable. Reported name does not match name".into(),
150+
);
146151
}
147152
if efi_variable.guid != guid {
148-
return Err::<EfiVariable, Box<dyn Error>>("Corrupt variable. Reported guid does not match guid".into());
153+
return Err::<EfiVariable, Box<dyn Error>>(
154+
"Corrupt variable. Reported guid does not match guid".into(),
155+
);
149156
}
150157
return Ok(efi_variable);
151158
}
152159

153160
fn parse_payload(&self, var_path: &Path) -> Result<EfiVariable, Box<dyn Error>> {
154-
let mut handle = fs::File::open(var_path)?;
161+
let handle = fs::File::open(var_path)?;
155162
let mut buffer: Box<dyn EfiNVariableBuffer> = match self.platform_size {
156163
64 => {
157164
Ok(Box::new(Efi64VariableBuffer::try_from(handle)?) as Box<dyn EfiNVariableBuffer>)
@@ -173,7 +180,8 @@ impl EfiVariables {
173180
return None;
174181
})
175182
.collect::<Vec<u16>>(),
176-
)?.into();
183+
)?
184+
.into();
177185
let guid = EfiGuid::try_from(buffer.guid() as &[u8])?;
178186
let data_size: usize = match TryInto::<[u8; 8]>::try_into(buffer.data_size()) {
179187
Ok(v) => Ok::<usize, Box<dyn Error>>(usize::from_ne_bytes(v)),
@@ -182,7 +190,9 @@ impl EfiVariables {
182190
)?) as usize),
183191
}?;
184192
if data_size > 1024 {
185-
return Err::<EfiVariable, Box<dyn Error>>("Corrupt variable. Reported data size exceeds maximum".into());
193+
return Err::<EfiVariable, Box<dyn Error>>(
194+
"Corrupt variable. Reported data size exceeds maximum".into(),
195+
);
186196
}
187197
let data: Vec<u8> = buffer.data()[0..data_size].into();
188198
let status: usize = match TryInto::<[u8; 8]>::try_into(buffer.status()) {
@@ -192,9 +202,13 @@ impl EfiVariables {
192202
)?) as usize),
193203
}?;
194204
if status != 0 {
195-
return Err::<EfiVariable, Box<dyn Error>>(format!("Variable read error. Unexpected status code {}", status).into());
205+
return Err::<EfiVariable, Box<dyn Error>>(
206+
format!("Variable read error. Unexpected status code {}", status).into(),
207+
);
196208
}
197-
let attributes = parse_attributes(u32::from_ne_bytes(TryInto::<[u8; 4]>::try_into(buffer.attributes())?));
209+
let attributes = parse_attributes(u32::from_ne_bytes(TryInto::<[u8; 4]>::try_into(
210+
buffer.attributes(),
211+
)?));
198212

199213
return Ok(EfiVariable {
200214
name,
@@ -205,12 +219,17 @@ impl EfiVariables {
205219
}
206220

207221
fn set_firmware_platform_size(&mut self, size: usize) -> Result<(), Box<dyn Error>> {
208-
match size {
209-
64 => Ok(self.platform_size = 64),
210-
32 => Ok(self.platform_size = 32),
211-
_ => Err(format!("Unsupported platform size: {}", size)),
222+
return match size {
223+
64 => {
224+
self.platform_size = 64;
225+
Ok(())
226+
}
227+
32 => {
228+
self.platform_size = 32;
229+
Ok(())
230+
}
231+
_ => Err(format!("Unsupported platform size: {}", size).into()),
212232
};
213-
return Ok(());
214233
}
215234

216235
fn get_firmware_platform_size(path: &str) -> Result<usize, Box<dyn Error>> {
@@ -219,7 +238,7 @@ impl EfiVariables {
219238
Ok(chars) => {
220239
let ws_index = match chars.find(char::is_whitespace) {
221240
Some(index) => index,
222-
None => chars.len()
241+
None => chars.len(),
223242
};
224243
Ok(usize::from_str_radix(&chars[0..ws_index], 10)?)
225244
}

src/lib/efivar/efivarfs/efi_variables.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use crate::types::{EfiGuid, EfiVariable};
21
use crate::efi_variable_attributes::parse_attributes;
2+
use crate::types::{EfiGuid, EfiVariable};
3+
use crate::MIN_VAR_FILE_NAME_LEN;
34
use std::fs::{self, ReadDir};
45
use std::io;
56
use std::path::PathBuf;
6-
use crate::MIN_VAR_FILE_NAME_LEN;
77

88
const EFIVARFS_PATH: &'static str = "/sys/firmware/efi/efivars";
99

@@ -115,7 +115,8 @@ impl EfiVariables {
115115
Err(_) => {
116116
return Err(io::ErrorKind::InvalidInput.into());
117117
}
118-
}.unwrap();
118+
}
119+
.unwrap();
119120
let prefix = &name[MIN_VAR_FILE_NAME_LEN - 1..];
120121
let full_path = self.path.join(String::new() + prefix + &"-" + guid_bytes);
121122
let bytes: Vec<u8> = match fs::read(full_path) {

0 commit comments

Comments
 (0)