Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Leon Romanovsky and committed by
Jason Gunthorpe
bdb0e4e3 e677b72a

+16 -47
+16 -46
drivers/infiniband/core/iwpm_util.c
··· 48 48 static struct hlist_head *iwpm_reminfo_bucket; 49 49 static DEFINE_SPINLOCK(iwpm_reminfo_lock); 50 50 51 - static DEFINE_MUTEX(iwpm_admin_lock); 52 51 static struct iwpm_admin_data iwpm_admin; 53 52 54 53 /** ··· 58 59 */ 59 60 int iwpm_init(u8 nl_client) 60 61 { 61 - int ret = 0; 62 - mutex_lock(&iwpm_admin_lock); 63 - if (!refcount_read(&iwpm_admin.refcount)) { 64 - iwpm_hash_bucket = kcalloc(IWPM_MAPINFO_HASH_SIZE, 65 - sizeof(struct hlist_head), 66 - GFP_KERNEL); 67 - if (!iwpm_hash_bucket) { 68 - ret = -ENOMEM; 69 - goto init_exit; 70 - } 71 - iwpm_reminfo_bucket = kcalloc(IWPM_REMINFO_HASH_SIZE, 72 - sizeof(struct hlist_head), 73 - GFP_KERNEL); 74 - if (!iwpm_reminfo_bucket) { 75 - kfree(iwpm_hash_bucket); 76 - ret = -ENOMEM; 77 - goto init_exit; 78 - } 62 + iwpm_hash_bucket = kcalloc(IWPM_MAPINFO_HASH_SIZE, 63 + sizeof(struct hlist_head), GFP_KERNEL); 64 + if (!iwpm_hash_bucket) 65 + return -ENOMEM; 79 66 80 - refcount_set(&iwpm_admin.refcount, 1); 81 - } else { 82 - refcount_inc(&iwpm_admin.refcount); 67 + iwpm_reminfo_bucket = kcalloc(IWPM_REMINFO_HASH_SIZE, 68 + sizeof(struct hlist_head), GFP_KERNEL); 69 + if (!iwpm_reminfo_bucket) { 70 + kfree(iwpm_hash_bucket); 71 + return -ENOMEM; 83 72 } 84 73 85 - init_exit: 86 - mutex_unlock(&iwpm_admin_lock); 87 - if (!ret) { 88 - iwpm_set_valid(nl_client, 1); 89 - iwpm_set_registration(nl_client, IWPM_REG_UNDEF); 90 - pr_debug("%s: Mapinfo and reminfo tables are created\n", 91 - __func__); 92 - } 93 - return ret; 74 + iwpm_set_valid(nl_client, 1); 75 + iwpm_set_registration(nl_client, IWPM_REG_UNDEF); 76 + pr_debug("%s: Mapinfo and reminfo tables are created\n", __func__); 77 + return 0; 94 78 } 95 79 96 80 static void free_hash_bucket(void); ··· 87 105 */ 88 106 int iwpm_exit(u8 nl_client) 89 107 { 90 - 91 - if (!iwpm_valid_client(nl_client)) 92 - return -EINVAL; 93 - mutex_lock(&iwpm_admin_lock); 94 - if (!refcount_read(&iwpm_admin.refcount)) { 95 - mutex_unlock(&iwpm_admin_lock); 96 - pr_err("%s Incorrect usage - negative refcount\n", __func__); 97 - return -EINVAL; 98 - } 99 - if (refcount_dec_and_test(&iwpm_admin.refcount)) { 100 - free_hash_bucket(); 101 - free_reminfo_bucket(); 102 - pr_debug("%s: Resources are destroyed\n", __func__); 103 - } 104 - mutex_unlock(&iwpm_admin_lock); 108 + free_hash_bucket(); 109 + free_reminfo_bucket(); 110 + pr_debug("%s: Resources are destroyed\n", __func__); 105 111 iwpm_set_valid(nl_client, 0); 106 112 iwpm_set_registration(nl_client, IWPM_REG_UNDEF); 107 113 return 0;
-1
drivers/infiniband/core/iwpm_util.h
··· 90 90 }; 91 91 92 92 struct iwpm_admin_data { 93 - refcount_t refcount; 94 93 atomic_t nlmsg_seq; 95 94 int client_list[RDMA_NL_NUM_CLIENTS]; 96 95 u32 reg_list[RDMA_NL_NUM_CLIENTS];