diff mbox series

[3/6] net: dsa: refactor the code to set the port MAC address into a dedicated function

Message ID 20210629170839.2583797-4-olteanv@gmail.com
State Changes Requested
Delegated to: Priyanka Jain
Headers show
Series Call phy_config at port probe time for the Felix DSA driver | expand

Commit Message

Vladimir Oltean June 29, 2021, 5:08 p.m. UTC
From: Vladimir Oltean <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>
---
 net/dsa-uclass.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

Comments

Ramon Fried June 29, 2021, 10:17 p.m. UTC | #1
On Tue, Jun 29, 2021 at 8:09 PM Vladimir Oltean <olteanv@gmail.com> wrote:
>
> From: Vladimir Oltean <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>
> ---
>  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
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Priyanka Jain July 20, 2021, 9:16 a.m. UTC | #2
>-----Original Message-----
>From: U-Boot <u-boot-bounces@lists.denx.de> On Behalf Of Vladimir Oltean
>Sent: Tuesday, June 29, 2021 10:39 PM
>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>; Bin Meng
><bmeng.cn@gmail.com>; Alexandru Marginean
><alexandru.marginean@nxp.com>; Michael Walle <michael@walle.cc>;
>tharvey@gateworks.com; Vladimir Oltean <vladimir.oltean@nxp.com>
>Subject: [PATCH 3/6] net: dsa: refactor the code to set the port MAC address into
>a dedicated function
>
>From: Vladimir Oltean <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>
>---
> 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

Kindly rebase to top of master branch.

Regards
Priyanka
diff mbox series

Patch

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;
 }