Commit 7681750b authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

zram: convert to blk_alloc_disk/blk_cleanup_disk

Convert the zram driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Link: https://lore.kernel.org/r/20210521055116.1053587-11-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 0be7966e
...@@ -1890,7 +1890,6 @@ static const struct attribute_group *zram_disk_attr_groups[] = { ...@@ -1890,7 +1890,6 @@ static const struct attribute_group *zram_disk_attr_groups[] = {
static int zram_add(void) static int zram_add(void)
{ {
struct zram *zram; struct zram *zram;
struct request_queue *queue;
int ret, device_id; int ret, device_id;
zram = kzalloc(sizeof(struct zram), GFP_KERNEL); zram = kzalloc(sizeof(struct zram), GFP_KERNEL);
...@@ -1906,27 +1905,20 @@ static int zram_add(void) ...@@ -1906,27 +1905,20 @@ static int zram_add(void)
#ifdef CONFIG_ZRAM_WRITEBACK #ifdef CONFIG_ZRAM_WRITEBACK
spin_lock_init(&zram->wb_limit_lock); spin_lock_init(&zram->wb_limit_lock);
#endif #endif
queue = blk_alloc_queue(NUMA_NO_NODE);
if (!queue) {
pr_err("Error allocating disk queue for device %d\n",
device_id);
ret = -ENOMEM;
goto out_free_idr;
}
/* gendisk structure */ /* gendisk structure */
zram->disk = alloc_disk(1); zram->disk = blk_alloc_disk(NUMA_NO_NODE);
if (!zram->disk) { if (!zram->disk) {
pr_err("Error allocating disk structure for device %d\n", pr_err("Error allocating disk structure for device %d\n",
device_id); device_id);
ret = -ENOMEM; ret = -ENOMEM;
goto out_free_queue; goto out_free_idr;
} }
zram->disk->major = zram_major; zram->disk->major = zram_major;
zram->disk->first_minor = device_id; zram->disk->first_minor = device_id;
zram->disk->minors = 1;
zram->disk->fops = &zram_devops; zram->disk->fops = &zram_devops;
zram->disk->queue = queue;
zram->disk->private_data = zram; zram->disk->private_data = zram;
snprintf(zram->disk->disk_name, 16, "zram%d", device_id); snprintf(zram->disk->disk_name, 16, "zram%d", device_id);
...@@ -1969,8 +1961,6 @@ static int zram_add(void) ...@@ -1969,8 +1961,6 @@ static int zram_add(void)
pr_info("Added device: %s\n", zram->disk->disk_name); pr_info("Added device: %s\n", zram->disk->disk_name);
return device_id; return device_id;
out_free_queue:
blk_cleanup_queue(queue);
out_free_idr: out_free_idr:
idr_remove(&zram_index_idr, device_id); idr_remove(&zram_index_idr, device_id);
out_free_dev: out_free_dev:
...@@ -2000,8 +1990,7 @@ static int zram_remove(struct zram *zram) ...@@ -2000,8 +1990,7 @@ static int zram_remove(struct zram *zram)
pr_info("Removed device: %s\n", zram->disk->disk_name); pr_info("Removed device: %s\n", zram->disk->disk_name);
del_gendisk(zram->disk); del_gendisk(zram->disk);
blk_cleanup_queue(zram->disk->queue); blk_cleanup_disk(zram->disk);
put_disk(zram->disk);
kfree(zram); kfree(zram);
return 0; return 0;
} }
......
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