From b578419e0950994b4e0a002362e294b3fc74fca6 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Wed, 12 Sep 2018 13:57:36 -0700 Subject: [PATCH] Bug fix fmu hard fault on pwm info A hardfault was happening on: fmu stop fmu mode_pwm pwm info The _mixer was null and being dereferenced to access the trim setting that were moved to the mixer from the fmu. This commit fixes that but making the getter issue a warning and the setter fail. --- src/drivers/px4fmu/fmu.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/drivers/px4fmu/fmu.cpp b/src/drivers/px4fmu/fmu.cpp index 1685f13abb..e5d89bd931 100644 --- a/src/drivers/px4fmu/fmu.cpp +++ b/src/drivers/px4fmu/fmu.cpp @@ -1735,6 +1735,12 @@ PX4FMU::pwm_ioctl(file *filp, int cmd, unsigned long arg) break; } + if (_mixers == nullptr) { + PX4_ERR("error: no mixer loaded"); + ret = -EIO; + break; + } + /* copy the trim values to the mixer offsets */ _mixers->set_trims((int16_t *)pwm->values, pwm->channel_count); PX4_DEBUG("set_trims: %d, %d, %d, %d", pwm->values[0], pwm->values[1], pwm->values[2], pwm->values[3]); @@ -1745,7 +1751,14 @@ PX4FMU::pwm_ioctl(file *filp, int cmd, unsigned long arg) case PWM_SERVO_GET_TRIM_PWM: { struct pwm_output_values *pwm = (struct pwm_output_values *)arg; - pwm->channel_count = _mixers->get_trims((int16_t *)pwm->values); + if (_mixers == nullptr) { + memset(pwm, 0, sizeof(pwm_output_values)); + PX4_WARN("warning: trim values not valid - no mixer loaded"); + + } else { + + pwm->channel_count = _mixers->get_trims((int16_t *)pwm->values); + } break; }