FrequencySensor::initIfValid: check for error

Do not set m_pin until we fully happy. Otherwise deInit() can do
bad things to pin that is possibly not belongs to us.
This commit is contained in:
Andrey Gusakov 2024-03-05 23:31:21 +03:00 committed by rusefillc
parent f4cd6de86d
commit 0ce7db29b0
1 changed files with 6 additions and 5 deletions

View File

@ -28,15 +28,16 @@ void FrequencySensor::initIfValid(brain_pin_e pin, SensorConverter &converter, f
setFunction(converter);
m_pin = pin;
#if EFI_PROD_CODE
// todo: refactor https://github.com/rusefi/rusefi/issues/2123
efiExtiEnablePin(getSensorName(), pin,
PAL_EVENT_MODE_FALLING_EDGE,
freqSensorExtiCallback, reinterpret_cast<void*>(this));
if (efiExtiEnablePin(getSensorName(), pin, PAL_EVENT_MODE_FALLING_EDGE,
freqSensorExtiCallback, reinterpret_cast<void*>(this)) < 0) {
return;
}
#endif // EFI_PROD_CODE
m_pin = pin;
Register();
}