Skip to content

Commit 24afc15

Browse files
tititiou36axboe
authored andcommitted
block/rnbd: Remove a useless mutex
According to lib/idr.c, The IDA handles its own locking. It is safe to call any of the IDA functions without synchronisation in your code. so the 'ida_lock' mutex can just be removed. It is here only to protect some ida_simple_get()/ida_simple_remove() calls. While at it, switch to ida_alloc_XXX()/ida_free() instead to ida_simple_get()/ida_simple_remove(). The latter is deprecated and more verbose. Signed-off-by: Christophe JAILLET <[email protected]> Acked-by: Jack Wang <[email protected]> Link: https://lore.kernel.org/r/7f9eccd8b1fce1bac45ac9b01a78cf72f54c0a61.1644266862.git.christophe.jaillet@wanadoo.fr Signed-off-by: Jens Axboe <[email protected]>
1 parent 030ce8b commit 24afc15

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

drivers/block/rnbd/rnbd-clt.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ MODULE_LICENSE("GPL");
2323

2424
static int rnbd_client_major;
2525
static DEFINE_IDA(index_ida);
26-
static DEFINE_MUTEX(ida_lock);
2726
static DEFINE_MUTEX(sess_lock);
2827
static LIST_HEAD(sess_list);
2928

@@ -55,9 +54,7 @@ static void rnbd_clt_put_dev(struct rnbd_clt_dev *dev)
5554
if (!refcount_dec_and_test(&dev->refcount))
5655
return;
5756

58-
mutex_lock(&ida_lock);
59-
ida_simple_remove(&index_ida, dev->clt_device_id);
60-
mutex_unlock(&ida_lock);
57+
ida_free(&index_ida, dev->clt_device_id);
6158
kfree(dev->hw_queues);
6259
kfree(dev->pathname);
6360
rnbd_clt_put_sess(dev->sess);
@@ -1460,10 +1457,8 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
14601457
goto out_alloc;
14611458
}
14621459

1463-
mutex_lock(&ida_lock);
1464-
ret = ida_simple_get(&index_ida, 0, 1 << (MINORBITS - RNBD_PART_BITS),
1465-
GFP_KERNEL);
1466-
mutex_unlock(&ida_lock);
1460+
ret = ida_alloc_max(&index_ida, 1 << (MINORBITS - RNBD_PART_BITS),
1461+
GFP_KERNEL);
14671462
if (ret < 0) {
14681463
pr_err("Failed to initialize device '%s' from session %s, allocating idr failed, err: %d\n",
14691464
pathname, sess->sessname, ret);

0 commit comments

Comments
 (0)