Browse Source

HAL_Linux: fixed some valgrind errors

mission-4.1.18
Andrew Tridgell 11 years ago
parent
commit
8e5915ef7d
  1. 4
      libraries/AP_HAL_Linux/I2CDriver.cpp
  2. 5
      libraries/AP_HAL_Linux/SPIDriver.cpp
  3. 1
      libraries/AP_HAL_Linux/UARTDriver.cpp

4
libraries/AP_HAL_Linux/I2CDriver.cpp

@ -162,6 +162,9 @@ uint8_t LinuxI2CDriver::readRegisters(uint8_t addr, uint8_t reg,
nmsgs : 2 nmsgs : 2
}; };
// prevent valgrind error
memset(data, 0, len);
if (ioctl(_fd, I2C_RDWR, &i2c_data) == -1) { if (ioctl(_fd, I2C_RDWR, &i2c_data) == -1) {
return 1; return 1;
} }
@ -207,6 +210,7 @@ uint8_t LinuxI2CDriver::readRegister(uint8_t addr, uint8_t reg, uint8_t* data)
return 1; return 1;
} }
union i2c_smbus_data v; union i2c_smbus_data v;
memset(&v, 0, sizeof(v));
if (_i2c_smbus_access(_fd,I2C_SMBUS_READ, reg, if (_i2c_smbus_access(_fd,I2C_SMBUS_READ, reg,
I2C_SMBUS_BYTE_DATA, &v)) { I2C_SMBUS_BYTE_DATA, &v)) {
return 1; return 1;

5
libraries/AP_HAL_Linux/SPIDriver.cpp

@ -109,6 +109,11 @@ void LinuxSPIDeviceDriver::transaction(const uint8_t *tx, uint8_t *rx, uint16_t
spi[0].speed_hz = _speed; spi[0].speed_hz = _speed;
spi[0].bits_per_word = _bitsPerWord; spi[0].bits_per_word = _bitsPerWord;
spi[0].cs_change = 0; spi[0].cs_change = 0;
if (rx != NULL) {
// keep valgrind happy
memset(rx, 0, len);
}
ioctl(_fd, SPI_IOC_MESSAGE(1), &spi); ioctl(_fd, SPI_IOC_MESSAGE(1), &spi);
cs_release(); cs_release();

1
libraries/AP_HAL_Linux/UARTDriver.cpp

@ -163,6 +163,7 @@ void LinuxUARTDriver::begin(uint32_t b, uint16_t rxS, uint16_t txS)
if (b != 0 && _rd_fd == _wr_fd) { if (b != 0 && _rd_fd == _wr_fd) {
// set the baud rate // set the baud rate
struct termios t; struct termios t;
memset(&t, 0, sizeof(t));
tcgetattr(_rd_fd, &t); tcgetattr(_rd_fd, &t);
cfsetspeed(&t, b); cfsetspeed(&t, b);
// disable LF -> CR/LF // disable LF -> CR/LF

Loading…
Cancel
Save