AP_OpticalFlow: prevent crash on bad device name

This commit is contained in:
Andrew Tridgell 2018-01-08 16:31:01 +11:00
parent 755eca31c2
commit ddf8523c2b
1 changed files with 3 additions and 0 deletions

View File

@ -104,6 +104,9 @@ AP_OpticalFlow_Pixart *AP_OpticalFlow_Pixart::detect(OpticalFlow &_frontend)
// setup the device
bool AP_OpticalFlow_Pixart::setup_sensor(void)
{
if (!_dev) {
return false;
}
if (!_dev->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
AP_HAL::panic("Unable to get bus semaphore");
}