1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #17156 from maribu/drivers/encx24j600

drivers/encx24j600: fix unaligned memory access
This commit is contained in:
benpicco 2021-11-07 18:55:58 +01:00 committed by GitHub
commit 358abcf133
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) 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]; char result[4];
enc_spi_transfer(dev, cmd, result, 4); enc_spi_transfer(dev, cmd_buf, result, 4);
return result[2] | (result[3] << 8); 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) static void reg_set(encx24j600_t *dev, uint8_t reg, uint16_t value)
{ {
char cmd[4] = { ENC_WCRU, reg, value, value >> 8 }; char cmd_buf[4] = { ENC_WCRU, reg, value, value >> 8 };
enc_spi_transfer(dev, cmd, NULL, 4); enc_spi_transfer(dev, cmd_buf, NULL, 4);
} }
static void reg_set_bits(encx24j600_t *dev, uint8_t reg, uint16_t mask) static void reg_set_bits(encx24j600_t *dev, uint8_t reg, uint16_t mask)
{ {
char cmd[4] = { ENC_BFSU, reg, mask, mask >> 8 }; char cmd_buf[4] = { ENC_BFSU, reg, mask, mask >> 8 };
enc_spi_transfer(dev, cmd, NULL, 4); enc_spi_transfer(dev, cmd_buf, NULL, 4);
} }
static void reg_clear_bits(encx24j600_t *dev, uint8_t reg, uint16_t mask) static void reg_clear_bits(encx24j600_t *dev, uint8_t reg, uint16_t mask)
{ {
char cmd[4] = { ENC_BFCU, reg, mask, mask >> 8 }; char cmd_buf[4] = { ENC_BFCU, reg, mask, mask >> 8 };
enc_spi_transfer(dev, cmd, NULL, 4); enc_spi_transfer(dev, cmd_buf, NULL, 4);
} }
/* /*
@ -326,7 +326,7 @@ static inline int _packets_available(encx24j600_t *dev)
static void _get_mac_addr(netdev_t *encdev, uint8_t* buf) static void _get_mac_addr(netdev_t *encdev, uint8_t* buf)
{ {
encx24j600_t * dev = (encx24j600_t *) encdev; encx24j600_t * dev = (encx24j600_t *) encdev;
uint16_t *addr = (uint16_t *) buf; uint16_t addr[3];
lock(dev); 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[1] = reg_get(dev, ENC_MAADR2);
addr[2] = reg_get(dev, ENC_MAADR3); addr[2] = reg_get(dev, ENC_MAADR3);
memcpy(buf, addr, sizeof(addr));
unlock(dev); unlock(dev);
} }