smbus: fix invalid memory access in read_word()

read_word() expected 3 bytes (uint16_t + PEC byte), but was passed an
address to an uint16_t value.

write_word() is changed to be type-safe as well.
This commit is contained in:
Beat Küng
2019-11-07 10:56:27 +01:00
parent e772ddf012
commit 32359168d6
3 changed files with 44 additions and 49 deletions
+7 -7
View File
@@ -55,7 +55,7 @@ public:
* @param cmd_code The command code.
* @param data The data to be written.
* @param length The number of bytes being written.
* @return Returns PX4_OK on success, PX4_ERROR on failure.
* @return Returns PX4_OK on success, -errno on failure.
*/
int block_write(const uint8_t cmd_code, void *data, uint8_t byte_count, bool use_pec);
@@ -64,7 +64,7 @@ public:
* @param cmd_code The command code.
* @param data The returned data.
* @param length The number of bytes being read
* @return Returns PX4_OK on success, PX4_ERROR on failure.
* @return Returns PX4_OK on success, -errno on failure.
*/
int block_read(const uint8_t cmd_code, void *data, const uint8_t length, bool use_pec);
@@ -72,23 +72,23 @@ public:
* @brief Sends a read word command.
* @param cmd_code The command code.
* @param data The 2 bytes of returned data plus a 1 byte CRC if used.
* @return Returns PX4_OK on success, PX4_ERROR on failure.
* @return Returns PX4_OK on success, -errno on failure.
*/
int read_word(const uint8_t cmd_code, void *data);
int read_word(const uint8_t cmd_code, uint16_t &data);
/**
* @brief Sends a write word command.
* @param cmd_code The command code.
* @param data The 2 bytes of data to be transfered.
* @return Returns PX4_OK on success, PX4_ERROR on failure.
* @return Returns PX4_OK on success, -errno on failure.
*/
int write_word(const uint8_t cmd_code, void *data);
int write_word(const uint8_t cmd_code, uint16_t data);
/**
* @brief Calculates the PEC from the data.
* @param buffer The buffer that stores the data to perform the CRC over.
* @param length The number of bytes being written.
* @return Returns PX4_OK on success, PX4_ERROR on failure.
* @return Returns PX4_OK on success, -errno on failure.
*/
uint8_t get_pec(uint8_t *buffer, uint8_t length);