summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2025-07-10 18:50:42 +0700
committerGitHub <[email protected]>2025-07-10 18:50:42 +0700
commit40dc1dd436ce96d9d3257d6de60f3c28fd38e294 (patch)
tree482444899f3f0a1fc1252b806ae75e12935235bc /src
parent546e8413b5ed05a8c35b8dbe7792516a3cd631fa (diff)
parentea38115d6c65463b8c12f2da661855d2b4f263bd (diff)
Merge pull request #2987 from hathach/fix-2923-alt
make sure TOTAL_DRIVER_COUNT is not overflow 8-bit
Diffstat (limited to 'src')
-rw-r--r--src/device/usbd.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c
index 1e16034a8..b09d02fbd 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -329,26 +329,24 @@ enum { BUILTIN_DRIVER_COUNT = TU_ARRAY_SIZE(_usbd_driver) };
tu_static usbd_class_driver_t const * _app_driver = NULL;
tu_static uint8_t _app_driver_count = 0;
-#define TOTAL_DRIVER_COUNT (_app_driver_count + BUILTIN_DRIVER_COUNT)
+#define TOTAL_DRIVER_COUNT ((uint8_t) (_app_driver_count + BUILTIN_DRIVER_COUNT))
// virtually joins built-in and application drivers together.
// Application is positioned first to allow overwriting built-in ones.
TU_ATTR_ALWAYS_INLINE static inline usbd_class_driver_t const * get_driver(uint8_t drvid) {
- usbd_class_driver_t const * driver = NULL;
- if ( drvid < _app_driver_count ) {
+ usbd_class_driver_t const *driver = NULL;
+ if (drvid < _app_driver_count) {
// Application drivers
driver = &_app_driver[drvid];
- } else if ( drvid < TOTAL_DRIVER_COUNT && BUILTIN_DRIVER_COUNT > 0 ){
+ } else if (drvid < TOTAL_DRIVER_COUNT && BUILTIN_DRIVER_COUNT > 0) {
driver = &_usbd_driver[drvid - _app_driver_count];
}
return driver;
}
-
//--------------------------------------------------------------------+
// DCD Event
//--------------------------------------------------------------------+
-
enum { RHPORT_INVALID = 0xFFu };
tu_static uint8_t _usbd_rhport = RHPORT_INVALID;
@@ -520,6 +518,7 @@ bool tud_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
// Get application driver if available
if (usbd_app_driver_get_cb) {
_app_driver = usbd_app_driver_get_cb(&_app_driver_count);
+ TU_ASSERT(_app_driver_count + BUILTIN_DRIVER_COUNT <= UINT8_MAX);
}
// Init class drivers