Skip to content

Commit 02fa5eb

Browse files
jbeaurivageAfoHTvcchtjaderTDHolmes
authored andcommitted
Cleanup Clippy Lints (atsamd-rs#569)
* Cleanup clippy lints * Changelog * rustfmt * Don't allow missing_safety_docs, revert From/Into GClock-Hertz impls * Docs: NVM, PUKCC (atsamd-rs#4) Co-authored-by: Henrik Tjäder <henrik.tjader@volvocars.com> * rustfmt * Allow double underscores in entire pukcc module * Fix rust_2018_idioms lints * Fix clippy lints in T1 examples Co-authored-by: Henrik Tjäder <henrik@tjaders.com> Co-authored-by: Henrik Tjäder <henrik.tjader@volvocars.com> Co-authored-by: Tyler Holmes <tyler@holmesengineering.com>
1 parent 7821b14 commit 02fa5eb

File tree

41 files changed

+242
-171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+242
-171
lines changed

boards/feather_m0/examples/adalogger.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ fn main() -> ! {
6868
};
6969

7070
unsafe {
71-
USB_SERIAL = Some(SerialPort::new(&bus_allocator));
71+
USB_SERIAL = Some(SerialPort::new(bus_allocator));
7272
USB_BUS = Some(
73-
UsbDeviceBuilder::new(&bus_allocator, UsbVidPid(0x16c0, 0x27dd))
73+
UsbDeviceBuilder::new(bus_allocator, UsbVidPid(0x16c0, 0x27dd))
7474
.manufacturer("Fake company")
7575
.product("Serial port")
7676
.serial_number("TEST")
@@ -109,7 +109,7 @@ fn main() -> ! {
109109
red_led.set_low().unwrap();
110110
delay.delay_ms(500_u32);
111111

112-
while USB_DATA_RECEIVED.load(atomic::Ordering::Relaxed) == false {
112+
while !USB_DATA_RECEIVED.load(atomic::Ordering::Relaxed) {
113113
delay.delay_ms(250_u32);
114114
red_led.toggle().unwrap();
115115
}
@@ -192,16 +192,16 @@ static USB_DATA_RECEIVED: atomic::AtomicBool = atomic::AtomicBool::new(false);
192192
#[interrupt]
193193
fn USB() {
194194
unsafe {
195-
USB_BUS.as_mut().map(|usb_dev| {
196-
USB_SERIAL.as_mut().map(|serial| {
195+
if let Some(usb_dev) = USB_BUS.as_mut() {
196+
if let Some(serial) = USB_SERIAL.as_mut() {
197197
usb_dev.poll(&mut [serial]);
198198
let mut buf = [0u8; 16];
199199
if let Ok(count) = serial.read(&mut buf) {
200200
if count > 0 {
201201
USB_DATA_RECEIVED.store(true, atomic::Ordering::Relaxed);
202202
}
203203
}
204-
});
205-
});
204+
};
205+
};
206206
};
207207
}

boards/feather_m0/examples/clock.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ fn main() -> ! {
6767
USB_ALLOCATOR.as_ref().unwrap()
6868
};
6969
unsafe {
70-
USB_SERIAL = Some(SerialPort::new(&bus_allocator));
70+
USB_SERIAL = Some(SerialPort::new(bus_allocator));
7171
USB_BUS = Some(
72-
UsbDeviceBuilder::new(&bus_allocator, UsbVidPid(0x16c0, 0x27dd))
72+
UsbDeviceBuilder::new(bus_allocator, UsbVidPid(0x16c0, 0x27dd))
7373
.manufacturer("Fake company")
7474
.product("Serial port")
7575
.serial_number("TEST")
@@ -109,16 +109,16 @@ static mut RTC: Option<rtc::Rtc<rtc::ClockMode>> = None;
109109

110110
fn write_serial(bytes: &[u8]) {
111111
unsafe {
112-
USB_SERIAL.as_mut().map(|serial| {
112+
if let Some(serial) = USB_SERIAL.as_mut() {
113113
serial.write(bytes).unwrap();
114-
});
114+
};
115115
}
116116
}
117117

118118
fn poll_usb() {
119119
unsafe {
120-
USB_BUS.as_mut().map(|usb_dev| {
121-
USB_SERIAL.as_mut().map(|serial| {
120+
if let Some(usb_dev) = USB_BUS.as_mut() {
121+
if let Some(serial) = USB_SERIAL.as_mut() {
122122
usb_dev.poll(&mut [serial]);
123123
let mut buf = [0u8; 32];
124124

@@ -133,7 +133,7 @@ fn poll_usb() {
133133
Ok((remaining, time)) => {
134134
buffer = remaining;
135135
disable_interrupts(|_| {
136-
RTC.as_mut().map(|rtc| {
136+
if let Some(rtc) = RTC.as_mut() {
137137
rtc.set_time(rtc::Datetime {
138138
seconds: time.second as u8,
139139
minutes: time.minute as u8,
@@ -142,15 +142,15 @@ fn poll_usb() {
142142
month: 0,
143143
year: 0,
144144
});
145-
});
145+
};
146146
});
147147
}
148148
_ => break,
149149
};
150150
}
151151
};
152-
});
153-
});
152+
};
153+
};
154154
};
155155
}
156156

boards/feather_m0/examples/dmac.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ fn main() -> ! {
7777
let _b = buf_16[LENGTH - 1];
7878

7979
// Manipulate the returned buffer for fun
80-
for i in 0..LENGTH {
81-
buf_16[i] = i as u16;
80+
for (i, item) in buf_16.iter_mut().enumerate() {
81+
*item = i as u16;
8282
}
8383

8484
// Setup a DMA transfer (memory-to-memory -> incrementing source, fixed

boards/feather_m0/examples/usb_echo.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ fn main() -> ! {
4747
};
4848

4949
unsafe {
50-
USB_SERIAL = Some(SerialPort::new(&bus_allocator));
50+
USB_SERIAL = Some(SerialPort::new(bus_allocator));
5151
USB_BUS = Some(
52-
UsbDeviceBuilder::new(&bus_allocator, UsbVidPid(0x16c0, 0x27dd))
52+
UsbDeviceBuilder::new(bus_allocator, UsbVidPid(0x16c0, 0x27dd))
5353
.manufacturer("Fake company")
5454
.product("Serial port")
5555
.serial_number("TEST")
@@ -77,8 +77,8 @@ static mut USB_SERIAL: Option<SerialPort<UsbBus>> = None;
7777

7878
fn poll_usb() {
7979
unsafe {
80-
USB_BUS.as_mut().map(|usb_dev| {
81-
USB_SERIAL.as_mut().map(|serial| {
80+
if let Some(usb_dev) = USB_BUS.as_mut() {
81+
if let Some(serial) = USB_SERIAL.as_mut() {
8282
usb_dev.poll(&mut [serial]);
8383
let mut buf = [0u8; 64];
8484

@@ -87,11 +87,11 @@ fn poll_usb() {
8787
if i >= count {
8888
break;
8989
}
90-
serial.write(&[c.clone()]).ok();
90+
serial.write(&[*c]).ok();
9191
}
9292
};
93-
});
94-
});
93+
};
94+
};
9595
};
9696
}
9797

boards/feather_m4/examples/dmac.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ fn main() -> ! {
7676
let _b = buf_16[LENGTH - 1];
7777

7878
// Manipulate the returned buffer for fun
79-
for i in 0..LENGTH {
80-
buf_16[i] = i as u16;
79+
for (i, item) in buf_16.iter_mut().enumerate() {
80+
*item = i as u16;
8181
}
8282

8383
// Setup a DMA transfer (memory-to-memory -> incrementing source, fixed

boards/feather_m4/examples/nvm_dsu.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![no_std]
22
#![no_main]
3+
#![allow(clippy::bool_comparison)]
34

45
use bsp::ehal;
56
use bsp::hal;
@@ -55,9 +56,9 @@ fn main() -> ! {
5556
};
5657

5758
unsafe {
58-
USB_SERIAL = Some(SerialPort::new(&bus_allocator));
59+
USB_SERIAL = Some(SerialPort::new(bus_allocator));
5960
USB_BUS = Some(
60-
UsbDeviceBuilder::new(&bus_allocator, UsbVidPid(0x16c0, 0x27dd))
61+
UsbDeviceBuilder::new(bus_allocator, UsbVidPid(0x16c0, 0x27dd))
6162
.manufacturer("Fake company")
6263
.product("Serial port")
6364
.serial_number("TEST")
@@ -155,8 +156,8 @@ where
155156
T: Fn(&mut SerialPort<UsbBus>) -> R,
156157
{
157158
usb_free(|_| unsafe {
158-
let mut usb_serial = USB_SERIAL.as_mut().expect("UsbSerial not initialized");
159-
borrower(&mut usb_serial)
159+
let usb_serial = USB_SERIAL.as_mut().expect("UsbSerial not initialized");
160+
borrower(usb_serial)
160161
})
161162
}
162163

@@ -212,8 +213,8 @@ macro_rules! serial_writeln {
212213

213214
fn poll_usb() {
214215
unsafe {
215-
USB_BUS.as_mut().map(|usb_dev| {
216-
USB_SERIAL.as_mut().map(|serial| {
216+
if let Some(usb_dev) = USB_BUS.as_mut() {
217+
if let Some(serial) = USB_SERIAL.as_mut() {
217218
usb_dev.poll(&mut [serial]);
218219
let mut buf = [0u8; 64];
219220

@@ -223,8 +224,8 @@ fn poll_usb() {
223224
}
224225
serial.write(&buf[..count]).unwrap();
225226
};
226-
});
227-
});
227+
};
228+
};
228229
};
229230
}
230231

boards/feather_m4/examples/pukcc_test.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![no_std]
22
#![no_main]
3+
#![allow(clippy::bool_comparison)]
34

45
use bsp::ehal;
56
use bsp::hal;
@@ -49,9 +50,9 @@ fn main() -> ! {
4950
};
5051

5152
unsafe {
52-
USB_SERIAL = Some(SerialPort::new(&bus_allocator));
53+
USB_SERIAL = Some(SerialPort::new(bus_allocator));
5354
USB_BUS = Some(
54-
UsbDeviceBuilder::new(&bus_allocator, UsbVidPid(0x16c0, 0x27dd))
55+
UsbDeviceBuilder::new(bus_allocator, UsbVidPid(0x16c0, 0x27dd))
5556
.manufacturer("Fake company")
5657
.product("Serial port")
5758
.serial_number("TEST")
@@ -98,27 +99,25 @@ fn main() -> ! {
9899
false
99100
}
100101
};
101-
let is_signature_valid = match pukcc.zp_ecdsa_verify_signature::<curves::Nist256p>(
102-
&generated_signature,
103-
&HASH,
104-
&ecdsa::PUBLIC_KEY,
105-
) {
106-
Ok(_) => true,
107-
Err(_) => false,
108-
};
102+
let is_signature_valid = pukcc
103+
.zp_ecdsa_verify_signature::<curves::Nist256p>(
104+
&generated_signature,
105+
&HASH,
106+
&ecdsa::PUBLIC_KEY,
107+
)
108+
.is_ok();
109109

110110
// Break signature
111111
generated_signature[14] = generated_signature[14].wrapping_sub(1);
112112

113-
let is_broken_signature_invalid = match pukcc
113+
let is_broken_signature_invalid = pukcc
114114
.zp_ecdsa_verify_signature::<curves::Nist256p>(
115115
&generated_signature,
116116
&HASH,
117117
&ecdsa::PUBLIC_KEY,
118-
) {
119-
Err(_) => true,
120-
Ok(_) => false,
121-
};
118+
)
119+
.is_err();
120+
122121
serial_writeln!(
123122
"{:>2}: {:<5} | {:<5} | {:<5}",
124123
i,
@@ -158,7 +157,7 @@ fn main() -> ! {
158157
};
159158
let is_signature_valid = match pukcc.modular_exponentiation(
160159
reference_signature,
161-
&exp_mod::PUBLIC_EXPONENT,
160+
exp_mod::PUBLIC_EXPONENT,
162161
modulus,
163162
ExpModMode::Regular,
164163
ExpModWindowSize::One,
@@ -186,7 +185,7 @@ fn main() -> ! {
186185
broken_reference_signature[broken_reference_signature.len() - 1].wrapping_sub(1);
187186
let is_broken_signature_invalid = match pukcc.modular_exponentiation(
188187
&broken_reference_signature[broken_reference_signature.len() - modulus.len()..],
189-
&exp_mod::PUBLIC_EXPONENT,
188+
exp_mod::PUBLIC_EXPONENT,
190189
modulus,
191190
ExpModMode::Regular,
192191
ExpModWindowSize::One,
@@ -242,8 +241,8 @@ where
242241
T: Fn(&mut SerialPort<UsbBus>) -> R,
243242
{
244243
usb_free(|_| unsafe {
245-
let mut usb_serial = USB_SERIAL.as_mut().expect("UsbSerial not initialized");
246-
borrower(&mut usb_serial)
244+
let usb_serial = USB_SERIAL.as_mut().expect("UsbSerial not initialized");
245+
borrower(usb_serial)
247246
})
248247
}
249248

@@ -299,8 +298,8 @@ macro_rules! serial_writeln {
299298

300299
fn poll_usb() {
301300
unsafe {
302-
USB_BUS.as_mut().map(|usb_dev| {
303-
USB_SERIAL.as_mut().map(|serial| {
301+
if let Some(usb_dev) = USB_BUS.as_mut() {
302+
if let Some(serial) = USB_SERIAL.as_mut() {
304303
usb_dev.poll(&mut [serial]);
305304
let mut buf = [0u8; 64];
306305

@@ -309,11 +308,11 @@ fn poll_usb() {
309308
if i >= count {
310309
break;
311310
}
312-
serial.write(&[c.clone()]).unwrap();
311+
serial.write(&[*c]).unwrap();
313312
}
314313
};
315-
});
316-
});
314+
};
315+
};
317316
};
318317
}
319318

@@ -341,7 +340,7 @@ mod exp_mod {
341340
pub const PUBLIC_EXPONENT: &[u8] = &[0x01, 0x00, 0x01];
342341

343342
/// Vector of tuples of (modulus, private_exponent, expected_signature)
344-
pub const RSA_VECTOR: [(&'static [u8], &'static [u8], &'static [u8]); 8] = [
343+
pub const RSA_VECTOR: [(&[u8], &[u8], &[u8]); 8] = [
345344
// RSA512
346345
(
347346
&[

boards/feather_m4/examples/smart_eeprom.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![no_std]
22
#![no_main]
3+
#![allow(clippy::bool_comparison)]
34

45
use bsp::ehal;
56
use bsp::hal;
@@ -53,9 +54,9 @@ fn main() -> ! {
5354
};
5455

5556
unsafe {
56-
USB_SERIAL = Some(SerialPort::new(&bus_allocator));
57+
USB_SERIAL = Some(SerialPort::new(bus_allocator));
5758
USB_BUS = Some(
58-
UsbDeviceBuilder::new(&bus_allocator, UsbVidPid(0x16c0, 0x27dd))
59+
UsbDeviceBuilder::new(bus_allocator, UsbVidPid(0x16c0, 0x27dd))
5960
.manufacturer("Fake company")
6061
.product("Serial port")
6162
.serial_number("TEST")
@@ -93,7 +94,7 @@ fn main() -> ! {
9394
let mut read_buf = [0u8; 14];
9495
seeprom.get(0x14, &mut read_buf);
9596
read_buf.rotate_left(4);
96-
if &read_buf[..8] == &write_buf {
97+
if read_buf[..8] == write_buf {
9798
serial_writeln!("Smart EEPROM test successful");
9899
} else {
99100
serial_writeln!("Smart EEPROM test failed");
@@ -135,8 +136,8 @@ where
135136
T: Fn(&mut SerialPort<UsbBus>) -> R,
136137
{
137138
usb_free(|_| unsafe {
138-
let mut usb_serial = USB_SERIAL.as_mut().expect("UsbSerial not initialized");
139-
borrower(&mut usb_serial)
139+
let usb_serial = USB_SERIAL.as_mut().expect("UsbSerial not initialized");
140+
borrower(usb_serial)
140141
})
141142
}
142143

@@ -192,8 +193,8 @@ macro_rules! serial_writeln {
192193

193194
fn poll_usb() {
194195
unsafe {
195-
USB_BUS.as_mut().map(|usb_dev| {
196-
USB_SERIAL.as_mut().map(|serial| {
196+
if let Some(usb_dev) = USB_BUS.as_mut() {
197+
if let Some(serial) = USB_SERIAL.as_mut() {
197198
usb_dev.poll(&mut [serial]);
198199
let mut buf = [0u8; 64];
199200

@@ -203,8 +204,8 @@ fn poll_usb() {
203204
}
204205
serial.write(&buf[..count]).unwrap();
205206
};
206-
});
207-
});
207+
};
208+
}
208209
};
209210
}
210211

0 commit comments

Comments
 (0)