All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauri Sandberg <maukka@ext.kapsi.fi>
To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Mauri Sandberg <maukka@ext.kapsi.fi>,
	Andrew Lunn <andrew@lunn.ch>
Subject: [PATCH v2] net: mv643xx_eth: process retval from of_get_mac_address
Date: Wed, 23 Feb 2022 16:23:37 +0200	[thread overview]
Message-ID: <20220223142337.41757-1-maukka@ext.kapsi.fi> (raw)
In-Reply-To: <20220221062441.2685-1-maukka@ext.kapsi.fi>

Obtaining a MAC address may be deferred in cases when the MAC is stored
in an NVMEM block, for example, and it may not be ready upon the first
retrieval attempt and return EPROBE_DEFER.

It is also possible that a port that does not rely on NVMEM has been
already created when getting the defer request. Thus, also the resources
allocated previously must be freed when doing a roll-back.

Signed-off-by: Mauri Sandberg <maukka@ext.kapsi.fi>
Cc: Andrew Lunn <andrew@lunn.ch>
---
v1 -> v2
 - escalate all error values from of_get_mac_address()
 - move mv643xx_eth_shared_of_remove() before
   mv643xx_eth_shared_of_probe()
 - release all resources potentially allocated for previous port nodes
 - update commit title and message
---
 drivers/net/ethernet/marvell/mv643xx_eth.c | 24 +++++++++++++---------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index 105247582684..143ca8be5eb5 100644
--- a/drivers/net/ethernet/marvell/mv643xx_eth.c
+++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -2704,6 +2704,16 @@ MODULE_DEVICE_TABLE(of, mv643xx_eth_shared_ids);
 
 static struct platform_device *port_platdev[3];
 
+static void mv643xx_eth_shared_of_remove(void)
+{
+	int n;
+
+	for (n = 0; n < 3; n++) {
+		platform_device_del(port_platdev[n]);
+		port_platdev[n] = NULL;
+	}
+}
+
 static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,
 					  struct device_node *pnp)
 {
@@ -2740,7 +2750,9 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,
 		return -EINVAL;
 	}
 
-	of_get_mac_address(pnp, ppd.mac_addr);
+	ret = of_get_mac_address(pnp, ppd.mac_addr);
+	if (ret)
+		return ret;
 
 	mv643xx_eth_property(pnp, "tx-queue-size", ppd.tx_queue_size);
 	mv643xx_eth_property(pnp, "tx-sram-addr", ppd.tx_sram_addr);
@@ -2804,21 +2816,13 @@ static int mv643xx_eth_shared_of_probe(struct platform_device *pdev)
 		ret = mv643xx_eth_shared_of_add_port(pdev, pnp);
 		if (ret) {
 			of_node_put(pnp);
+			mv643xx_eth_shared_of_remove();
 			return ret;
 		}
 	}
 	return 0;
 }
 
-static void mv643xx_eth_shared_of_remove(void)
-{
-	int n;
-
-	for (n = 0; n < 3; n++) {
-		platform_device_del(port_platdev[n]);
-		port_platdev[n] = NULL;
-	}
-}
 #else
 static inline int mv643xx_eth_shared_of_probe(struct platform_device *pdev)
 {

base-commit: cfb92440ee71adcc2105b0890bb01ac3cddb8507
-- 
2.25.1


  parent reply	other threads:[~2022-02-23 14:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-21  6:24 [PATCH] net: mv643xx_eth: handle EPROBE_DEFER Mauri Sandberg
2022-02-21 12:21 ` Andrew Lunn
2022-02-21 18:25   ` Mauri Sandberg
2022-02-21 22:15     ` Andrew Lunn
2022-02-22  5:42       ` Mauri Sandberg
2022-02-23 14:23 ` Mauri Sandberg [this message]
2022-02-24 16:57   ` [PATCH v2] net: mv643xx_eth: process retval from of_get_mac_address Jakub Kicinski
2022-02-24 17:43     ` Andrew Lunn
2022-02-24 18:20   ` patchwork-bot+netdevbpf

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=20220223142337.41757-1-maukka@ext.kapsi.fi \
    --to=maukka@ext.kapsi.fi \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sebastian.hesselbarth@gmail.com \
    /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.