drivers: ethernet: use sys_rand_get directly

use sys_rand_get() directly.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
This commit is contained in:
Fin Maaß 2024-04-03 11:41:06 +02:00 committed by Carles Cufí
parent 9e8e21b36f
commit 792cbb9a24
2 changed files with 2 additions and 11 deletions

View File

@ -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_ */

View File

@ -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]); \