On Mon, Apr 29, 2019 at 11:34:42AM +0300, Leon Romanovsky wrote:
> +/**
> + * rdma_counter_unbind_qp - Unbind a qp from a counter
> + * @force:
> + * true - Decrease the counter ref-count anyway (e.g., qp destroy)
> + */
> +int rdma_counter_unbind_qp(struct ib_qp *qp, bool force)
> +{
> + struct rdma_counter *counter = qp->counter;
> + int ret;
> +
> + if (!counter)
> + return -EINVAL;
> +
> + ret = __rdma_counter_unbind_qp(qp, force);
> + if (ret && !force)
> + return ret;
> +
> + rdma_restrack_put(&counter->res);
> + if (atomic_dec_and_test(&counter->usecnt))
> + rdma_counter_dealloc(counter);
An atomic that does kfree when it reaches zero should be implemented
with a kref.
Jason