public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Michael Walle <michael@walle.cc>
To: u-boot@lists.denx.de
Subject: [PATCH 4/4] net: dsa: remove master santiy check
Date: Wed, 24 Feb 2021 17:40:42 +0100	[thread overview]
Message-ID: <20210224164042.21747-5-michael@walle.cc> (raw)
In-Reply-To: <20210224164042.21747-1-michael@walle.cc>

Because we probe the master ourselves (and fail if there is no master),
it is not possible that we don't have a master device.

There is one catch though: device removal. We don't support that. It
wasn't supported neither before this patch. Because the master device
was only set in .pre_probe(), if a device was removed master_dev was a
dangling pointer and transmitting a frame cause a panic. I don't see a
good solution without having some sort of notify machanism when a
udevice is removed.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 net/dsa-uclass.c | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/net/dsa-uclass.c b/net/dsa-uclass.c
index d453cc6930..7ea1cb6949 100644
--- a/net/dsa-uclass.c
+++ b/net/dsa-uclass.c
@@ -69,11 +69,6 @@ static int dsa_port_start(struct udevice *pdev)
 	struct dsa_ops *ops = dsa_get_ops(dev);
 	int err;
 
-	if (!master) {
-		dev_err(pdev, "DSA master Ethernet device not found!\n");
-		return -EINVAL;
-	}
-
 	if (ops->port_enable) {
 		struct dsa_port_pdata *port_pdata;
 
@@ -108,13 +103,7 @@ static void dsa_port_stop(struct udevice *pdev)
 		ops->port_disable(dev, priv->cpu_port, NULL);
 	}
 
-	/*
-	 * stop master only if it's active, don't probe it otherwise.
-	 * Under normal usage it would be active because we're using it, but
-	 * during tear-down it may have been removed ahead of us.
-	 */
-	if (master && device_active(master))
-		eth_get_ops(master)->stop(master);
+	eth_get_ops(master)->stop(master);
 }
 
 /*
@@ -133,9 +122,6 @@ static int dsa_port_send(struct udevice *pdev, void *packet, int length)
 	struct dsa_port_pdata *port_pdata;
 	int err;
 
-	if (!master)
-		return -EINVAL;
-
 	if (length + head + tail > PKTSIZE_ALIGN)
 		return -EINVAL;
 
@@ -165,9 +151,6 @@ static int dsa_port_recv(struct udevice *pdev, int flags, uchar **packetp)
 	struct dsa_port_pdata *port_pdata;
 	int length, port_index, err;
 
-	if (!master)
-		return -EINVAL;
-
 	length = eth_get_ops(master)->recv(master, flags, packetp);
 	if (length <= 0)
 		return length;
@@ -201,9 +184,6 @@ static int dsa_port_free_pkt(struct udevice *pdev, uchar *packet, int length)
 	struct udevice *master = dsa_get_master(dev);
 	struct dsa_priv *priv;
 
-	if (!master)
-		return -EINVAL;
-
 	priv = dev_get_uclass_priv(dev);
 	if (eth_get_ops(master)->free_pkt) {
 		/* return the original pointer and length to master Eth */
@@ -284,6 +264,9 @@ static int dsa_port_probe(struct udevice *pdev)
 	/*
 	 * Probe the master device. We depend on the master device for proper
 	 * operation and we also need it for MAC inheritance below.
+	 *
+	 * TODO: we assume the master device is always there and doesn't get
+	 * removed during runtime.
 	 */
 	ret = device_probe(master);
 	if (ret)
-- 
2.20.1

  parent reply	other threads:[~2021-02-24 16:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-24 16:40 [PATCH 0/4] net: dsa: various fixes Michael Walle
2021-02-24 16:40 ` [PATCH 1/4] net: dsa: return early if there is no master Michael Walle
2021-02-25 19:12   ` Ramon Fried
2021-02-24 16:40 ` [PATCH 2/4] net: dsa: probe master device Michael Walle
2021-02-25 19:13   ` Ramon Fried
2021-02-24 16:40 ` [PATCH 3/4] net: dsa: remove NULL check for priv and platform data Michael Walle
2021-02-24 22:23   ` Vladimir Oltean
2021-02-25 19:14     ` Ramon Fried
2021-02-24 16:40 ` Michael Walle [this message]
2021-02-24 17:11   ` [PATCH 4/4] net: dsa: remove master santiy check Vladimir Oltean
2021-02-24 17:29     ` Michael Walle
2021-02-24 17:45       ` Vladimir Oltean
2021-02-24 18:08         ` Michael Walle
2021-02-24 18:19           ` Vladimir Oltean
2021-02-24 19:03             ` Michael Walle
2021-02-24 21:40               ` Vladimir Oltean
2021-02-24 22:25   ` Vladimir Oltean
2021-02-24 22:52   ` Michael Walle

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=20210224164042.21747-5-michael@walle.cc \
    --to=michael@walle.cc \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox