From 6ed4eca57fd7afc7569adc6082eed7d4e11fbe80 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 1 Jan 2021 21:11:05 +1100 Subject: [PATCH] AP_CANManager: fixed use of CANSensor on multiple ports we should not increment _num_drivers if we don't have a driver yet --- libraries/AP_CANManager/AP_CANManager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/AP_CANManager/AP_CANManager.cpp b/libraries/AP_CANManager/AP_CANManager.cpp index a0db66e61c..878a67d07f 100644 --- a/libraries/AP_CANManager/AP_CANManager.cpp +++ b/libraries/AP_CANManager/AP_CANManager.cpp @@ -186,8 +186,7 @@ void AP_CANManager::init() continue; } - _num_drivers++; - if (_num_drivers > HAL_MAX_CAN_PROTOCOL_DRIVERS) { + if (_num_drivers >= HAL_MAX_CAN_PROTOCOL_DRIVERS) { // We are exceeding number of drivers, // this can't be happening time to panic AP_BoardConfig::config_error("Max number of CAN Drivers exceeded\n\r"); @@ -247,6 +246,8 @@ void AP_CANManager::init() continue; } + _num_drivers++; + // Hook this interface to the selected Driver Type _drivers[drv_num]->add_interface(iface); log_text(AP_CANManager::LOG_INFO, LOG_TAG, "Adding Interface %d to Driver %d", i + 1, drv_num + 1);