All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: Joe Hershberger <joe.hershberger@ni.com>,
	Ramon Fried <rfried.dev@gmail.com>,
	u-boot@lists.denx.de
Cc: Claudiu Manoil <claudiu.manoil@nxp.com>,
	Michael Walle <michael@walle.cc>,
	Priyanka Jain <priyanka.jain@nxp.com>
Subject: [PATCH v2 3/6] net: dsa: refactor the code to set the port MAC address into a dedicated function
Date: Tue, 24 Aug 2021 15:00:40 +0300	[thread overview]
Message-ID: <20210824120043.3823931-4-vladimir.oltean@nxp.com> (raw)
In-Reply-To: <20210824120043.3823931-1-vladimir.oltean@nxp.com>

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 <vladimir.oltean@nxp.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Tested-by: Michael Walle <michael@walle.cc>
---
 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


  parent reply	other threads:[~2021-08-24 12:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-24 12:00 [PATCH v2 0/6] Call phy_config at port probe time for the Felix DSA driver Vladimir Oltean
2021-08-24 12:00 ` [PATCH v2 1/6] net: dsa: felix: felix_init() can be static Vladimir Oltean
2021-09-14  9:23   ` Ramon Fried
2021-08-24 12:00 ` [PATCH v2 2/6] net: dsa: use "err" instead of "ret" in dsa_port_probe Vladimir Oltean
2021-09-14  9:23   ` Ramon Fried
2021-08-24 12:00 ` Vladimir Oltean [this message]
2021-09-14  9:23   ` [PATCH v2 3/6] net: dsa: refactor the code to set the port MAC address into a dedicated function Ramon Fried
2021-08-24 12:00 ` [PATCH v2 4/6] net: dsa: introduce a .port_probe() method in struct dsa_ops Vladimir Oltean
2021-09-14  9:24   ` Ramon Fried
2021-08-24 12:00 ` [PATCH v2 5/6] net: dsa: felix: call phy_config at .port_probe() time Vladimir Oltean
2021-08-24 12:00 ` [PATCH v2 6/6] net: dsa: felix: propagate the error code from phy_startup() Vladimir Oltean
2021-09-14  9:24   ` Ramon Fried
2021-08-25 11:08 ` [PATCH v2 0/6] Call phy_config at port probe time for the Felix DSA driver Vladimir Oltean

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210824120043.3823931-4-vladimir.oltean@nxp.com \
    --to=vladimir.oltean@nxp.com \
    --cc=claudiu.manoil@nxp.com \
    --cc=joe.hershberger@ni.com \
    --cc=michael@walle.cc \
    --cc=priyanka.jain@nxp.com \
    --cc=rfried.dev@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.