]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net/mlx5: Refactor devcom to return NULL on failure
authorPatrisious Haddad <phaddad@nvidia.com>
Wed, 22 Oct 2025 12:29:41 +0000 (15:29 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 23 Oct 2025 14:14:33 +0000 (07:14 -0700)
Devcom device and component registration isn't always critical to the
functionality of the caller, hence the registration can fail and we can
continue working with an ERR_PTR value saved inside a variable.

In order to avoid that make sure all devcom failures return NULL.

Signed-off-by: Patrisious Haddad <phaddad@nvidia.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/1761136182-918470-4-git-send-email-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c
drivers/net/ethernet/mellanox/mlx5/core/main.c

index a56825921c2308f8c89289664a30f756c01995eb..41fd5eee6306200efee8893223faed7c45b9f490 100644 (file)
@@ -242,8 +242,8 @@ static int mlx5e_devcom_init_mpv(struct mlx5e_priv *priv, u64 *data)
                                                      &attr,
                                                      mlx5e_devcom_event_mpv,
                                                      priv);
-       if (IS_ERR(priv->devcom))
-               return PTR_ERR(priv->devcom);
+       if (!priv->devcom)
+               return -EINVAL;
 
        if (mlx5_core_is_mp_master(priv->mdev)) {
                mlx5_devcom_send_event(priv->devcom, MPV_DEVCOM_MASTER_UP,
@@ -256,7 +256,7 @@ static int mlx5e_devcom_init_mpv(struct mlx5e_priv *priv, u64 *data)
 
 static void mlx5e_devcom_cleanup_mpv(struct mlx5e_priv *priv)
 {
-       if (IS_ERR_OR_NULL(priv->devcom))
+       if (!priv->devcom)
                return;
 
        if (mlx5_core_is_mp_master(priv->mdev)) {
index 4cf995be127d10a91e3e86ef883cb5f3280a126e..34749814f19b86d2901e4e14c9ea43e2400582d1 100644 (file)
@@ -3129,7 +3129,7 @@ void mlx5_esw_offloads_devcom_init(struct mlx5_eswitch *esw,
                                                     attr,
                                                     mlx5_esw_offloads_devcom_event,
                                                     esw);
-       if (IS_ERR(esw->devcom))
+       if (!esw->devcom)
                return;
 
        mlx5_devcom_send_event(esw->devcom,
@@ -3140,7 +3140,7 @@ void mlx5_esw_offloads_devcom_init(struct mlx5_eswitch *esw,
 
 void mlx5_esw_offloads_devcom_cleanup(struct mlx5_eswitch *esw)
 {
-       if (IS_ERR_OR_NULL(esw->devcom))
+       if (!esw->devcom)
                return;
 
        mlx5_devcom_send_event(esw->devcom,
index 59c00c9112757a64f0e0744da14ed818d945380d..3db0387bf6dcb727a65df9d0253f242554af06db 100644 (file)
@@ -1430,11 +1430,10 @@ static int mlx5_lag_register_hca_devcom_comp(struct mlx5_core_dev *dev)
                mlx5_devcom_register_component(dev->priv.devc,
                                               MLX5_DEVCOM_HCA_PORTS,
                                               &attr, NULL, dev);
-       if (IS_ERR(dev->priv.hca_devcom_comp)) {
+       if (!dev->priv.hca_devcom_comp) {
                mlx5_core_err(dev,
-                             "Failed to register devcom HCA component, err: %ld\n",
-                             PTR_ERR(dev->priv.hca_devcom_comp));
-               return PTR_ERR(dev->priv.hca_devcom_comp);
+                             "Failed to register devcom HCA component.");
+               return -EINVAL;
        }
 
        return 0;
index d0ba83d77cd16c82add28f5d0d069a6a35ef04ef..29e7fa09c32c8cd04f9225dc85dcaa11d1fec110 100644 (file)
@@ -1444,7 +1444,7 @@ static void mlx5_shared_clock_register(struct mlx5_core_dev *mdev, u64 key)
        compd = mlx5_devcom_register_component(mdev->priv.devc,
                                               MLX5_DEVCOM_SHARED_CLOCK,
                                               &attr, NULL, mdev);
-       if (IS_ERR(compd))
+       if (!compd)
                return;
 
        mdev->clock_state->compdev = compd;
index faa2833602c89603e19f9bb25b26107e5575aa04..e749618229bc09f9c428406899d5d8ab878b23f6 100644 (file)
@@ -76,20 +76,18 @@ mlx5_devcom_dev_alloc(struct mlx5_core_dev *dev)
 struct mlx5_devcom_dev *
 mlx5_devcom_register_device(struct mlx5_core_dev *dev)
 {
-       struct mlx5_devcom_dev *devc;
+       struct mlx5_devcom_dev *devc = NULL;
 
        mutex_lock(&dev_list_lock);
 
        if (devcom_dev_exists(dev)) {
-               devc = ERR_PTR(-EEXIST);
+               mlx5_core_err(dev, "devcom device already exists");
                goto out;
        }
 
        devc = mlx5_devcom_dev_alloc(dev);
-       if (!devc) {
-               devc = ERR_PTR(-ENOMEM);
+       if (!devc)
                goto out;
-       }
 
        list_add_tail(&devc->list, &devcom_dev_list);
 out:
@@ -110,8 +108,10 @@ mlx5_devcom_dev_release(struct kref *ref)
 
 void mlx5_devcom_unregister_device(struct mlx5_devcom_dev *devc)
 {
-       if (!IS_ERR_OR_NULL(devc))
-               kref_put(&devc->ref, mlx5_devcom_dev_release);
+       if (!devc)
+               return;
+
+       kref_put(&devc->ref, mlx5_devcom_dev_release);
 }
 
 static struct mlx5_devcom_comp *
@@ -122,7 +122,7 @@ mlx5_devcom_comp_alloc(u64 id, const struct mlx5_devcom_match_attr *attr,
 
        comp = kzalloc(sizeof(*comp), GFP_KERNEL);
        if (!comp)
-               return ERR_PTR(-ENOMEM);
+               return NULL;
 
        comp->id = id;
        comp->key.key = attr->key;
@@ -160,7 +160,7 @@ devcom_alloc_comp_dev(struct mlx5_devcom_dev *devc,
 
        devcom = kzalloc(sizeof(*devcom), GFP_KERNEL);
        if (!devcom)
-               return ERR_PTR(-ENOMEM);
+               return NULL;
 
        kref_get(&devc->ref);
        devcom->devc = devc;
@@ -240,31 +240,28 @@ mlx5_devcom_register_component(struct mlx5_devcom_dev *devc,
                               mlx5_devcom_event_handler_t handler,
                               void *data)
 {
-       struct mlx5_devcom_comp_dev *devcom;
+       struct mlx5_devcom_comp_dev *devcom = NULL;
        struct mlx5_devcom_comp *comp;
 
-       if (IS_ERR_OR_NULL(devc))
-               return ERR_PTR(-EINVAL);
+       if (!devc)
+               return NULL;
 
        mutex_lock(&comp_list_lock);
        comp = devcom_component_get(devc, id, attr, handler);
-       if (IS_ERR(comp)) {
-               devcom = ERR_PTR(-EINVAL);
+       if (IS_ERR(comp))
                goto out_unlock;
-       }
 
        if (!comp) {
                comp = mlx5_devcom_comp_alloc(id, attr, handler);
-               if (IS_ERR(comp)) {
-                       devcom = ERR_CAST(comp);
+               if (!comp)
                        goto out_unlock;
-               }
+
                list_add_tail(&comp->comp_list, &devcom_comp_list);
        }
        mutex_unlock(&comp_list_lock);
 
        devcom = devcom_alloc_comp_dev(devc, comp, data);
-       if (IS_ERR(devcom))
+       if (!devcom)
                kref_put(&comp->ref, mlx5_devcom_comp_release);
 
        return devcom;
@@ -276,8 +273,10 @@ out_unlock:
 
 void mlx5_devcom_unregister_component(struct mlx5_devcom_comp_dev *devcom)
 {
-       if (!IS_ERR_OR_NULL(devcom))
-               devcom_free_comp_dev(devcom);
+       if (!devcom)
+               return;
+
+       devcom_free_comp_dev(devcom);
 }
 
 int mlx5_devcom_comp_get_size(struct mlx5_devcom_comp_dev *devcom)
@@ -296,7 +295,7 @@ int mlx5_devcom_send_event(struct mlx5_devcom_comp_dev *devcom,
        int err = 0;
        void *data;
 
-       if (IS_ERR_OR_NULL(devcom))
+       if (!devcom)
                return -ENODEV;
 
        comp = devcom->comp;
@@ -338,7 +337,7 @@ void mlx5_devcom_comp_set_ready(struct mlx5_devcom_comp_dev *devcom, bool ready)
 
 bool mlx5_devcom_comp_is_ready(struct mlx5_devcom_comp_dev *devcom)
 {
-       if (IS_ERR_OR_NULL(devcom))
+       if (!devcom)
                return false;
 
        return READ_ONCE(devcom->comp->ready);
@@ -348,7 +347,7 @@ bool mlx5_devcom_for_each_peer_begin(struct mlx5_devcom_comp_dev *devcom)
 {
        struct mlx5_devcom_comp *comp;
 
-       if (IS_ERR_OR_NULL(devcom))
+       if (!devcom)
                return false;
 
        comp = devcom->comp;
@@ -421,21 +420,21 @@ void *mlx5_devcom_get_next_peer_data_rcu(struct mlx5_devcom_comp_dev *devcom,
 
 void mlx5_devcom_comp_lock(struct mlx5_devcom_comp_dev *devcom)
 {
-       if (IS_ERR_OR_NULL(devcom))
+       if (!devcom)
                return;
        down_write(&devcom->comp->sem);
 }
 
 void mlx5_devcom_comp_unlock(struct mlx5_devcom_comp_dev *devcom)
 {
-       if (IS_ERR_OR_NULL(devcom))
+       if (!devcom)
                return;
        up_write(&devcom->comp->sem);
 }
 
 int mlx5_devcom_comp_trylock(struct mlx5_devcom_comp_dev *devcom)
 {
-       if (IS_ERR_OR_NULL(devcom))
+       if (!devcom)
                return 0;
        return down_write_trylock(&devcom->comp->sem);
 }
index f5c2701f6e8797b9547d948703c70b88a7ec6b42..8e17daae48afb5e48df266b504bea0c09914e797 100644 (file)
@@ -221,8 +221,8 @@ static int sd_register(struct mlx5_core_dev *dev)
        attr.net = mlx5_core_net(dev);
        devcom = mlx5_devcom_register_component(dev->priv.devc, MLX5_DEVCOM_SD_GROUP,
                                                &attr, NULL, dev);
-       if (IS_ERR(devcom))
-               return PTR_ERR(devcom);
+       if (!devcom)
+               return -EINVAL;
 
        sd->devcom = devcom;
 
index df93625c9dfa3a11b769acdcab1320a6a4aeb4b0..70c156591b0ba9c61dd99818043003e50e177590 100644 (file)
@@ -978,9 +978,8 @@ static int mlx5_init_once(struct mlx5_core_dev *dev)
        int err;
 
        dev->priv.devc = mlx5_devcom_register_device(dev);
-       if (IS_ERR(dev->priv.devc))
-               mlx5_core_warn(dev, "failed to register devcom device %pe\n",
-                              dev->priv.devc);
+       if (!dev->priv.devc)
+               mlx5_core_warn(dev, "failed to register devcom device\n");
 
        err = mlx5_query_board_id(dev);
        if (err) {