Commit ef358854 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

xpram: convert to blk_alloc_disk/blk_cleanup_disk

Convert the xpram 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 avatarHannes Reinecke <hare@suse.de>
Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Link: https://lore.kernel.org/r/20210521055116.1053587-25-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 0692ef28
...@@ -56,7 +56,6 @@ typedef struct { ...@@ -56,7 +56,6 @@ typedef struct {
static xpram_device_t xpram_devices[XPRAM_MAX_DEVS]; static xpram_device_t xpram_devices[XPRAM_MAX_DEVS];
static unsigned int xpram_sizes[XPRAM_MAX_DEVS]; static unsigned int xpram_sizes[XPRAM_MAX_DEVS];
static struct gendisk *xpram_disks[XPRAM_MAX_DEVS]; static struct gendisk *xpram_disks[XPRAM_MAX_DEVS];
static struct request_queue *xpram_queues[XPRAM_MAX_DEVS];
static unsigned int xpram_pages; static unsigned int xpram_pages;
static int xpram_devs; static int xpram_devs;
...@@ -341,17 +340,13 @@ static int __init xpram_setup_blkdev(void) ...@@ -341,17 +340,13 @@ static int __init xpram_setup_blkdev(void)
int i, rc = -ENOMEM; int i, rc = -ENOMEM;
for (i = 0; i < xpram_devs; i++) { for (i = 0; i < xpram_devs; i++) {
xpram_disks[i] = alloc_disk(1); xpram_disks[i] = blk_alloc_disk(NUMA_NO_NODE);
if (!xpram_disks[i]) if (!xpram_disks[i])
goto out; goto out;
xpram_queues[i] = blk_alloc_queue(NUMA_NO_NODE); blk_queue_flag_set(QUEUE_FLAG_NONROT, xpram_disks[i]->queue);
if (!xpram_queues[i]) { blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM,
put_disk(xpram_disks[i]); xpram_disks[i]->queue);
goto out; blk_queue_logical_block_size(xpram_disks[i]->queue, 4096);
}
blk_queue_flag_set(QUEUE_FLAG_NONROT, xpram_queues[i]);
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, xpram_queues[i]);
blk_queue_logical_block_size(xpram_queues[i], 4096);
} }
/* /*
...@@ -373,9 +368,9 @@ static int __init xpram_setup_blkdev(void) ...@@ -373,9 +368,9 @@ static int __init xpram_setup_blkdev(void)
offset += xpram_devices[i].size; offset += xpram_devices[i].size;
disk->major = XPRAM_MAJOR; disk->major = XPRAM_MAJOR;
disk->first_minor = i; disk->first_minor = i;
disk->minors = 1;
disk->fops = &xpram_devops; disk->fops = &xpram_devops;
disk->private_data = &xpram_devices[i]; disk->private_data = &xpram_devices[i];
disk->queue = xpram_queues[i];
sprintf(disk->disk_name, "slram%d", i); sprintf(disk->disk_name, "slram%d", i);
set_capacity(disk, xpram_sizes[i] << 1); set_capacity(disk, xpram_sizes[i] << 1);
add_disk(disk); add_disk(disk);
...@@ -383,10 +378,8 @@ static int __init xpram_setup_blkdev(void) ...@@ -383,10 +378,8 @@ static int __init xpram_setup_blkdev(void)
return 0; return 0;
out: out:
while (i--) { while (i--)
blk_cleanup_queue(xpram_queues[i]); blk_cleanup_disk(xpram_disks[i]);
put_disk(xpram_disks[i]);
}
return rc; return rc;
} }
...@@ -434,8 +427,7 @@ static void __exit xpram_exit(void) ...@@ -434,8 +427,7 @@ static void __exit xpram_exit(void)
int i; int i;
for (i = 0; i < xpram_devs; i++) { for (i = 0; i < xpram_devs; i++) {
del_gendisk(xpram_disks[i]); del_gendisk(xpram_disks[i]);
blk_cleanup_queue(xpram_queues[i]); blk_cleanup_disk(xpram_disks[i]);
put_disk(xpram_disks[i]);
} }
unregister_blkdev(XPRAM_MAJOR, XPRAM_NAME); unregister_blkdev(XPRAM_MAJOR, XPRAM_NAME);
platform_device_unregister(xpram_pdev); platform_device_unregister(xpram_pdev);
......
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