Skip to content

Commit

Permalink
RDMA/core: Annotate destroy of mutex to ensure that it is released as…
Browse files Browse the repository at this point in the history
… unlocked

While compiled with CONFIG_DEBUG_MUTEXES, the kernel ensures that mutex is
not held during destroy. Hence add mutex_destroy() for mutexes used in
RDMA modules.

Link: https://lore.kernel.org/r/20190723065733.4899-2-leon@kernel.org
Signed-off-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Reviewed-by: Jason Gunthorpe <jgg@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
  • Loading branch information
Parav Pandit authored and Jason Gunthorpe committed Jul 25, 2019
1 parent a511f82 commit 56594ae
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions drivers/infiniband/core/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ static void release_gid_table(struct ib_device *device,
if (leak)
return;

mutex_destroy(&table->lock);
kfree(table->data_vec);
kfree(table);
}
Expand Down
8 changes: 7 additions & 1 deletion drivers/infiniband/core/cma_configfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,18 @@ static struct configfs_subsystem cma_subsys = {

int __init cma_configfs_init(void)
{
int ret;

config_group_init(&cma_subsys.su_group);
mutex_init(&cma_subsys.su_mutex);
return configfs_register_subsystem(&cma_subsys);
ret = configfs_register_subsystem(&cma_subsys);
if (ret)
mutex_destroy(&cma_subsys.su_mutex);
return ret;
}

void __exit cma_configfs_exit(void)
{
configfs_unregister_subsystem(&cma_subsys);
mutex_destroy(&cma_subsys.su_mutex);
}
8 changes: 4 additions & 4 deletions drivers/infiniband/core/counters.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ int rdma_counter_get_mode(struct ib_device *dev, u8 port,
void rdma_counter_init(struct ib_device *dev)
{
struct rdma_port_counter *port_counter;
u32 port;
u32 port, i;

if (!dev->ops.alloc_hw_stats || !dev->port_data)
return;
Expand All @@ -610,13 +610,12 @@ void rdma_counter_init(struct ib_device *dev)
return;

fail:
rdma_for_each_port(dev, port) {
for (i = port; i >= rdma_start_port(dev); i--) {
port_counter = &dev->port_data[port].port_counter;
kfree(port_counter->hstats);
port_counter->hstats = NULL;
mutex_destroy(&port_counter->lock);
}

return;
}

void rdma_counter_release(struct ib_device *dev)
Expand All @@ -630,5 +629,6 @@ void rdma_counter_release(struct ib_device *dev)
rdma_for_each_port(dev, port) {
port_counter = &dev->port_data[port].port_counter;
kfree(port_counter->hstats);
mutex_destroy(&port_counter->lock);
}
}
3 changes: 3 additions & 0 deletions drivers/infiniband/core/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,9 @@ static void ib_device_release(struct device *device)
rcu_head);
}

mutex_destroy(&dev->unregistration_lock);
mutex_destroy(&dev->compat_devs_mutex);

xa_destroy(&dev->compat_devs);
xa_destroy(&dev->client_data);
kfree_rcu(dev, rcu_head);
Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/core/user_mad.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ static int ib_umad_close(struct inode *inode, struct file *filp)
ib_unregister_mad_agent(file->agent[i]);

mutex_unlock(&file->port->file_mutex);

mutex_destroy(&file->mutex);
kfree(file);
return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions drivers/infiniband/core/uverbs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ static void ib_uverbs_release_dev(struct device *device)

uverbs_destroy_api(dev->uapi);
cleanup_srcu_struct(&dev->disassociate_srcu);
mutex_destroy(&dev->lists_mutex);
mutex_destroy(&dev->xrcd_tree_mutex);
kfree(dev);
}

Expand Down Expand Up @@ -212,6 +214,8 @@ void ib_uverbs_release_file(struct kref *ref)

if (file->disassociate_page)
__free_pages(file->disassociate_page, 0);
mutex_destroy(&file->umap_lock);
mutex_destroy(&file->ucontext_lock);
kfree(file);
}

Expand Down
1 change: 1 addition & 0 deletions drivers/infiniband/core/verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2259,6 +2259,7 @@ int ib_dealloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata)
if (ret)
return ret;
}
mutex_destroy(&xrcd->tgt_qp_mutex);

return xrcd->device->ops.dealloc_xrcd(xrcd, udata);
}
Expand Down

0 comments on commit 56594ae

Please sign in to comment.