net/mlx5e: Fix possible non-initialized struct usage
If mlx5e_devlink_port_register() fails, driver may try to register devlink health TX and RX reporters on non-registered devlink port. Instead, create health reporters only if mlx5e_devlink_port_register() does not fail. And destroy reporters only if devlink_port is registered. Also, change mlx5e_get_devlink_port() behavior and return NULL in case port is not registered to replicate devlink's wrapper when ndo is not implemented. Signed-off-by: Vladyslav Tarasiuk <vladyslavt@nvidia.com> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
This commit is contained in:
parent
d408c01cae
commit
6a5689ba02
@ -55,12 +55,17 @@ void mlx5e_devlink_port_unregister(struct mlx5e_priv *priv)
|
||||
{
|
||||
struct devlink_port *dl_port = mlx5e_devlink_get_dl_port(priv);
|
||||
|
||||
devlink_port_unregister(dl_port);
|
||||
if (dl_port->registered)
|
||||
devlink_port_unregister(dl_port);
|
||||
}
|
||||
|
||||
struct devlink_port *mlx5e_get_devlink_port(struct net_device *dev)
|
||||
{
|
||||
struct mlx5e_priv *priv = netdev_priv(dev);
|
||||
struct devlink_port *port;
|
||||
|
||||
return mlx5e_devlink_get_dl_port(priv);
|
||||
port = mlx5e_devlink_get_dl_port(priv);
|
||||
if (port->registered)
|
||||
return port;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -4886,6 +4886,7 @@ static int mlx5e_nic_init(struct mlx5_core_dev *mdev,
|
||||
struct net_device *netdev)
|
||||
{
|
||||
struct mlx5e_priv *priv = netdev_priv(netdev);
|
||||
struct devlink_port *dl_port;
|
||||
int err;
|
||||
|
||||
mlx5e_build_nic_params(priv, &priv->xsk, netdev->mtu);
|
||||
@ -4901,14 +4902,19 @@ static int mlx5e_nic_init(struct mlx5_core_dev *mdev,
|
||||
if (err)
|
||||
mlx5_core_err(mdev, "TLS initialization failed, %d\n", err);
|
||||
|
||||
mlx5e_health_create_reporters(priv);
|
||||
dl_port = mlx5e_devlink_get_dl_port(priv);
|
||||
if (dl_port->registered)
|
||||
mlx5e_health_create_reporters(priv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mlx5e_nic_cleanup(struct mlx5e_priv *priv)
|
||||
{
|
||||
mlx5e_health_destroy_reporters(priv);
|
||||
struct devlink_port *dl_port = mlx5e_devlink_get_dl_port(priv);
|
||||
|
||||
if (dl_port->registered)
|
||||
mlx5e_health_destroy_reporters(priv);
|
||||
mlx5e_tls_cleanup(priv);
|
||||
mlx5e_ipsec_cleanup(priv);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user