misc: clippy: add if_not_else

This removes cognitive load when reading if statements.
All changes were applied by clippy via `--fix`.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
Philipp Schuster
2025-11-21 11:08:27 +01:00
committed by Rob Bradford
parent a0b72dce22
commit 0a07c96d17
16 changed files with 139 additions and 144 deletions

View File

@@ -111,10 +111,7 @@ impl CtrlQueue {
.memory()
.read_obj::<u64>(data_desc_addr)
.map_err(Error::GuestMemory)?;
if u32::from(ctrl_hdr.cmd) != VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET {
warn!("Unsupported command: {}", ctrl_hdr.cmd);
false
} else {
if u32::from(ctrl_hdr.cmd) == VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET {
let mut ok = true;
for tap in self.taps.iter_mut() {
info!("Reprogramming tap offload with features: {features}");
@@ -126,6 +123,9 @@ impl CtrlQueue {
.ok();
}
ok
} else {
warn!("Unsupported command: {}", ctrl_hdr.cmd);
false
}
}
_ => {

View File

@@ -80,16 +80,14 @@ fn open_tap_rx_q_0(
None => Tap::new(num_rx_q).map_err(Error::TapOpen)?,
};
// Don't overwrite ip configuration of existing interfaces:
if !tap_exists {
if let Some(ip) = ip_addr {
tap.set_ip_addr(ip, netmask)
.map_err(Error::TapSetIpNetmask)?;
}
} else {
if tap_exists {
warn!(
"Tap {} already exists. IP configuration will not be overwritten.",
if_name.unwrap_or_default()
);
} else if let Some(ip) = ip_addr {
tap.set_ip_addr(ip, netmask)
.map_err(Error::TapSetIpNetmask)?;
}
if let Some(mac) = host_mac {
tap.set_mac_addr(*mac).map_err(Error::TapSetMac)?;

View File

@@ -88,7 +88,9 @@ impl TxVirtio {
next_desc = desc_chain.next();
}
let len = if !iovecs.is_empty() {
let len = if iovecs.is_empty() {
0
} else {
// SAFETY: FFI call with correct arguments
let result = unsafe {
libc::writev(
@@ -119,8 +121,6 @@ impl TxVirtio {
self.counter_frames += Wrapping(1);
result as u32
} else {
0
};
// For the sake of simplicity (similar to the RX rate limiting), we always
@@ -230,7 +230,9 @@ impl RxVirtio {
next_desc = desc_chain.next();
}
let len = if !iovecs.is_empty() {
let len = if iovecs.is_empty() {
0
} else {
// SAFETY: FFI call with correct arguments
let result = unsafe {
libc::readv(
@@ -268,8 +270,6 @@ impl RxVirtio {
self.counter_frames += Wrapping(1);
result as u32
} else {
0
};
// For the sake of simplicity (keeping the handling of RX_QUEUE_EVENT and