@@ -317,26 +317,24 @@ enum { BUILTIN_DRIVER_COUNT = TU_ARRAY_SIZE(_usbd_driver) };
317317tu_static usbd_class_driver_t const * _app_driver = NULL ;
318318tu_static uint8_t _app_driver_count = 0 ;
319319
320- #define TOTAL_DRIVER_COUNT (_app_driver_count + BUILTIN_DRIVER_COUNT)
320+ #define TOTAL_DRIVER_COUNT ((uint8_t) ( _app_driver_count + BUILTIN_DRIVER_COUNT) )
321321
322322// virtually joins built-in and application drivers together.
323323// Application is positioned first to allow overwriting built-in ones.
324324TU_ATTR_ALWAYS_INLINE static inline usbd_class_driver_t const * get_driver (uint8_t drvid ) {
325- usbd_class_driver_t const * driver = NULL ;
326- if ( drvid < _app_driver_count ) {
325+ usbd_class_driver_t const * driver = NULL ;
326+ if (drvid < _app_driver_count ) {
327327 // Application drivers
328328 driver = & _app_driver [drvid ];
329- } else if ( drvid < TOTAL_DRIVER_COUNT && BUILTIN_DRIVER_COUNT > 0 ) {
329+ } else if (drvid < TOTAL_DRIVER_COUNT && BUILTIN_DRIVER_COUNT > 0 ) {
330330 driver = & _usbd_driver [drvid - _app_driver_count ];
331331 }
332332 return driver ;
333333}
334334
335-
336335//--------------------------------------------------------------------+
337336// DCD Event
338337//--------------------------------------------------------------------+
339-
340338enum { RHPORT_INVALID = 0xFFu };
341339tu_static uint8_t _usbd_rhport = RHPORT_INVALID ;
342340
@@ -488,6 +486,7 @@ bool tud_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
488486 // Get application driver if available
489487 if (usbd_app_driver_get_cb ) {
490488 _app_driver = usbd_app_driver_get_cb (& _app_driver_count );
489+ TU_ASSERT (_app_driver_count + BUILTIN_DRIVER_COUNT <= UINT8_MAX );
491490 }
492491
493492 // Init class drivers
0 commit comments