Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 816BBC11F67 for ; Tue, 29 Jun 2021 17:09:46 +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 C0AA261DD2 for ; Tue, 29 Jun 2021 17:09:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C0AA261DD2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 102D2831C0; Tue, 29 Jun 2021 19:09:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="PXU0HLBV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3B4C5831B3; Tue, 29 Jun 2021 19:09:16 +0200 (CEST) Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B09E4831B2 for ; Tue, 29 Jun 2021 19:09:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=olteanv@gmail.com Received: by mail-ed1-x530.google.com with SMTP id df12so32284260edb.2 for ; Tue, 29 Jun 2021 10:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y4/s+YDzA6tY1oYP2HReW/50gHg7EwQyDCj6drsC3gw=; b=PXU0HLBVjjZ8TmiLik3vH8B76mLhpU6WUfCtULPrzcVsibTEdJUmfv+zsMIMsyo2se 3B85BMJkPjl8rtWRaERn0XL6mLKb5JnE+FLn8YISZ2A3KGtbdbcSrDMOOz5JIvZjUKr5 LweC9ZpgZir2BzNGJACabQpegapw8sKCDPumDDw0Kscz1nR7b4ci55Z5GEXhjyn2gb5j sub9N54tvIjIIkto88dyBqpFCBtOJju6/ajX+6UkJKKiJnLaKF0ysDFiVXIN9biwIgWW X+qsoRu9+TWoSe3KW7sBbfO/IJEqGKLpsM6i2jYHTcKzZa7u59+7/ZNyxOmuRZSlwyPs kKDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y4/s+YDzA6tY1oYP2HReW/50gHg7EwQyDCj6drsC3gw=; b=GmOTSiCfZ49GQRvZDcM/4Set3yzMTfe2Q6eW0bp+S6kl4KtJ6qAf+CIwhL7zIu+1/z xjgNCG1hwFcApoKTxwl+pHJNIb/2rfj0wM88/EwTx1w9ig+GPtdumF4JaYbfeALqP1Vn avbHCWOVGPRoEQtu1YZ/NhtqDr650prtHTSwjUJNYB8VCxM2/RJruqxJ8x2pKLjNnFPs 78OaIDa3YW3Zku9iypk/QBYnb5cdvlIbs2x+LEHt6kVq6rkxrxwAdmjfmqOG+z1t5xWQ wU0aw4Zr/yff9/lqD6dHwwZsKo7IfknBQNAaRL8jZadma2B+q/mB0zPWfgp+RL9G0nVU aolw== X-Gm-Message-State: AOAM533xZZd2A25sIK8gE48rU11Tei0rQF65d0QEYTn/3+oK+ZDjS5pe 3D42f2n/kIzCmTNF/v7NzjQ= X-Google-Smtp-Source: ABdhPJws5N+TVm02f39CKgnA4ogBfeX6DNv1MraRrOD4bwaynLGMOhXoVeWyU0CxGZwrb/9RqoMq9Q== X-Received: by 2002:a05:6402:d0a:: with SMTP id eb10mr42587890edb.139.1624986552416; Tue, 29 Jun 2021 10:09:12 -0700 (PDT) Received: from localhost.localdomain ([188.26.224.68]) by smtp.gmail.com with ESMTPSA id h19sm9928525edt.87.2021.06.29.10.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 10:09:12 -0700 (PDT) From: Vladimir Oltean To: Joe Hershberger , Ramon Fried , u-boot@lists.denx.de Cc: Claudiu Manoil , Bin Meng , Alex Marginean , Michael Walle , Tim Harvey , Vladimir Oltean Subject: [PATCH 3/6] net: dsa: refactor the code to set the port MAC address into a dedicated function Date: Tue, 29 Jun 2021 20:08:36 +0300 Message-Id: <20210629170839.2583797-4-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210629170839.2583797-1-olteanv@gmail.com> References: <20210629170839.2583797-1-olteanv@gmail.com> MIME-Version: 1.0 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: Vladimir Oltean This snippet of code has a bothering "if (...) return 0" in it which assumes it is the last piece of code running in dsa_port_probe(). This makes it difficult to add further code at the end of dsa_port_probe() which does not depend on MAC address stuff. So move the code to a dedicated function which returns void and let the code flow through. Signed-off-by: Vladimir Oltean --- net/dsa-uclass.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/net/dsa-uclass.c b/net/dsa-uclass.c index 17b33834f585..e23da2ed0e95 100644 --- a/net/dsa-uclass.c +++ b/net/dsa-uclass.c @@ -240,11 +240,29 @@ static const struct eth_ops dsa_port_ops = { .free_pkt = dsa_port_free_pkt, }; -static int dsa_port_probe(struct udevice *pdev) +/* + * Inherit port's hwaddr from the DSA master, unless the port already has a + * unique MAC address specified in the environment. + */ +static void dsa_port_set_hwaddr(struct udevice *pdev, struct udevice *master) { - struct udevice *dev = dev_get_parent(pdev); struct eth_pdata *eth_pdata, *master_pdata; unsigned char env_enetaddr[ARP_HLEN]; + + eth_env_get_enetaddr_by_index("eth", dev_seq(pdev), env_enetaddr); + if (!is_zero_ethaddr(env_enetaddr)) + return; + + master_pdata = dev_get_plat(master); + eth_pdata = dev_get_plat(pdev); + memcpy(eth_pdata->enetaddr, master_pdata->enetaddr, ARP_HLEN); + eth_env_set_enetaddr_by_index("eth", dev_seq(pdev), + master_pdata->enetaddr); +} + +static int dsa_port_probe(struct udevice *pdev) +{ + struct udevice *dev = dev_get_parent(pdev); struct dsa_port_pdata *port_pdata; struct dsa_priv *dsa_priv; struct udevice *master; @@ -272,19 +290,8 @@ static int dsa_port_probe(struct udevice *pdev) if (err) return err; - /* - * Inherit port's hwaddr from the DSA master, unless the port already - * has a unique MAC address specified in the environment. - */ - eth_env_get_enetaddr_by_index("eth", dev_seq(pdev), env_enetaddr); - if (!is_zero_ethaddr(env_enetaddr)) - return 0; + dsa_port_set_hwaddr(pdev, master); - master_pdata = dev_get_plat(master); - eth_pdata = dev_get_plat(pdev); - memcpy(eth_pdata->enetaddr, master_pdata->enetaddr, ARP_HLEN); - eth_env_set_enetaddr_by_index("eth", dev_seq(pdev), - master_pdata->enetaddr); return 0; } -- 2.25.1