]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
mlx5: Use refcount_t for refcount
authorChuhong Yuan <hslester96@gmail.com>
Tue, 6 Aug 2019 01:59:50 +0000 (09:59 +0800)
committerSaeed Mahameed <saeedm@mellanox.com>
Wed, 7 Aug 2019 18:01:48 +0000 (11:01 -0700)
Reference counters are preferred to use refcount_t instead of
atomic_t.
This is because the implementation of refcount_t can prevent
overflows and detect possible use-after-free.
So convert atomic_t ref counters to refcount_t.

Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
Acked-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/infiniband/hw/mlx5/srq_cmd.c
drivers/net/ethernet/mellanox/mlx5/core/qp.c
include/linux/mlx5/driver.h

index b0d0687c7a686571a0cd8aa043282f80dadc76c5..8fc3630a9d4c3742995f31b2d06584b8024a29cf 100644 (file)
@@ -86,7 +86,7 @@ struct mlx5_core_srq *mlx5_cmd_get_srq(struct mlx5_ib_dev *dev, u32 srqn)
        xa_lock(&table->array);
        srq = xa_load(&table->array, srqn);
        if (srq)
-               atomic_inc(&srq->common.refcount);
+               refcount_inc(&srq->common.refcount);
        xa_unlock(&table->array);
 
        return srq;
@@ -592,7 +592,7 @@ int mlx5_cmd_create_srq(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
        if (err)
                return err;
 
-       atomic_set(&srq->common.refcount, 1);
+       refcount_set(&srq->common.refcount, 1);
        init_completion(&srq->common.free);
 
        err = xa_err(xa_store_irq(&table->array, srq->srqn, srq, GFP_KERNEL));
@@ -675,7 +675,7 @@ static int srq_event_notifier(struct notifier_block *nb,
        xa_lock(&table->array);
        srq = xa_load(&table->array, srqn);
        if (srq)
-               atomic_inc(&srq->common.refcount);
+               refcount_inc(&srq->common.refcount);
        xa_unlock(&table->array);
 
        if (!srq)
index b8ba74de95558f84c29b26c80fb1ccb30889b83f..7b44d1e4960436fe676b3885ae357e58566a4b2a 100644 (file)
@@ -53,7 +53,7 @@ mlx5_get_rsc(struct mlx5_qp_table *table, u32 rsn)
 
        common = radix_tree_lookup(&table->tree, rsn);
        if (common)
-               atomic_inc(&common->refcount);
+               refcount_inc(&common->refcount);
 
        spin_unlock_irqrestore(&table->lock, flags);
 
@@ -62,7 +62,7 @@ mlx5_get_rsc(struct mlx5_qp_table *table, u32 rsn)
 
 void mlx5_core_put_rsc(struct mlx5_core_rsc_common *common)
 {
-       if (atomic_dec_and_test(&common->refcount))
+       if (refcount_dec_and_test(&common->refcount))
                complete(&common->free);
 }
 
@@ -209,7 +209,7 @@ static int create_resource_common(struct mlx5_core_dev *dev,
        if (err)
                return err;
 
-       atomic_set(&qp->common.refcount, 1);
+       refcount_set(&qp->common.refcount, 1);
        init_completion(&qp->common.free);
        qp->pid = current->pid;
 
index 267b2bc0ca4a65cfa19a1d2ed2293fcc24d4124f..0acd28f2e62c3d20540d798ef276ef021c2022de 100644 (file)
@@ -47,6 +47,7 @@
 #include <linux/interrupt.h>
 #include <linux/idr.h>
 #include <linux/notifier.h>
+#include <linux/refcount.h>
 
 #include <linux/mlx5/device.h>
 #include <linux/mlx5/doorbell.h>
@@ -398,7 +399,7 @@ enum mlx5_res_type {
 
 struct mlx5_core_rsc_common {
        enum mlx5_res_type      res;
-       atomic_t                refcount;
+       refcount_t              refcount;
        struct completion       free;
 };