From 9f1cece6eecb614fe61bd59645d5303aab131a60 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Sat, 6 Nov 2021 20:32:46 +0100 Subject: [PATCH 1/2] drivers/encx24j600: fix unaligned memory access --- drivers/encx24j600/encx24j600.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/encx24j600/encx24j600.c b/drivers/encx24j600/encx24j600.c index 3f1f8252e7..ef782a7d49 100644 --- a/drivers/encx24j600/encx24j600.c +++ b/drivers/encx24j600/encx24j600.c @@ -326,7 +326,7 @@ static inline int _packets_available(encx24j600_t *dev) static void _get_mac_addr(netdev_t *encdev, uint8_t* buf) { encx24j600_t * dev = (encx24j600_t *) encdev; - uint16_t *addr = (uint16_t *) buf; + uint16_t addr[3]; lock(dev); @@ -334,6 +334,8 @@ static void _get_mac_addr(netdev_t *encdev, uint8_t* buf) addr[1] = reg_get(dev, ENC_MAADR2); addr[2] = reg_get(dev, ENC_MAADR3); + memcpy(buf, addr, sizeof(addr)); + unlock(dev); } From 4c22716001eae40152a413749f6ce62aef2e82c9 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Sun, 7 Nov 2021 08:44:19 +0100 Subject: [PATCH 2/2] drivers/encx24j600: make cppcheck happy Rename cmd buffer to cmd_buf to avoid shadowing outer function. --- drivers/encx24j600/encx24j600.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/encx24j600/encx24j600.c b/drivers/encx24j600/encx24j600.c index ef782a7d49..9cc8c36763 100644 --- a/drivers/encx24j600/encx24j600.c +++ b/drivers/encx24j600/encx24j600.c @@ -149,10 +149,10 @@ static inline void enc_spi_transfer(encx24j600_t *dev, char *out, char *in, int static inline uint16_t reg_get(encx24j600_t *dev, uint8_t reg) { - char cmd[4] = { ENC_RCRU, reg, 0, 0 }; + char cmd_buf[4] = { ENC_RCRU, reg, 0, 0 }; char result[4]; - enc_spi_transfer(dev, cmd, result, 4); + enc_spi_transfer(dev, cmd_buf, result, 4); return result[2] | (result[3] << 8); } @@ -173,20 +173,20 @@ static void cmdn(encx24j600_t *dev, uint8_t cmd, char *out, char *in, int len) { static void reg_set(encx24j600_t *dev, uint8_t reg, uint16_t value) { - char cmd[4] = { ENC_WCRU, reg, value, value >> 8 }; - enc_spi_transfer(dev, cmd, NULL, 4); + char cmd_buf[4] = { ENC_WCRU, reg, value, value >> 8 }; + enc_spi_transfer(dev, cmd_buf, NULL, 4); } static void reg_set_bits(encx24j600_t *dev, uint8_t reg, uint16_t mask) { - char cmd[4] = { ENC_BFSU, reg, mask, mask >> 8 }; - enc_spi_transfer(dev, cmd, NULL, 4); + char cmd_buf[4] = { ENC_BFSU, reg, mask, mask >> 8 }; + enc_spi_transfer(dev, cmd_buf, NULL, 4); } static void reg_clear_bits(encx24j600_t *dev, uint8_t reg, uint16_t mask) { - char cmd[4] = { ENC_BFCU, reg, mask, mask >> 8 }; - enc_spi_transfer(dev, cmd, NULL, 4); + char cmd_buf[4] = { ENC_BFCU, reg, mask, mask >> 8 }; + enc_spi_transfer(dev, cmd_buf, NULL, 4); } /*