From 29e5edde8abbb286d9fac38eeb0d8074589b1706 Mon Sep 17 00:00:00 2001 From: doryan Date: Mon, 26 May 2025 10:24:51 +0400 Subject: [PATCH] feat(check): add check for endpoint table length --- src/types/usb_device.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/types/usb_device.rs b/src/types/usb_device.rs index 51b7d2f..d3ef557 100644 --- a/src/types/usb_device.rs +++ b/src/types/usb_device.rs @@ -84,13 +84,17 @@ pub(crate) const ONE_MS_16_MGHZ: u32 = 16000; impl UsbDevice { #[inline] pub fn new(pll: PLL, usb: USB_DEVICE) -> UsbBusAllocator { - UsbBusAllocator::new(Self { - pll: Mutex::new(pll), - usb: Mutex::new(usb), - ep_table: [USBEndpoint::default(); L], - pending_ins: Mutex::new(Cell::new(0u8)), - dpram_already_used: 0, - }) + if L > 1 { + UsbBusAllocator::new(Self { + pll: Mutex::new(pll), + usb: Mutex::new(usb), + ep_table: [USBEndpoint::default(); L], + pending_ins: Mutex::new(Cell::new(0u8)), + dpram_already_used: 0, + }) + } else { + panic!("Endpoint table cannot be with length <= 1") + } } #[inline(always)]