From 7d65c5c4fa9f4a931019625168d7eacf0ec2fa40 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 3 Aug 2024 00:14:11 +0200 Subject: [PATCH] usb-synopsys-otg: ensure ep alloc fails when endpoint_count < MAX_EP_COUNT. Before, it would alloc the endpoint fine and then panic later due to out of range. This ensures it falis at ep alloc time, and with a panic message that says what's the actual problem: "no free endpoints available". --- embassy-usb-synopsys-otg/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embassy-usb-synopsys-otg/src/lib.rs b/embassy-usb-synopsys-otg/src/lib.rs index b90e059f6..f155f1522 100644 --- a/embassy-usb-synopsys-otg/src/lib.rs +++ b/embassy-usb-synopsys-otg/src/lib.rs @@ -382,8 +382,8 @@ impl<'d, const MAX_EP_COUNT: usize> Driver<'d, MAX_EP_COUNT> { } let eps = match D::dir() { - Direction::Out => &mut self.ep_out, - Direction::In => &mut self.ep_in, + Direction::Out => &mut self.ep_out[..self.instance.endpoint_count], + Direction::In => &mut self.ep_in[..self.instance.endpoint_count], }; // Find free endpoint slot