Message ID | 20211009173346.7859-9-kabel@kernel.org |
---|---|
State | Accepted |
Commit | 0034d84a66eaa51263a4881274b75de5b1c4f800 |
Delegated to: | Stefan Roese |
Headers | show |
Series | Small Turris MOX and Omnia changes | expand |
On 09.10.21 19:33, Marek Behún wrote: > From: Marek Behún <marek.behun@nic.cz> > > Currently we overwrite ethaddr and eth1addr only if these variables > don't exist. > > Better overwrite them even if the env variable exists, but is invalid - > eth_env_get_enetaddr_by_index() checks for validity. > > Refactor the code to use a for cycle. > > Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de> Thanks, Stefan > --- > board/CZ.NIC/turris_mox/turris_mox.c | 16 +++++++++------- > 1 file changed, 9 insertions(+), 7 deletions(-) > > diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c > index 7c5acfd1d9..2202eb8cfb 100644 > --- a/board/CZ.NIC/turris_mox/turris_mox.c > +++ b/board/CZ.NIC/turris_mox/turris_mox.c > @@ -359,20 +359,22 @@ static int get_reset_gpio(struct gpio_desc *reset_gpio) > > int misc_init_r(void) > { > - int ret; > - u8 mac1[6], mac2[6]; > + u8 mac[2][6]; > + int i, ret; > > - ret = mbox_sp_get_board_info(NULL, mac1, mac2, NULL, NULL); > + ret = mbox_sp_get_board_info(NULL, mac[0], mac[1], NULL, NULL); > if (ret < 0) { > printf("Cannot read data from OTP!\n"); > return 0; > } > > - if (is_valid_ethaddr(mac1) && !env_get("ethaddr")) > - eth_env_set_enetaddr("ethaddr", mac1); > + for (i = 0; i < 2; ++i) { > + u8 oldmac[6]; > > - if (is_valid_ethaddr(mac2) && !env_get("eth1addr")) > - eth_env_set_enetaddr("eth1addr", mac2); > + if (is_valid_ethaddr(mac[i]) && > + !eth_env_get_enetaddr_by_index("eth", i, oldmac)) > + eth_env_set_enetaddr_by_index("eth", i, mac[i]); > + } > > return 0; > } > Viele Grüße, Stefan
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 7c5acfd1d9..2202eb8cfb 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -359,20 +359,22 @@ static int get_reset_gpio(struct gpio_desc *reset_gpio) int misc_init_r(void) { - int ret; - u8 mac1[6], mac2[6]; + u8 mac[2][6]; + int i, ret; - ret = mbox_sp_get_board_info(NULL, mac1, mac2, NULL, NULL); + ret = mbox_sp_get_board_info(NULL, mac[0], mac[1], NULL, NULL); if (ret < 0) { printf("Cannot read data from OTP!\n"); return 0; } - if (is_valid_ethaddr(mac1) && !env_get("ethaddr")) - eth_env_set_enetaddr("ethaddr", mac1); + for (i = 0; i < 2; ++i) { + u8 oldmac[6]; - if (is_valid_ethaddr(mac2) && !env_get("eth1addr")) - eth_env_set_enetaddr("eth1addr", mac2); + if (is_valid_ethaddr(mac[i]) && + !eth_env_get_enetaddr_by_index("eth", i, oldmac)) + eth_env_set_enetaddr_by_index("eth", i, mac[i]); + } return 0; }