Skip to content

Commit d8e7be6

Browse files
committed
spi: add and fix workspace lints
No functional changes. Signed-off-by: Manos Pitsidianakis <[email protected]>
1 parent 402f8e6 commit d8e7be6

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

vhost-device-spi/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ categories = ["virtualization"]
1010
license = "Apache-2.0 OR BSD-3-Clause"
1111
edition = "2021"
1212

13-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
13+
[lints]
14+
workspace = true
1415

1516
[features]
1617
xen = ["vm-memory/xen", "vhost/xen", "vhost-user-backend/xen"]

vhost-device-spi/src/linux_spi.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ ioctl_iow_nr!(SPI_IOC_WR_MODE32, 107, 5, u32);
5353

5454
// Corresponds to the SPI_IOC_MESSAGE macro in Linux
5555
pub fn spi_ioc_message(n: u32) -> u64 {
56-
let mut size: u32 = 0;
57-
if n * 32 < (1 << _IOC_SIZEBITS) {
58-
size = n * 32;
59-
}
60-
(SPI_IOC_MESSAGE_BASE | (size << _IOC_SIZESHIFT)) as u64
56+
let size = if n * 32 < (1 << _IOC_SIZEBITS) {
57+
n * 32
58+
} else {
59+
0
60+
};
61+
u64::from(SPI_IOC_MESSAGE_BASE | (size << _IOC_SIZESHIFT))
6162
}
6263

