netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: altera_tse: fix init sequence to avoid races with register_netdev
@ 2023-06-11 10:40 Maxime Chevallier
  2023-06-11 15:42 ` Russell King (Oracle)
  0 siblings, 1 reply; 3+ messages in thread
From: Maxime Chevallier @ 2023-06-11 10:40 UTC (permalink / raw)
  To: davem
  Cc: Maxime Chevallier, netdev, linux-kernel, thomas.petazzoni,
	Andrew Lunn, Jakub Kicinski, Eric Dumazet, Paolo Abeni,
	Russell King, linux-arm-kernel, Simon Horman, alexis.lothore

As reported here[1], the init sequence in altera_tse can be racy should
any operation on the registered netdev happen after netdev registration
but before phylink initialization.

Fix the registering order to avoid such races by making register_netdev
the last step of the probing sequence.

[1]: https://lore.kernel.org/netdev/ZH9XK5yEGyoDMIs%2F@shell.armlinux.org.uk/

Fixes: fef2998203e1 ("net: altera: tse: convert to phylink")
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
This patch targets net-next as it fixes a commit that is in net-next
too.

 drivers/net/ethernet/altera/altera_tse_main.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
index 2e15800e5310..54f1b5ad84ce 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -1395,12 +1395,6 @@ static int altera_tse_probe(struct platform_device *pdev)
 	spin_lock_init(&priv->rxdma_irq_lock);
 
 	netif_carrier_off(ndev);
-	ret = register_netdev(ndev);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to register TSE net device\n");
-		goto err_register_netdev;
-	}
-
 	platform_set_drvdata(pdev, ndev);
 
 	priv->revision = ioread32(&priv->mac_dev->megacore_revision);
@@ -1449,12 +1443,16 @@ static int altera_tse_probe(struct platform_device *pdev)
 		goto err_init_phylink;
 	}
 
+	ret = register_netdev(ndev);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to register TSE net device\n");
+		return ret;
+	}
+
 	return 0;
 err_init_phylink:
 	lynx_pcs_destroy(priv->pcs);
 err_init_pcs:
-	unregister_netdev(ndev);
-err_register_netdev:
 	netif_napi_del(&priv->napi);
 	altera_tse_mdio_destroy(ndev);
 err_free_netdev:
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-11 16:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-11 10:40 [PATCH net-next] net: altera_tse: fix init sequence to avoid races with register_netdev Maxime Chevallier
2023-06-11 15:42 ` Russell King (Oracle)
2023-06-11 16:30   ` Maxime Chevallier

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).