From 9d3081e31556d2bedf8e4671c0082ceac52ac18f Mon Sep 17 00:00:00 2001 From: Mark Meserve Date: Tue, 3 Oct 2017 11:17:27 -0500 Subject: spidev: fix error handling in initialization - Reversed the incorrect logic in spidev_iface.cpp for error checking on init_spi - Error on failed fd creation is now valid and added a null pointer check for fd - ioctl read operations are now given non-const references - Bits per word coercion check is now initialized correctly - Coercion errors now return -ENOTSUP instead of 2 - Improved logging messages with more information --- mpm/lib/spi/spidev_iface.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'mpm/lib/spi/spidev_iface.cpp') diff --git a/mpm/lib/spi/spidev_iface.cpp b/mpm/lib/spi/spidev_iface.cpp index 522238e19..8be73471d 100644 --- a/mpm/lib/spi/spidev_iface.cpp +++ b/mpm/lib/spi/spidev_iface.cpp @@ -21,6 +21,7 @@ extern "C" { #include "spidev.h" } +#include #include #include @@ -42,22 +43,21 @@ public: ) : _speed(max_speed_hz), _mode(spi_mode) { - - if (!init_spi( + if (init_spi( &_fd, device.c_str(), - _mode, _speed, _bits, _delay - )) { + _mode, _speed, _bits, _delay) < 0) + { throw mpm::runtime_error(str( - boost::format("Could not initialize spidev device %s") - % device - )); + boost::format("Could not initialize spidev device %s") + % device)); } - if (_fd < 0) { + + if (_fd < 0) + { throw mpm::runtime_error(str( - boost::format("Could not open spidev device %s") - % device - )); + boost::format("Could not open spidev device %s") + % device)); } } -- cgit v1.2.3