rust: Apply clippy fixes to format strings

Makes the code easier to read.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2025-10-28 15:29:16 +01:00
committed by Jan Höppner
parent a1126352ec
commit b766d4a53c
13 changed files with 31 additions and 41 deletions

View File

@@ -162,7 +162,7 @@ impl Display for MsaLevel {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "{} ", self.msa_level)?;
match self.stfle_bit {
Some(bit) => write!(f, "STFLE bit [ {:>3} ] : ", bit)?,
Some(bit) => write!(f, "STFLE bit [ {bit:>3} ] : ")?,
None => write!(f, " : ")?,
}
match self.enabled {

View File

@@ -304,8 +304,7 @@ pub enum BindState {
/// an error string. Does NOT print any error messages.
pub fn get_apqn_bind_state(card: u32, dom: u32) -> Result<BindState> {
let path = format!(
"{}/card{:02x}/{:02x}.{:04x}/se_bind",
PATH_SYS_DEVICES_AP, card, card, dom
"{PATH_SYS_DEVICES_AP}/card{card:02x}/{card:02x}.{dom:04x}/se_bind"
);
let state_str = read_file_string(path, "se_bind attribute")?;
let state = state_str.trim();
@@ -332,8 +331,7 @@ pub fn get_apqn_bind_state(card: u32, dom: u32) -> Result<BindState> {
pub fn set_apqn_bind_state(card: u32, dom: u32, state: BindState) -> Result<()> {
let ctx = "bind APQN";
let path = format!(
"{}/card{:02x}/{:02x}.{:04x}/se_bind",
PATH_SYS_DEVICES_AP, card, card, dom
"{PATH_SYS_DEVICES_AP}/card{card:02x}/{card:02x}.{dom:04x}/se_bind"
);
match state {
BindState::Bound => write_file(path, 1.to_string(), ctx),
@@ -375,8 +373,7 @@ pub enum AssocState {
/// an error string. Does NOT print any error messages.
pub fn get_apqn_associate_state(card: u32, dom: u32) -> Result<AssocState> {
let path = format!(
"{}/card{:02x}/{:02x}.{:04x}/se_associate",
PATH_SYS_DEVICES_AP, card, card, dom
"{PATH_SYS_DEVICES_AP}/card{card:02x}/{card:02x}.{dom:04x}/se_associate"
);
let state_str = read_file_string(path, "se_associate attribute")?;
let state = state_str.trim();
@@ -393,8 +390,7 @@ pub fn get_apqn_associate_state(card: u32, dom: u32) -> Result<AssocState> {
fn set_apqn_associate_state_associate(card: u32, dom: u32, idx: u16) -> Result<()> {
let path = format!(
"{}/card{:02x}/{:02x}.{:04x}/se_associate",
PATH_SYS_DEVICES_AP, card, card, dom
"{PATH_SYS_DEVICES_AP}/card{card:02x}/{card:02x}.{dom:04x}/se_associate"
);
write_file(path, idx.to_string(), "associate APQN")?;
let mut ms: u64 = 0;
@@ -423,8 +419,7 @@ fn set_apqn_associate_state_associate(card: u32, dom: u32, idx: u16) -> Result<(
fn set_apqn_associate_state_unbind(card: u32, dom: u32) -> Result<()> {
let bindpath = format!(
"{}/card{:02x}/{:02x}.{:04x}/se_bind",
PATH_SYS_DEVICES_AP, card, card, dom
"{PATH_SYS_DEVICES_AP}/card{card:02x}/{card:02x}.{dom:04x}/se_bind"
);
write_file(bindpath, 0.to_string(), "unbind APQN")?;
let mut ms: u64 = 0;

View File

@@ -127,8 +127,7 @@ impl ApqnList {
Ok(r) => r,
Err(err) => {
eprintln!(
"Failure reading AP devices {} ({:?}).",
PATH_SYS_DEVICES_AP, err
"Failure reading AP devices {PATH_SYS_DEVICES_AP} ({err:?})."
);
return None;
}
@@ -139,8 +138,7 @@ impl ApqnList {
Ok(r) => r,
Err(err) => {
eprintln!(
"Failure reading AP queue directories in {} ({:?}).",
path, err
"Failure reading AP queue directories in {path} ({err:?})."
);
return None;
}
@@ -209,7 +207,7 @@ impl ApqnList {
continue;
}
if i1.mkvp == i2.mkvp {
eprintln!("APQN {} and APQN {} have same MPVK", a1, a2);
eprintln!("APQN {a1} and APQN {a2} have same MPVK");
return false;
}
}

View File

@@ -143,7 +143,7 @@ impl ApConfigEntry {
self.mode = mode;
self.validate_accel_entry()?;
}
_ => return Err(format!("Unknown or invalid mode '{}'.", mode)),
_ => return Err(format!("Unknown or invalid mode '{mode}'.")),
}
Ok(())
}
@@ -176,16 +176,14 @@ impl ApConfigList {
Ok(f) => f,
Err(err) => {
return Err(format!(
"Failure to open AP config file {}: {:?}",
fname, err
"Failure to open AP config file {fname}: {err:?}"
))
}
};
match serde_yaml::from_reader(file) {
Ok(cfg) => Ok(cfg),
Err(err) => Err(format!(
"Failure parsing AP config file {}: {:?}",
fname, err
"Failure parsing AP config file {fname}: {err:?}"
)),
}
}
@@ -195,10 +193,10 @@ impl ApConfigList {
let ename = if !entry.name.trim().is_empty() {
format!("AP config entry {} '{}'", i, entry.name.trim())
} else {
format!("AP config entry {}", i)
format!("AP config entry {i}")
};
if let Err(err) = &entry.validate() {
return Err(format!("{}: {}", ename, err));
return Err(format!("{ename}: {err}"));
}
}
Ok(())

View File

@@ -103,8 +103,7 @@ fn main() -> ExitCode {
};
if apconfig.is_empty() {
println!(
"No AP configuration entries in config file '{}': Nothing to do.",
configfile
"No AP configuration entries in config file '{configfile}': Nothing to do."
);
return ExitCode::SUCCESS;
}
@@ -382,7 +381,7 @@ fn do_ap_config(
if let Err(err) = apqn.set_bind_state(pvap::bind_state::Bound) {
// bind failed, unbind/reset this apqn, return with failure
let _ = apqn.set_bind_state(pvap::bind_state::Unbound);
return Err(format!("Failure binding APQN {}: {}", apqn, err));
return Err(format!("Failure binding APQN {apqn}: {err}"));
}
}
// try to associate
@@ -662,6 +661,6 @@ mod tests {
let r = do_ap_config(&mut apqnlist, &secretlist, &apcfglist, true);
assert!(r.is_ok());
let n = r.unwrap();
assert!(n == 3, "n = {} != 3", n);
assert!(n == 3, "n = {n} != 3");
}
}

View File

@@ -52,7 +52,7 @@ pub fn has_list_secrets_facility() -> Result<(), String> {
/// The list may be empty if the UV doesn't have any secrets stored.
pub fn gather_secrets() -> Result<SecretList, String> {
let uv = match UvDevice::open() {
Err(e) => return Err(format!("Failed to open UV device: {:?}.", e)),
Err(e) => return Err(format!("Failed to open UV device: {e:?}.")),
Ok(u) => u,
};
let mut cmd = ListCmd::default();

View File

@@ -44,15 +44,15 @@ impl Display for AttestationResult<'_> {
writeln!(f, "{:#}", self.cuid)?;
if let Some(data) = &self.add {
writeln!(f, "Additional-data:")?;
writeln!(f, "{:#}", data)?;
writeln!(f, "{data:#}")?;
}
if let Some(data) = &self.add_fields {
writeln!(f, "Additional-data content:")?;
writeln!(f, "{:#}", data)?;
writeln!(f, "{data:#}")?;
}
if let Some(data) = &self.user_data {
writeln!(f, "user-data:")?;
writeln!(f, "{:#}", data)?;
writeln!(f, "{data:#}")?;
}
Ok(())
}

View File

@@ -123,8 +123,7 @@ pub fn host_key_check<'a, 'b>(
}) {
Some(phkh) => contains_phkh(&hkd_hashes, phkh, kind, check_enforced),
None if check_enforced => CheckState::Err(format!(
"The Attestation result does not contain an {}, but checking was enabled.",
kind
"The Attestation result does not contain an {kind}, but checking was enabled."
)),
None => CheckState::Data(HostKeyCheck::default()),
};

View File

@@ -1,5 +1,7 @@
#![allow(missing_docs)]
use std::{fs::File, io::Write, path::PathBuf};
use anyhow::Context;
use clap::{Parser, ValueEnum, ValueHint};
use log::info;
@@ -14,7 +16,6 @@ use pvimg::{
UvDataPlainTrait, UvDataTrait,
},
};
use std::{fs::File, io::Write, path::PathBuf};
use utils::{PvLogger, VerbosityOptions};
#[derive(Parser, Debug)]
@@ -139,7 +140,7 @@ fn main() -> anyhow::Result<()> {
Ok(_) => (),
Err(err) => {
std::fs::remove_file(&opt.outfile)?;
panic!("Could not seek SE header: {}", err);
panic!("Could not seek SE header: {err}");
}
};

View File

@@ -150,7 +150,7 @@ impl Layout {
}
if let Some(overlapped) = self.overlaps(&interval) {
let msg = format!("{} ... {}", overlapped, interval);
let msg = format!("{overlapped} ... {interval}");
return Err(Error::IntervalOverlap(msg));
}

View File

@@ -145,7 +145,7 @@ impl<T: ControlFlagTrait> ControlFlagsTrait for ControlFlags<T> {
impl<T: ControlFlagTrait> Display for ControlFlags<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let value: u64 = self.flags.into();
write!(f, "{:#018x}", value)
write!(f, "{value:#018x}")
}
}
@@ -266,7 +266,7 @@ mod test {
#[test]
fn test_display() {
let flags = PlaintextControlFlagsV1::from_flags([PcfV1::NoComponentEncryption.enabled()]);
assert_eq!("0x0000000010000000", format!("{}", flags));
assert_eq!("0x0000000010000000", format!("{flags}"));
let flags = PlaintextControlFlagsV1::from_flags([
PcfV1::AllowDumping.enabled(),
@@ -277,7 +277,7 @@ mod test {
PcfV1::PckmoEcc.enabled(),
PcfV1::PckmoHmac.enabled(),
]);
assert_eq!("0x00000000300000f2", format!("{}", flags));
assert_eq!("0x00000000300000f2", format!("{flags}"));
}
#[test]

View File

@@ -25,7 +25,7 @@ pub fn ser_lower_hex<S: Serializer, B: LowerHex>(
data: &B,
ser: S,
) -> std::result::Result<S::Ok, S::Error> {
format!("{:#018x}", data).serialize(ser)
format!("{data:#018x}").serialize(ser)
}
pub fn ser_hex_confidential<S: Serializer, const COUNT: usize>(

View File

@@ -48,7 +48,7 @@ impl Display for HexSlice<'_> {
if f.sign_minus() && f.alternate() {
write!(f, "0x")?;
}
write!(f, "{:0>2x}", byte)?;
write!(f, "{byte:0>2x}")?;
if f.sign_minus() {
write!(f, " ")?;
}