aboutsummaryrefslogtreecommitdiff
path: root/drivers/block
diff options
context:
space:
mode:
authorChristoph Hellwig2021-08-11 14:44:26 +0200
committerJens Axboe2021-08-13 14:17:37 -0600
commit7bdc00cf7e369b3be17f26e5643da28de98d9d6d (patch)
treeb6aa51a0dd72533cf0311de9c224c9db2813d1ae /drivers/block
parent327b501b1d94342fe17a1b6b1a40746e57ddd472 (diff)
nbd: return the allocated nbd_device from nbd_dev_add
Return the device we just allocated instead of doing an extra search for it in the caller. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20210811124428.2368491-5-hch@lst.de Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/nbd.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 48530fe01c0f..a81b95c66dbf 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1683,7 +1683,7 @@ static const struct blk_mq_ops nbd_mq_ops = {
.timeout = nbd_xmit_timeout,
};
-static int nbd_dev_add(int index)
+static struct nbd_device *nbd_dev_add(int index)
{
struct nbd_device *nbd;
struct gendisk *disk;
@@ -1755,7 +1755,7 @@ static int nbd_dev_add(int index)
sprintf(disk->disk_name, "nbd%d", index);
add_disk(disk);
nbd_total_devices++;
- return index;
+ return nbd;
out_free_idr:
idr_remove(&nbd_index_idr, index);
@@ -1764,7 +1764,7 @@ out_free_tags:
out_free_nbd:
kfree(nbd);
out:
- return err;
+ return ERR_PTR(err);
}
static int find_free_cb(int id, void *ptr, void *data)
@@ -1850,25 +1850,22 @@ again:
if (index == -1) {
ret = idr_for_each(&nbd_index_idr, &find_free_cb, &nbd);
if (ret == 0) {
- int new_index;
- new_index = nbd_dev_add(-1);
- if (new_index < 0) {
+ nbd = nbd_dev_add(-1);
+ if (IS_ERR(nbd)) {
mutex_unlock(&nbd_index_mutex);
printk(KERN_ERR "nbd: failed to add new device\n");
- return new_index;
+ return PTR_ERR(nbd);
}
- nbd = idr_find(&nbd_index_idr, new_index);
}
} else {
nbd = idr_find(&nbd_index_idr, index);
if (!nbd) {
- ret = nbd_dev_add(index);
- if (ret < 0) {
+ nbd = nbd_dev_add(index);
+ if (IS_ERR(nbd)) {
mutex_unlock(&nbd_index_mutex);
printk(KERN_ERR "nbd: failed to add new device\n");
- return ret;
+ return PTR_ERR(nbd);
}
- nbd = idr_find(&nbd_index_idr, index);
}
}
if (!nbd) {