From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EC8FC433EF for ; Sat, 9 Oct 2021 17:35:49 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7D8186108B for ; Sat, 9 Oct 2021 17:35:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7D8186108B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F107F83695; Sat, 9 Oct 2021 19:34:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="JbAHHAe7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CD6F583695; Sat, 9 Oct 2021 19:34:19 +0200 (CEST) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id ACDB38366F for ; Sat, 9 Oct 2021 19:34:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: by mail.kernel.org (Postfix) with ESMTPSA id 731DC60F57; Sat, 9 Oct 2021 17:33:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633800840; bh=joTvuu0GmcYRl3A4nFASyEykm72la+hBaR9Q0YFfjJs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JbAHHAe7dqkkMSwYgabR5iP/8dCYZNQSjccDtKZVuBiKymyXmFZwxGfM/EtuTyXtJ Isjyzn9bOT2W659HPjgzfYDLeOqZhOTmv0qZApDyrGar0U9fr6MmDvb1zM25CVW+B1 70ULdKnCTxJcb1PKbftGA9nMHsaCvfV6r9Du1Opk9PDqP7UCn5qPQ/wt86hUskmIN7 rHt83TBDDbBuiA/p+0UOyxBdLQ/8MjGEf10+G/7EMHZNowjqzmjTkYURj5IicUUv0t Y5pc6mYlhWTVVRaEoYJnbKiI2p7YF/IWcYbUGIJdBRArM2JbOxyQhYfkUHF8ykOOi1 HdWLaQOz5UGww== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, pali@kernel.org, =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH u-boot-marvell 08/12] arm: mvebu: turris_mox: Better check for valid ethernet addresses in env Date: Sat, 9 Oct 2021 19:33:42 +0200 Message-Id: <20211009173346.7859-9-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211009173346.7859-1-kabel@kernel.org> References: <20211009173346.7859-1-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean From: Marek BehĂșn 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 --- 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; } -- 2.32.0