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 X-Spam-Level: X-Spam-Status: No, score=-12.7 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 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 BB36BC433F5 for ; Tue, 14 Sep 2021 09:24:38 +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 ED44561056 for ; Tue, 14 Sep 2021 09:24:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org ED44561056 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com 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 31C6D8313F; Tue, 14 Sep 2021 11:24:31 +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="KhpJPigt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3A58883278; Tue, 14 Sep 2021 11:24:24 +0200 (CEST) Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) (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 5077383143 for ; Tue, 14 Sep 2021 11:24: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=rfried.dev@gmail.com Received: by mail-ot1-x32c.google.com with SMTP id g66-20020a9d12c8000000b0051aeba607f1so17492851otg.11 for ; Tue, 14 Sep 2021 02:24:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Fd7/ux5tOy7jf+t8fGSp9TuR4dYNjfa7sZmfD+lc/zY=; b=KhpJPigtHt7LCh8ubCSOCOAYoGLW62kKbEbJuZub2EOGY+uecbMpOy7/oo2OTqcMx1 RU1Su+XOGsOK19/Zr4DNe9y7Q2oyC5CZNxDxcJBvmu6C1o53dJHQGyJ3CwgGtTvBPZNb bLPzPl04NDJJLIdhCaBojTkV/JbdXTScnNdatxKJN9kE8xqNWzyBr4CQWiOYzL67vzau JmU83eaP9Hi7VgYK/L7mofRfOKn3F+OgOg1BOtFCWVBbU/E+Vabr1+3veq88l7hsnvE9 StCVXblJRZy9avy8PpXJzrz8RQYwBrjYlrykPU5TreMa07IUgMaELiWfDpWLaUzpyv/x QSag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Fd7/ux5tOy7jf+t8fGSp9TuR4dYNjfa7sZmfD+lc/zY=; b=sKBx3n1j8B7YAKoLB5V5JGwtzK3lTS/ECuIbeaUUxFMdq7x/opSVm428f/kaYc3xpI HuihHhE8eEi8x2HY2jg8UwpshM7PjNegVaehKOVM+3LOCfmMgNlfLpAg6owki8L8QJDJ Zm5TGkf/ChH6wX2+GswELVp5GdGVxedro0EfssNl+wyyF/Ao0uSDZAweR37n1j5VIwGn vHxvhoiGRkAsIfzxttlmP9pQxjGg9DCZC9HPQZJQBL8yVNEtmP60Jr+DJMH5B8wq4oZB +tssbgsxNy9ZX21ZFq5xi6ToKJcCfcGbY70bJlsRjVQDgsvD61d6YBRIv8L4TDeWBkjZ 9Tpw== X-Gm-Message-State: AOAM532kTCq4TEvSsEe8yWLBspG7Pq2W8DMS0E8QWtgO81W/eLZ/C46M Yqhk5MYuEwxJulO1cN1LVaZUZcEXx0esrstMfIY= X-Google-Smtp-Source: ABdhPJzfjk+Srp+gAilkbT9ctPO6dtZcDDq3eG2ewCMuV5K8ok2oKxccE8VxUKs/N3Zhs4dq5yofDtEL0IOrtjFWyR4= X-Received: by 2002:a9d:527:: with SMTP id 36mr14090007otw.363.1631611451013; Tue, 14 Sep 2021 02:24:11 -0700 (PDT) MIME-Version: 1.0 References: <20210824120043.3823931-1-vladimir.oltean@nxp.com> <20210824120043.3823931-4-vladimir.oltean@nxp.com> In-Reply-To: <20210824120043.3823931-4-vladimir.oltean@nxp.com> From: Ramon Fried Date: Tue, 14 Sep 2021 12:23:59 +0300 Message-ID: Subject: Re: [PATCH v2 3/6] net: dsa: refactor the code to set the port MAC address into a dedicated function To: Vladimir Oltean Cc: Joe Hershberger , U-Boot Mailing List , Claudiu Manoil , Michael Walle , Priyanka Jain Content-Type: text/plain; charset="UTF-8" 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 On Tue, Aug 24, 2021 at 3:01 PM Vladimir Oltean wrote: > > 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 > Reviewed-by: Ramon Fried > Tested-by: Michael Walle > --- > net/dsa-uclass.c | 50 +++++++++++++++++++++++++++--------------------- > 1 file changed, 28 insertions(+), 22 deletions(-) > > diff --git a/net/dsa-uclass.c b/net/dsa-uclass.c > index f279ca7d2d6c..dbd8558b6486 100644 > --- a/net/dsa-uclass.c > +++ b/net/dsa-uclass.c > @@ -240,11 +240,36 @@ 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)) { > + /* individual port mac addrs require master to be promisc */ > + struct eth_ops *eth_ops = eth_get_ops(master); > + > + if (eth_ops->set_promisc) > + eth_ops->set_promisc(master, 1); > + > + 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,26 +297,7 @@ 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)) { > - /* individual port mac addrs require master to be promisc */ > - struct eth_ops *eth_ops = eth_get_ops(master); > - > - if (eth_ops->set_promisc) > - eth_ops->set_promisc(master, 1); > - > - return 0; > - } > - > - 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); > + dsa_port_set_hwaddr(pdev, master); > > return 0; > } > -- > 2.25.1 > Applied to u-boot-net/network-master Thanks, Ramon.