From patchwork Tue Jun 29 17:08:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1498491 X-Patchwork-Delegate: priyanka.jain@nxp.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=PXU0HLBV; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GDrZ41VLSz9sWD for ; Wed, 30 Jun 2021 03:09:48 +1000 (AEST) 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) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 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 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 Reviewed-by: Ramon Fried --- 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; }