Skip to content

Commit 9f2eac0

Browse files
authored
fix(breaking): clippy lints (#18)
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
1 parent 7bcba86 commit 9f2eac0

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

src/capability/msi.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ impl MsiCapability {
8383
}
8484

8585
pub fn ctrl(&self, access: &impl ConfigRegionAccess) -> u32 {
86-
let reg = unsafe { access.read(self.address.address, self.address.offset) };
87-
reg
86+
unsafe { access.read(self.address.address, self.address.offset) }
8887
}
8988

9089
/// Is MSI capability enabled?

src/lib.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,19 @@ pub type InterruptPin = u8;
7676
// TODO: documentation
7777
pub trait ConfigRegionAccess {
7878
fn function_exists(&self, address: PciAddress) -> bool;
79+
80+
/// Performs a PCI read at `address` with `offset`.
81+
///
82+
/// # Safety
83+
///
84+
/// `address` and `offset` must be valid for PCI reads.
7985
unsafe fn read(&self, address: PciAddress, offset: u16) -> u32;
86+
87+
/// Performs a PCI write at `address` with `offset`.
88+
///
89+
/// # Safety
90+
///
91+
/// `address` and `offset` must be valid for PCI writes.
8092
unsafe fn write(&self, address: PciAddress, offset: u16, value: u32);
8193
}
8294

@@ -288,7 +300,7 @@ impl EndpointHeader {
288300
/*
289301
* If bit 0 is `0`, the BAR is in memory. If it's `1`, it's in I/O.
290302
*/
291-
if bar.get_bit(0) == false {
303+
if !bar.get_bit(0) {
292304
let prefetchable = bar.get_bit(3);
293305
let address = bar.get_bits(4..32) << 4;
294306

@@ -358,10 +370,13 @@ impl EndpointHeader {
358370
}
359371
}
360372

361-
/// Write to a BAR, setting the address for a device to use. The supplied value must be a valid
362-
/// BAR value (refer to the PCIe specification for requirements) and must be of the correct
363-
/// size (i.e. no larger than `u32::MAX` for 32-bit BARs). In the case of a 64-bit BAR, the
364-
/// supplied slot should be the first slot of the pair.
373+
/// Write to a BAR, setting the address for a device to use.
374+
///
375+
/// # Safety
376+
///
377+
/// The supplied value must be a valid BAR value (refer to the PCIe specification for
378+
/// requirements) and must be of the correct size (i.e. no larger than `u32::MAX` for 32-bit
379+
/// BARs). In the case of a 64-bit BAR, the supplied slot should be the first slot of the pair.
365380
pub unsafe fn write_bar(
366381
&mut self,
367382
slot: u8,
@@ -388,7 +403,7 @@ impl EndpointHeader {
388403
}
389404
Ok(())
390405
}
391-
None => return Err(BarWriteError::NoSuchBar),
406+
None => Err(BarWriteError::NoSuchBar),
392407
}
393408
}
394409

src/register.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bit_field::BitField;
22
use core::{
33
convert::TryFrom,
4-
fmt::{Debug, Formatter},
4+
fmt::{self, Debug, Formatter},
55
};
66

77
/// Slowest time that a device will assert DEVSEL# for any bus command except Configuration Space
@@ -13,15 +13,26 @@ pub enum DevselTiming {
1313
Slow = 0x2,
1414
}
1515

16+
#[derive(Debug)]
17+
pub struct TryFromDevselTimingError {
18+
number: u8,
19+
}
20+
21+
impl fmt::Display for TryFromDevselTimingError {
22+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23+
write!(f, "No discriminant in `DevselTiming` matches the value `{}`", self.number)
24+
}
25+
}
26+
1627
impl TryFrom<u8> for DevselTiming {
17-
type Error = ();
28+
type Error = TryFromDevselTimingError;
1829

1930
fn try_from(value: u8) -> Result<Self, Self::Error> {
2031
match value {
2132
0x0 => Ok(DevselTiming::Fast),
2233
0x1 => Ok(DevselTiming::Medium),
2334
0x2 => Ok(DevselTiming::Slow),
24-
_ => Err(()),
35+
number => Err(TryFromDevselTimingError { number }),
2536
}
2637
}
2738
}
@@ -64,7 +75,7 @@ impl StatusRegister {
6475
/// Configuration Space read and writes.
6576
///
6677
/// For PCIe always set to `Fast`
67-
pub fn devsel_timing(&self) -> Result<DevselTiming, ()> {
78+
pub fn devsel_timing(&self) -> Result<DevselTiming, TryFromDevselTimingError> {
6879
let bits = self.0.get_bits(9..11);
6980
DevselTiming::try_from(bits as u8)
7081
}

0 commit comments

Comments
 (0)