mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
RDMA/iwpm: Remove not-needed reference counting
iwpm_init() and iwpm_exit() are called only once during iw_cm module load. This makes whole reference count implementation not needed at all. Link: https://lore.kernel.org/r/1778ded873ba58c9fadc5bb25038de1cec843bec.1627048781.git.leonro@nvidia.com Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
This commit is contained in:
parent
e677b72a06
commit
bdb0e4e3ff
2 changed files with 16 additions and 47 deletions
|
@ -48,7 +48,6 @@ static DEFINE_SPINLOCK(iwpm_mapinfo_lock);
|
||||||
static struct hlist_head *iwpm_reminfo_bucket;
|
static struct hlist_head *iwpm_reminfo_bucket;
|
||||||
static DEFINE_SPINLOCK(iwpm_reminfo_lock);
|
static DEFINE_SPINLOCK(iwpm_reminfo_lock);
|
||||||
|
|
||||||
static DEFINE_MUTEX(iwpm_admin_lock);
|
|
||||||
static struct iwpm_admin_data iwpm_admin;
|
static struct iwpm_admin_data iwpm_admin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,39 +58,22 @@ static struct iwpm_admin_data iwpm_admin;
|
||||||
*/
|
*/
|
||||||
int iwpm_init(u8 nl_client)
|
int iwpm_init(u8 nl_client)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
iwpm_hash_bucket = kcalloc(IWPM_MAPINFO_HASH_SIZE,
|
||||||
mutex_lock(&iwpm_admin_lock);
|
sizeof(struct hlist_head), GFP_KERNEL);
|
||||||
if (!refcount_read(&iwpm_admin.refcount)) {
|
if (!iwpm_hash_bucket)
|
||||||
iwpm_hash_bucket = kcalloc(IWPM_MAPINFO_HASH_SIZE,
|
return -ENOMEM;
|
||||||
sizeof(struct hlist_head),
|
|
||||||
GFP_KERNEL);
|
|
||||||
if (!iwpm_hash_bucket) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto init_exit;
|
|
||||||
}
|
|
||||||
iwpm_reminfo_bucket = kcalloc(IWPM_REMINFO_HASH_SIZE,
|
|
||||||
sizeof(struct hlist_head),
|
|
||||||
GFP_KERNEL);
|
|
||||||
if (!iwpm_reminfo_bucket) {
|
|
||||||
kfree(iwpm_hash_bucket);
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto init_exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
refcount_set(&iwpm_admin.refcount, 1);
|
iwpm_reminfo_bucket = kcalloc(IWPM_REMINFO_HASH_SIZE,
|
||||||
} else {
|
sizeof(struct hlist_head), GFP_KERNEL);
|
||||||
refcount_inc(&iwpm_admin.refcount);
|
if (!iwpm_reminfo_bucket) {
|
||||||
|
kfree(iwpm_hash_bucket);
|
||||||
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
init_exit:
|
iwpm_set_valid(nl_client, 1);
|
||||||
mutex_unlock(&iwpm_admin_lock);
|
iwpm_set_registration(nl_client, IWPM_REG_UNDEF);
|
||||||
if (!ret) {
|
pr_debug("%s: Mapinfo and reminfo tables are created\n", __func__);
|
||||||
iwpm_set_valid(nl_client, 1);
|
return 0;
|
||||||
iwpm_set_registration(nl_client, IWPM_REG_UNDEF);
|
|
||||||
pr_debug("%s: Mapinfo and reminfo tables are created\n",
|
|
||||||
__func__);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_hash_bucket(void);
|
static void free_hash_bucket(void);
|
||||||
|
@ -105,21 +87,9 @@ static void free_reminfo_bucket(void);
|
||||||
*/
|
*/
|
||||||
int iwpm_exit(u8 nl_client)
|
int iwpm_exit(u8 nl_client)
|
||||||
{
|
{
|
||||||
|
free_hash_bucket();
|
||||||
if (!iwpm_valid_client(nl_client))
|
free_reminfo_bucket();
|
||||||
return -EINVAL;
|
pr_debug("%s: Resources are destroyed\n", __func__);
|
||||||
mutex_lock(&iwpm_admin_lock);
|
|
||||||
if (!refcount_read(&iwpm_admin.refcount)) {
|
|
||||||
mutex_unlock(&iwpm_admin_lock);
|
|
||||||
pr_err("%s Incorrect usage - negative refcount\n", __func__);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
if (refcount_dec_and_test(&iwpm_admin.refcount)) {
|
|
||||||
free_hash_bucket();
|
|
||||||
free_reminfo_bucket();
|
|
||||||
pr_debug("%s: Resources are destroyed\n", __func__);
|
|
||||||
}
|
|
||||||
mutex_unlock(&iwpm_admin_lock);
|
|
||||||
iwpm_set_valid(nl_client, 0);
|
iwpm_set_valid(nl_client, 0);
|
||||||
iwpm_set_registration(nl_client, IWPM_REG_UNDEF);
|
iwpm_set_registration(nl_client, IWPM_REG_UNDEF);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -90,7 +90,6 @@ struct iwpm_remote_info {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct iwpm_admin_data {
|
struct iwpm_admin_data {
|
||||||
refcount_t refcount;
|
|
||||||
atomic_t nlmsg_seq;
|
atomic_t nlmsg_seq;
|
||||||
int client_list[RDMA_NL_NUM_CLIENTS];
|
int client_list[RDMA_NL_NUM_CLIENTS];
|
||||||
u32 reg_list[RDMA_NL_NUM_CLIENTS];
|
u32 reg_list[RDMA_NL_NUM_CLIENTS];
|
||||||
|
|
Loading…
Add table
Reference in a new issue