HAL_Linux: fixed some valgrind errors

This commit is contained in:
Andrew Tridgell 2014-07-07 13:36:20 +10:00
parent 130f831c1c
commit 8e5915ef7d
3 changed files with 10 additions and 0 deletions

View File

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

View File

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

View File

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