From 25c7e8bf603111ea8fc735ce2e4e8190dc8538fd Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Thu, 11 Aug 2016 17:36:17 +0200 Subject: [PATCH] AP_HAL: AP_HAL_Linux: perfect I2CDevice::transfer() According to man 3 ioctl, ioctl returns other values than -1 on success. So loop while ioctl returns -1. Furthermore, there is no necessity to initialise r with -EINVAL, Signed-off-by: Ralf Ramsauer --- libraries/AP_HAL_Linux/I2CDevice.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/AP_HAL_Linux/I2CDevice.cpp b/libraries/AP_HAL_Linux/I2CDevice.cpp index 1c8535918e..83d61fe6f9 100644 --- a/libraries/AP_HAL_Linux/I2CDevice.cpp +++ b/libraries/AP_HAL_Linux/I2CDevice.cpp @@ -177,13 +177,13 @@ bool I2CDevice::transfer(const uint8_t *send, uint32_t send_len, i2c_data.msgs = msgs; i2c_data.nmsgs = nmsgs; - int r = -EINVAL; + int r; unsigned retries = _retries; do { r = ::ioctl(_bus.fd, I2C_RDWR, &i2c_data); - } while (r < 0 && retries-- > 0); + } while (r == -1 && retries-- > 0); - return r >= 0; + return r != -1; } bool I2CDevice::read_registers_multiple(uint8_t first_reg, uint8_t *recv,