diff --git a/libraries/AP_HAL_Linux/CANSocketIface.cpp b/libraries/AP_HAL_Linux/CANSocketIface.cpp index d3c46302b8c..b68a2ae6979 100644 --- a/libraries/AP_HAL_Linux/CANSocketIface.cpp +++ b/libraries/AP_HAL_Linux/CANSocketIface.cpp @@ -319,6 +319,9 @@ bool CANIface::_pollRead() int CANIface::_write(const AP_HAL::CANFrame& frame) const { + if (_fd < 0) { + return -1; + } errno = 0; const can_frame sockcan_frame = makeSocketCanFrame(frame); @@ -339,6 +342,9 @@ int CANIface::_write(const AP_HAL::CANFrame& frame) const int CANIface::_read(AP_HAL::CANFrame& frame, uint64_t& timestamp_us, bool& loopback) const { + if (_fd < 0) { + return -1; + } auto iov = iovec(); auto sockcan_frame = can_frame(); iov.iov_base = &sockcan_frame;