6364
bitflags! {

vhost-device-spi/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct SpiConfiguration {
7171

7272
impl SpiConfiguration {
7373
fn from(args: SpiArgs) -> Result<Self> {
74-
Ok(SpiConfiguration {
74+
Ok(Self {
7575
socket_path: args.socket_path,
7676
socket_count: args.socket_count.get(),
7777
device: args.device,

vhost-device-spi/src/spi.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ use crate::{linux_spi::*, vhu_spi::VirtioSpiConfig, virtio_spi::*};
2020

2121
type Result<T> = std::result::Result<T, Error>;
2222

23-
#[derive(Copy, Clone, Debug, PartialEq, ThisError)]
23+
#[derive(Copy, Clone, Debug, PartialEq, Eq, ThisError)]
2424
/// Errors related to low level spi helpers
25-
pub(crate) enum Error {
25+
pub enum Error {
2626
#[error("Ioctl command failed for {0} operation: {1}")]
2727
IoctlFailure(&'static str, IoError),
2828
#[error("Failed to open spi controller")]
2929
DeviceOpenFailed,
3030
}
3131

3232
/// SPI definitions
33-
pub(crate) struct SpiTransReq {
33+
pub struct SpiTransReq {
3434
pub tx_buf: Vec<u8>,
3535
pub rx_buf: Vec<u8>,
3636
pub trans_len: u32,
@@ -51,7 +51,7 @@ pub(crate) struct SpiTransReq {
5151
/// be used outside of this crate. The purpose of this trait is to provide a
5252
/// mock implementation for the SPI driver so that we can test the SPI
5353
/// functionality without the need of a physical device.
54-
pub(crate) trait SpiDevice {
54+
pub trait SpiDevice {
5555
/// Open the device specified by the controller path.
5656
fn open(path: &Path) -> Result<Self>
5757
where
@@ -85,13 +85,13 @@ pub(crate) trait SpiDevice {
8585
/// A physical SPI device. This structure can only be initialized on hosts
8686
/// where `/dev/spidevX.Y` is available.
8787
#[derive(Debug)]
88-
pub(crate) struct PhysDevice {
88+
pub struct PhysDevice {
8989
file: File,
9090
}
9191

9292
impl SpiDevice for PhysDevice {
9393
fn open(path: &Path) -> Result<Self> {
94-
Ok(PhysDevice {
94+
Ok(Self {
9595
file: OpenOptions::new()
9696
.read(true)
9797
.write(true)
@@ -206,6 +206,7 @@ impl SpiDevice for PhysDevice {
206206
}
207207
}
208208

209+
#[allow(clippy::cognitive_complexity)]
209210
fn detect_supported_features(&self) -> Result<VirtioSpiConfig> {
210211
// supported cs_max_number 1
211212
// can't set cs timing from userland in Linux, reserve cs timing as 0
@@ -468,20 +469,20 @@ impl SpiDevice for PhysDevice {
468469
}
469470

470471
#[derive(Debug)]
471-
pub(crate) struct SpiController<D: SpiDevice> {
472+
pub struct SpiController<D: SpiDevice> {
472473
device: D,
473474
config: VirtioSpiConfig,
474475
}
475476

476477
impl<D: SpiDevice> SpiController<D> {
477478
// Creates a new controller corresponding to `device`.
478-
pub(crate) fn new(device: D) -> Result<SpiController<D>> {
479+
pub(crate) fn new(device: D) -> Result<Self> {
479480
let config: VirtioSpiConfig = device.detect_supported_features()?;
480481

481-
Ok(SpiController { device, config })
482+
Ok(Self { device, config })
482483
}
483484

484-
pub(crate) fn config(&self) -> &VirtioSpiConfig {
485+
pub(crate) const fn config(&self) -> &VirtioSpiConfig {
485486
&self.config
486487
}
487488

vhost-device-spi/src/vhu_spi.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Result<T> = std::result::Result<T, Error>;
3838

3939
#[derive(Copy, Clone, Debug, Eq, PartialEq, ThisError)]
4040
/// Errors related to vhost-device-spi daemon.
41-
pub(crate) enum Error {
41+
pub enum Error {
4242
#[error("TX length {0} and RX length {1} don't match")]
4343
TxRxTrnasLenNotEqual(u32, u32),
4444
#[error("TX length and RX length are both zero")]
@@ -65,7 +65,7 @@ pub(crate) enum Error {
6565

6666
impl From<Error> for io::Error {
6767
fn from(e: Error) -> Self {
68-
io::Error::new(io::ErrorKind::Other, e)
68+
Self::new(io::ErrorKind::Other, e)
6969
}
7070
}
7171

@@ -113,9 +113,9 @@ struct VirtioSpiTransferResult {
113113
unsafe impl ByteValued for VirtioSpiTransferResult {}
114114

115115
/// Virtio SPI Configuration
116-
#[derive(Copy, Clone, Debug, Default, PartialEq)]
116+
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
117117
#[repr(C)]
118-
pub(crate) struct VirtioSpiConfig {
118+
pub struct VirtioSpiConfig {
119119
pub(crate) cs_max_number: u8,
120120
pub(crate) cs_change_supported: u8,
121121
pub(crate) tx_nbits_supported: u8,
@@ -133,7 +133,7 @@ pub(crate) struct VirtioSpiConfig {
133133
// reading its content from byte array.
134134
unsafe impl ByteValued for VirtioSpiConfig {}
135135

136-
pub(crate) struct VhostUserSpiBackend<D: SpiDevice> {
136+
pub struct VhostUserSpiBackend<D: SpiDevice> {
137137
spi_ctrl: Arc<SpiController<D>>,
138138
event_idx: bool,
139139
pub exit_event: EventFd,
@@ -144,7 +144,7 @@ type SpiDescriptorChain = DescriptorChain<GuestMemoryLoadGuard<GuestMemoryMmap<(
144144

145145
impl<D: SpiDevice> VhostUserSpiBackend<D> {
146146
pub fn new(spi_ctrl: Arc<SpiController<D>>) -> Result<Self> {
147-
Ok(VhostUserSpiBackend {
147+
Ok(Self {
148148
spi_ctrl,
149149
event_idx: false,
150150
exit_event: EventFd::new(EFD_NONBLOCK).map_err(|_| Error::EventFdFailed)?,
@@ -352,7 +352,7 @@ impl<D: SpiDevice> VhostUserSpiBackend<D> {
352352
status: ResponseStatus::TransErr as u8,
353353
};
354354

355-
for desc_chain in requests.clone() {
355+
for desc_chain in requests {
356356
let len = size_of::<VirtioSpiTransferResult>() as u32;
357357
let mem = atomic_mem.memory();
358358

0 commit comments

Comments
 (0)