linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
	davem@davemloft.net, kuba@kernel.org, david.daney@cavium.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Subject: [PATCH] net: mdio: thunder: Do not unregister buses that have not been registered
Date: Thu, 13 May 2021 13:51:40 +0200	[thread overview]
Message-ID: <918382e19fdeb172f3836234d07e706460b7d06b.1620906605.git.christophe.jaillet@wanadoo.fr> (raw)

In the probe, if 'of_mdiobus_register()' fails, 'nexus->buses[i]' will
still have a non-NULL value.
So in the remove function, we will try to unregister a bus that has not
been registered.

In order to avoid that NULLify 'nexus->buses[i]'.
'oct_mdio_writeq(0,...)' must also be called here.

Suggested-by: Russell King - ARM Linux admin <linux@armlinux.org.uk>
Fixes: 379d7ac7ca31 ("phy: mdio-thunder: Add driver for Cavium Thunder SoC MDIO buses.")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Calling 'devm_mdiobus_free()' would also be cleaner, IMHO.
I've not added it because:
   - it should be fine, even without it
   - I'm not sure how to use it

The best I could think-of (not even compile tested) is:
   devm_mdiobus_free(&pdev->dev, container_of(mii_bus, struct mdiobus_devres, mii));
which is not very nice looking.
(unless I missed something obvious!)

If I'm correct, just passing 'mii_bus' to have something that look logical
would require changing 'devm_mdiobus_alloc_size()' and
'devm_mdiobus_free()'.
---
 drivers/net/mdio/mdio-thunder.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/mdio/mdio-thunder.c b/drivers/net/mdio/mdio-thunder.c
index 822d2cdd2f35..140c405d4a41 100644
--- a/drivers/net/mdio/mdio-thunder.c
+++ b/drivers/net/mdio/mdio-thunder.c
@@ -97,8 +97,14 @@ static int thunder_mdiobus_pci_probe(struct pci_dev *pdev,
 		bus->mii_bus->write = cavium_mdiobus_write;
 
 		err = of_mdiobus_register(bus->mii_bus, node);
-		if (err)
+		if (err) {
 			dev_err(&pdev->dev, "of_mdiobus_register failed\n");
+			/* non-registered buses must not be unregistered in
+			 * the .remove function
+			 */
+			oct_mdio_writeq(0, bus->register_base + SMI_EN);
+			nexus->buses[i] = NULL;
+		}
 
 		dev_info(&pdev->dev, "Added bus at %llx\n", r.start);
 		if (i >= ARRAY_SIZE(nexus->buses))
-- 
2.30.2


             reply	other threads:[~2021-05-13 11:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-13 11:51 Christophe JAILLET [this message]
2021-05-13 12:16 ` [PATCH] net: mdio: thunder: Do not unregister buses that have not been registered Russell King - ARM Linux admin
2023-02-16  6:45   ` Christophe JAILLET

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=918382e19fdeb172f3836234d07e706460b7d06b.1620906605.git.christophe.jaillet@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=david.daney@cavium.com \
    --cc=hkallweit1@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).