Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix magnetometer crashing when config is not valid.
[magnetometer] Fix crash when config is not valid. Contributes to JB#32073

There is multiple cases where pointers were not checked where the
sensorfw can crash if configuration file is not according to the "happy
path". This commit fixes the issues so that the sensorfw will not crash
and reboot when trying to access magnetometer that is not valid.

Signed-off-by: Marko Saukko <marko.saukko@jolla.com>
  • Loading branch information
saukko committed Aug 23, 2016
1 parent ae8b2ae commit 6dd35ca
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
29 changes: 26 additions & 3 deletions chains/magcalibrationchain/magcalibrationchain.cpp
Expand Up @@ -35,15 +35,24 @@
// magcalibrationchain requires: magnetometeradaptor, kbslideradaptor

MagCalibrationChain::MagCalibrationChain(const QString& id) :
AbstractChain(id)
AbstractChain(id),
filterBin(NULL),
magAdaptor(NULL),
magReader(NULL),
magCalFilter(NULL),
magScaleFilter(NULL),
magCoordinateAlignFilter_(NULL),
calibratedMagnetometerData(NULL)
{
setMatrixFromString("1,0,0,\
0,1,0,\
0,0,1");
SensorManager& sm = SensorManager::instance();

magAdaptor = sm.requestDeviceAdaptor("magnetometeradaptor");
setValid(magAdaptor->isValid());
// valid is false by default so no need to set it if magnetormeter adaptor is not there
if (magAdaptor)
setValid(magAdaptor->isValid());

// Config::configuration()->value<int>("magnetometer/interval_compensation", 16);
// Get the transformation matrix from config file
Expand Down Expand Up @@ -128,6 +137,11 @@ MagCalibrationChain::~MagCalibrationChain()

bool MagCalibrationChain::start()
{
if (!magAdaptor) {
sensordLogD() << "No magnetometer adaptor to start.";
return false;
}

if (AbstractSensorChannel::start()) {
sensordLogD() << "Starting MagCalibrationChain";
filterBin->start();
Expand All @@ -138,6 +152,11 @@ bool MagCalibrationChain::start()

bool MagCalibrationChain::stop()
{
if (!magAdaptor) {
sensordLogD() << "No magnetometer adaptor to stop.";
return false;
}

if (AbstractSensorChannel::stop()) {
sensordLogD() << "Stopping MagCalibrationChain";
magAdaptor->stopSensor();
Expand All @@ -150,7 +169,11 @@ void MagCalibrationChain::resetCalibration()
{
if (needsCalibration) {
CalibrationFilter *filter = static_cast<CalibrationFilter *>(magCalFilter);
filter->dropCalibration();
if (!filter) {
sensordLogD() << "Can not reset calibration without filter.";
return;
}
filter->dropCalibration();
}
}

Expand Down
11 changes: 9 additions & 2 deletions core/nodebase.cpp
Expand Up @@ -262,7 +262,7 @@ DataRangeList NodeBase::parseDataRangeList(const QString& input, int defaultReso

const QList<DataRange>& NodeBase::getAvailableIntervals() const
{
if (!hasLocalInterval())
if (m_intervalSource && !hasLocalInterval())
{
return m_intervalSource->getAvailableIntervals();
}
Expand Down Expand Up @@ -355,7 +355,8 @@ bool NodeBase::setIntervalRequest(const int sessionId, const unsigned int value)

void NodeBase::addStandbyOverrideSource(NodeBase* node)
{
m_standbySourceList.append(node);
if (node)
m_standbySourceList.append(node);
}

bool NodeBase::standbyOverride() const
Expand Down Expand Up @@ -514,6 +515,9 @@ void NodeBase::removeIntervalRequest(const int sessionId)

bool NodeBase::connectToSource(NodeBase* source, const QString& bufferName, RingBufferReaderBase* reader)
{
if (!source)
return false;

RingBufferBase* rb = source->findBuffer(bufferName);
if (rb == NULL)
{
Expand All @@ -535,6 +539,9 @@ bool NodeBase::connectToSource(NodeBase* source, const QString& bufferName, Ring

bool NodeBase::disconnectFromSource(NodeBase* source, const QString& bufferName, RingBufferReaderBase* reader)
{
if (!source)
return false;

RingBufferBase* rb = source->findBuffer(bufferName);
if (rb == NULL)
{
Expand Down

0 comments on commit 6dd35ca

Please sign in to comment.