summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/host/usbh.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/host/usbh.c b/src/host/usbh.c
index 2709856bb..e307bb5e5 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -319,13 +319,12 @@ static usbh_class_driver_t const usbh_class_drivers[] = {
#endif
};
-enum { BUILTIN_DRIVER_COUNT = TU_ARRAY_SIZE(usbh_class_drivers) };
-
// Additional class drivers implemented by application
static usbh_class_driver_t const * _app_driver = NULL;
-static uint8_t _app_driver_count = 0;
+static const uint8_t _builtin_driver_count = TU_ARRAY_SIZE(usbh_class_drivers);
+static uint8_t _app_driver_count = 0;
-#define TOTAL_DRIVER_COUNT (_app_driver_count + BUILTIN_DRIVER_COUNT)
+#define TOTAL_DRIVER_COUNT (_app_driver_count + _builtin_driver_count)
// virtually joins built-in and application drivers together.
// Application is positioned first to allow overwriting built-in ones.
@@ -335,7 +334,7 @@ TU_ATTR_ALWAYS_INLINE static inline usbh_class_driver_t const *get_driver(uint8_
driver = &_app_driver[drv_id];
} else {
drv_id -= _app_driver_count;
- if (drv_id < BUILTIN_DRIVER_COUNT) {
+ if (_builtin_driver_count > 0 && drv_id < _builtin_driver_count) {
driver = &usbh_class_drivers[drv_id];
}
}
@@ -547,6 +546,7 @@ bool tuh_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
// Get application driver if available
_app_driver = usbh_app_driver_get_cb(&_app_driver_count);
+ TU_ASSERT(_app_driver_count + _builtin_driver_count <= UINT8_MAX);
// Device
tu_memclr(_usbh_devices, sizeof(_usbh_devices));