Blob Blame History Raw
From: Leon Romanovsky <leonro@nvidia.com>
Date: Sat, 25 Sep 2021 14:23:01 +0300
Subject: net: dsa: Move devlink registration to be last devlink command
Patch-mainline: v5.16-rc1
Git-commit: bd936bd53b2d9c326a2ba8e12438f57cd5b1fc8a
References: jsc#SLE-19253

This change prevents from users to access device before devlink
is fully configured.

Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Acked-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
 net/dsa/dsa2.c |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -761,7 +761,6 @@ static int dsa_switch_setup(struct dsa_s
 	dl_priv = devlink_priv(ds->devlink);
 	dl_priv->ds = ds;
 
-	devlink_register(ds->devlink);
 	/* Setup devlink port instances now, so that the switch
 	 * setup() can register regions etc, against the ports
 	 */
@@ -787,8 +786,6 @@ static int dsa_switch_setup(struct dsa_s
 	if (err)
 		goto teardown;
 
-	devlink_params_publish(ds->devlink);
-
 	if (!ds->slave_mii_bus && ds->ops->phy_read) {
 		ds->slave_mii_bus = mdiobus_alloc();
 		if (!ds->slave_mii_bus) {
@@ -804,7 +801,7 @@ static int dsa_switch_setup(struct dsa_s
 	}
 
 	ds->setup = true;
-
+	devlink_register(ds->devlink);
 	return 0;
 
 free_slave_mii_bus:
@@ -819,7 +816,6 @@ unregister_devlink_ports:
 	list_for_each_entry(dp, &ds->dst->ports, list)
 		if (dp->ds == ds)
 			dsa_port_devlink_teardown(dp);
-	devlink_unregister(ds->devlink);
 	devlink_free(ds->devlink);
 	ds->devlink = NULL;
 	return err;
@@ -832,6 +828,9 @@ static void dsa_switch_teardown(struct d
 	if (!ds->setup)
 		return;
 
+	if (ds->devlink)
+		devlink_unregister(ds->devlink);
+
 	if (ds->slave_mii_bus && ds->ops->phy_read) {
 		mdiobus_unregister(ds->slave_mii_bus);
 		mdiobus_free(ds->slave_mii_bus);
@@ -847,7 +846,6 @@ static void dsa_switch_teardown(struct d
 		list_for_each_entry(dp, &ds->dst->ports, list)
 			if (dp->ds == ds)
 				dsa_port_devlink_teardown(dp);
-		devlink_unregister(ds->devlink);
 		devlink_free(ds->devlink);
 		ds->devlink = NULL;
 	}