net/mlx5e: Move devlink port registration to be done before netdev alloc
authorJiri Pirko <jiri@nvidia.com>
Wed, 18 Jan 2023 14:52:33 +0000 (15:52 +0100)
committerSaeed Mahameed <saeedm@nvidia.com>
Tue, 14 Feb 2023 22:08:26 +0000 (14:08 -0800)
Move the devlink port registration to be done right after devlink
instance registration.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/en_main.c

index f7ed130e9a0cdfd57697bec8ed9b1ef593b00e35..ea7c10e5d7dca83bc4078ad1959831f680228dca 100644 (file)
@@ -5903,12 +5903,19 @@ static int mlx5e_probe(struct auxiliary_device *adev,
                return PTR_ERR(mlx5e_dev);
        auxiliary_set_drvdata(adev, mlx5e_dev);
 
+       err = mlx5e_devlink_port_register(mlx5e_dev, mdev);
+       if (err) {
+               mlx5_core_err(mdev, "mlx5e_devlink_port_register failed, %d\n", err);
+               goto err_devlink_unregister;
+       }
+
        netdev = mlx5e_create_netdev(mdev, profile);
        if (!netdev) {
                mlx5_core_err(mdev, "mlx5e_create_netdev failed\n");
                err = -ENOMEM;
-               goto err_devlink_unregister;
+               goto err_devlink_port_unregister;
        }
+       SET_NETDEV_DEVLINK_PORT(netdev, &mlx5e_dev->dl_port);
 
        mlx5e_build_nic_netdev(netdev);
 
@@ -5921,17 +5928,10 @@ static int mlx5e_probe(struct auxiliary_device *adev,
        priv->dfs_root = debugfs_create_dir("nic",
                                            mlx5_debugfs_get_dev_root(priv->mdev));
 
-       err = mlx5e_devlink_port_register(mlx5e_dev, mdev);
-       if (err) {
-               mlx5_core_err(mdev, "mlx5e_devlink_port_register failed, %d\n", err);
-               goto err_destroy_netdev;
-       }
-       SET_NETDEV_DEVLINK_PORT(netdev, &mlx5e_dev->dl_port);
-
        err = profile->init(mdev, netdev);
        if (err) {
                mlx5_core_err(mdev, "mlx5e_nic_profile init failed, %d\n", err);
-               goto err_devlink_cleanup;
+               goto err_destroy_netdev;
        }
 
        err = mlx5e_resume(adev);
@@ -5955,11 +5955,11 @@ err_resume:
        mlx5e_suspend(adev, state);
 err_profile_cleanup:
        profile->cleanup(priv);
-err_devlink_cleanup:
-       mlx5e_devlink_port_unregister(mlx5e_dev);
 err_destroy_netdev:
        debugfs_remove_recursive(priv->dfs_root);
        mlx5e_destroy_netdev(priv);
+err_devlink_port_unregister:
+       mlx5e_devlink_port_unregister(mlx5e_dev);
 err_devlink_unregister:
        mlx5e_destroy_devlink(mlx5e_dev);
        return err;
@@ -5976,9 +5976,9 @@ static void mlx5e_remove(struct auxiliary_device *adev)
        unregister_netdev(priv->netdev);
        mlx5e_suspend(adev, state);
        priv->profile->cleanup(priv);
-       mlx5e_devlink_port_unregister(mlx5e_dev);
        debugfs_remove_recursive(priv->dfs_root);
        mlx5e_destroy_netdev(priv);
+       mlx5e_devlink_port_unregister(mlx5e_dev);
        mlx5e_destroy_devlink(mlx5e_dev);
 }