Skip to content

Commit ca1901d

Browse files
committed
avoid static mut for USB test device builder
1 parent a6e6c91 commit ca1901d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/test_class.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ mod sizes {
2222
pub const INTERRUPT_ENDPOINT: u16 = 31;
2323
}
2424

25-
static mut CONTROL_BUFFER: UnsafeCell<[u8; 256]> = UnsafeCell::new([0; 256]);
25+
pub struct ControlBuffer(UnsafeCell<[u8; 256]>);
26+
27+
unsafe impl Sync for ControlBuffer {}
28+
29+
static CONTROL_BUFFER: ControlBuffer = ControlBuffer(UnsafeCell::new([0; 256]));
2630

2731
/// Test USB class for testing USB driver implementations. Supports various endpoint types and
2832
/// requests for testing USB peripheral drivers on actual hardware.
@@ -115,7 +119,7 @@ impl<B: UsbBus> TestClass<'_, B> {
115119
usb_bus: &'a UsbBusAllocator<B>,
116120
) -> UsbDeviceBuilder<'a, B> {
117121
UsbDeviceBuilder::new(usb_bus, UsbVidPid(VID, PID), unsafe {
118-
CONTROL_BUFFER.get_mut()
122+
&mut *(CONTROL_BUFFER.0.get())
119123
})
120124
.strings(&[StringDescriptors::default()
121125
.manufacturer(MANUFACTURER)

tests/test_class_host/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn open_device(ctx: &Context) -> rusb::Result<DeviceHandles> {
6060
continue;
6161
}
6262

63-
let mut handle = device.open()?;
63+
let handle = device.open()?;
6464

6565
let langs = handle.read_languages(TIMEOUT)?;
6666
if langs.is_empty() || langs[0].lang_id() != EN_US {

0 commit comments

Comments
 (0)