Commit 6966bb92 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

mtd_blkdevs: use blk_mq_alloc_disk

Use the blk_mq_alloc_disk API to simplify the gendisk and request_queue
allocation.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Link: https://lore.kernel.org/r/20210602065345.355274-10-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 51ed5bd5
...@@ -30,11 +30,9 @@ static void blktrans_dev_release(struct kref *kref) ...@@ -30,11 +30,9 @@ static void blktrans_dev_release(struct kref *kref)
struct mtd_blktrans_dev *dev = struct mtd_blktrans_dev *dev =
container_of(kref, struct mtd_blktrans_dev, ref); container_of(kref, struct mtd_blktrans_dev, ref);
dev->disk->private_data = NULL; blk_cleanup_disk(dev->disk);
blk_cleanup_queue(dev->rq);
blk_mq_free_tag_set(dev->tag_set); blk_mq_free_tag_set(dev->tag_set);
kfree(dev->tag_set); kfree(dev->tag_set);
put_disk(dev->disk);
list_del(&dev->list); list_del(&dev->list);
kfree(dev); kfree(dev);
} }
...@@ -354,7 +352,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) ...@@ -354,7 +352,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
if (new->devnum > (MINORMASK >> tr->part_bits) || if (new->devnum > (MINORMASK >> tr->part_bits) ||
(tr->part_bits && new->devnum >= 27 * 26)) { (tr->part_bits && new->devnum >= 27 * 26)) {
mutex_unlock(&blktrans_ref_mutex); mutex_unlock(&blktrans_ref_mutex);
goto error1; return ret;
} }
list_add_tail(&new->list, &tr->devs); list_add_tail(&new->list, &tr->devs);
...@@ -366,17 +364,28 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) ...@@ -366,17 +364,28 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
if (!tr->writesect) if (!tr->writesect)
new->readonly = 1; new->readonly = 1;
/* Create gendisk */
ret = -ENOMEM; ret = -ENOMEM;
gd = alloc_disk(1 << tr->part_bits); new->tag_set = kzalloc(sizeof(*new->tag_set), GFP_KERNEL);
if (!new->tag_set)
goto out_list_del;
if (!gd) ret = blk_mq_alloc_sq_tag_set(new->tag_set, &mtd_mq_ops, 2,
goto error2; BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING);
if (ret)
goto out_kfree_tag_set;
/* Create gendisk */
gd = blk_mq_alloc_disk(new->tag_set, new);
if (IS_ERR(gd)) {
ret = PTR_ERR(gd);
goto out_free_tag_set;
}
new->disk = gd; new->disk = gd;
gd->private_data = new; gd->private_data = new;
gd->major = tr->major; gd->major = tr->major;
gd->first_minor = (new->devnum) << tr->part_bits; gd->first_minor = (new->devnum) << tr->part_bits;
gd->minors = 1 << tr->part_bits;
gd->fops = &mtd_block_ops; gd->fops = &mtd_block_ops;
if (tr->part_bits) if (tr->part_bits)
...@@ -398,22 +407,9 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) ...@@ -398,22 +407,9 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
spin_lock_init(&new->queue_lock); spin_lock_init(&new->queue_lock);
INIT_LIST_HEAD(&new->rq_list); INIT_LIST_HEAD(&new->rq_list);
new->tag_set = kzalloc(sizeof(*new->tag_set), GFP_KERNEL);
if (!new->tag_set)
goto error3;
new->rq = blk_mq_init_sq_queue(new->tag_set, &mtd_mq_ops, 2,
BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING);
if (IS_ERR(new->rq)) {
ret = PTR_ERR(new->rq);
new->rq = NULL;
goto error4;
}
if (tr->flush) if (tr->flush)
blk_queue_write_cache(new->rq, true, false); blk_queue_write_cache(new->rq, true, false);
new->rq->queuedata = new;
blk_queue_logical_block_size(new->rq, tr->blksize); blk_queue_logical_block_size(new->rq, tr->blksize);
blk_queue_flag_set(QUEUE_FLAG_NONROT, new->rq); blk_queue_flag_set(QUEUE_FLAG_NONROT, new->rq);
...@@ -437,13 +433,13 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) ...@@ -437,13 +433,13 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
WARN_ON(ret); WARN_ON(ret);
} }
return 0; return 0;
error4:
out_free_tag_set:
blk_mq_free_tag_set(new->tag_set);
out_kfree_tag_set:
kfree(new->tag_set); kfree(new->tag_set);
error3: out_list_del:
put_disk(new->disk);
error2:
list_del(&new->list); list_del(&new->list);
error1:
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment