aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/lib/spi/spidev_iface.cpp
diff options
context:
space:
mode:
authorMark Meserve <mark.meserve@ni.com>2017-10-03 11:17:27 -0500
committerMartin Braun <martin.braun@ettus.com>2017-12-22 15:04:01 -0800
commit9d3081e31556d2bedf8e4671c0082ceac52ac18f (patch)
tree0ed89aee6d2e6b30ad8b6f7e4244fdd578b856e4 /mpm/lib/spi/spidev_iface.cpp
parent46456dfd1377fb0f83d45965bd77fcd5fb8db480 (diff)
downloaduhd-9d3081e31556d2bedf8e4671c0082ceac52ac18f.tar.gz
uhd-9d3081e31556d2bedf8e4671c0082ceac52ac18f.tar.bz2
uhd-9d3081e31556d2bedf8e4671c0082ceac52ac18f.zip
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
Diffstat (limited to 'mpm/lib/spi/spidev_iface.cpp')
-rw-r--r--mpm/lib/spi/spidev_iface.cpp22
1 files changed, 11 insertions, 11 deletions
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 <fcntl.h>
#include <linux/spi/spidev.h>
#include <boost/format.hpp>
@@ -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));
}
}