Commit aa4ac90d authored by Tariq Toukan's avatar Tariq Toukan Committed by Jakub Kicinski

net/mlx5: SD, Handle possible devcom ERR_PTR

Check if devcom holds an error pointer and return immediately.

This fixes Smatch static checker warning:
drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c:221 sd_register()
error: 'devcom' dereferencing possible ERR_PTR()

Enhance mlx5_devcom_register_component() so it stops returning NULL,
making it easier for its callers.

Fixes: d3d05766 ("net/mlx5: SD, Implement devcom communication and primary election")
Reported-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/all/f09666c8-e604-41f6-958b-4cc55c73faf9@gmail.com/T/Signed-off-by: default avatarTariq Toukan <tariqt@nvidia.com>
Reviewed-by: default avatarGal Pressman <gal@nvidia.com>
Link: https://lore.kernel.org/r/20240411115444.374475-3-tariqt@nvidia.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 37cc10da
...@@ -209,8 +209,8 @@ static int mlx5e_devcom_init_mpv(struct mlx5e_priv *priv, u64 *data) ...@@ -209,8 +209,8 @@ static int mlx5e_devcom_init_mpv(struct mlx5e_priv *priv, u64 *data)
*data, *data,
mlx5e_devcom_event_mpv, mlx5e_devcom_event_mpv,
priv); priv);
if (IS_ERR_OR_NULL(priv->devcom)) if (IS_ERR(priv->devcom))
return -EOPNOTSUPP; return PTR_ERR(priv->devcom);
if (mlx5_core_is_mp_master(priv->mdev)) { if (mlx5_core_is_mp_master(priv->mdev)) {
mlx5_devcom_send_event(priv->devcom, MPV_DEVCOM_MASTER_UP, mlx5_devcom_send_event(priv->devcom, MPV_DEVCOM_MASTER_UP,
......
...@@ -3060,7 +3060,7 @@ void mlx5_esw_offloads_devcom_init(struct mlx5_eswitch *esw, u64 key) ...@@ -3060,7 +3060,7 @@ void mlx5_esw_offloads_devcom_init(struct mlx5_eswitch *esw, u64 key)
key, key,
mlx5_esw_offloads_devcom_event, mlx5_esw_offloads_devcom_event,
esw); esw);
if (IS_ERR_OR_NULL(esw->devcom)) if (IS_ERR(esw->devcom))
return; return;
mlx5_devcom_send_event(esw->devcom, mlx5_devcom_send_event(esw->devcom,
......
...@@ -220,7 +220,7 @@ mlx5_devcom_register_component(struct mlx5_devcom_dev *devc, ...@@ -220,7 +220,7 @@ mlx5_devcom_register_component(struct mlx5_devcom_dev *devc,
struct mlx5_devcom_comp *comp; struct mlx5_devcom_comp *comp;
if (IS_ERR_OR_NULL(devc)) if (IS_ERR_OR_NULL(devc))
return NULL; return ERR_PTR(-EINVAL);
mutex_lock(&comp_list_lock); mutex_lock(&comp_list_lock);
comp = devcom_component_get(devc, id, key, handler); comp = devcom_component_get(devc, id, key, handler);
......
...@@ -213,8 +213,8 @@ static int sd_register(struct mlx5_core_dev *dev) ...@@ -213,8 +213,8 @@ static int sd_register(struct mlx5_core_dev *dev)
sd = mlx5_get_sd(dev); sd = mlx5_get_sd(dev);
devcom = mlx5_devcom_register_component(dev->priv.devc, MLX5_DEVCOM_SD_GROUP, devcom = mlx5_devcom_register_component(dev->priv.devc, MLX5_DEVCOM_SD_GROUP,
sd->group_id, NULL, dev); sd->group_id, NULL, dev);
if (!devcom) if (IS_ERR(devcom))
return -ENOMEM; return PTR_ERR(devcom);
sd->devcom = devcom; sd->devcom = devcom;
......
...@@ -956,7 +956,7 @@ static void mlx5_register_hca_devcom_comp(struct mlx5_core_dev *dev) ...@@ -956,7 +956,7 @@ static void mlx5_register_hca_devcom_comp(struct mlx5_core_dev *dev)
mlx5_devcom_register_component(dev->priv.devc, MLX5_DEVCOM_HCA_PORTS, mlx5_devcom_register_component(dev->priv.devc, MLX5_DEVCOM_HCA_PORTS,
mlx5_query_nic_system_image_guid(dev), mlx5_query_nic_system_image_guid(dev),
NULL, dev); NULL, dev);
if (IS_ERR_OR_NULL(dev->priv.hca_devcom_comp)) if (IS_ERR(dev->priv.hca_devcom_comp))
mlx5_core_err(dev, "Failed to register devcom HCA component\n"); mlx5_core_err(dev, "Failed to register devcom HCA component\n");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment