diff options
author | Vladyslav Tarasiuk <vladyslavt@nvidia.com> | 2021-04-13 11:15:49 +0300 |
---|---|---|
committer | Saeed Mahameed <saeedm@nvidia.com> | 2021-04-19 20:17:06 -0700 |
commit | 6a5689ba0259acded00f69856fc364b158c54c2e (patch) | |
tree | 190eebc289b79fa87b53889558a443e6ce5e79b3 /drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c | |
parent | d408c01caef41d8ab1b43203164c8b6cbf18d084 (diff) | |
download | linux-stable-6a5689ba0259acded00f69856fc364b158c54c2e.tar.gz linux-stable-6a5689ba0259acded00f69856fc364b158c54c2e.tar.bz2 linux-stable-6a5689ba0259acded00f69856fc364b158c54c2e.zip |
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>
Diffstat (limited to 'drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c')
-rw-r--r-- | drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c index 765f3064689d..0dd7615e5931 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c @@ -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; } |