diff --git a/drivers/ethernet/eth.h b/drivers/ethernet/eth.h index ebbff29a9d9..f7e7ab79a4a 100644 --- a/drivers/ethernet/eth.h +++ b/drivers/ethernet/eth.h @@ -32,10 +32,6 @@ static inline void gen_random_mac(uint8_t *mac_addr, uint8_t b0, uint8_t b1, uint8_t b2) { - uint32_t entropy; - - entropy = sys_rand32_get(); - mac_addr[0] = b0; mac_addr[1] = b1; mac_addr[2] = b2; @@ -43,9 +39,7 @@ static inline void gen_random_mac(uint8_t *mac_addr, uint8_t b0, uint8_t b1, uin /* Set MAC address locally administered, unicast (LAA) */ mac_addr[0] |= 0x02; - mac_addr[3] = (entropy >> 16) & 0xff; - mac_addr[4] = (entropy >> 8) & 0xff; - mac_addr[5] = (entropy >> 0) & 0xff; + sys_rand_get(&mac_addr[3], 3U); } #endif /* ZEPHYR_DRIVERS_ETHERNET_ETH_H_ */ diff --git a/drivers/ethernet/eth_ivshmem.c b/drivers/ethernet/eth_ivshmem.c index 0d2c104359a..ae8135f2e22 100644 --- a/drivers/ethernet/eth_ivshmem.c +++ b/drivers/ethernet/eth_ivshmem.c @@ -390,10 +390,7 @@ static const struct ethernet_api eth_ivshmem_api = { #define ETH_IVSHMEM_RANDOM_MAC_ADDR(inst) \ static void generate_mac_addr_##inst(uint8_t mac_addr[6]) \ { \ - uint32_t entropy = sys_rand32_get(); \ - mac_addr[0] = (entropy >> 16) & 0xff; \ - mac_addr[1] = (entropy >> 8) & 0xff; \ - mac_addr[2] = (entropy >> 0) & 0xff; \ + sys_rand_get(mac_addr, 3U); \ /* Clear multicast bit */ \ mac_addr[0] &= 0xFE; \ gen_random_mac(mac_addr, mac_addr[0], mac_addr[1], mac_addr[2]); \