mirror of https://gitee.com/openkylin/linux.git
n64: cleanup n64cart_probe()
The goto label fail_queue is needed to cleanup the queue allocation when devm_platform_ioremap_resource() or alloc_disk() fails, either of these two functions are not dependent on the queue variable which is allocated prior to these calls. Allocate the queue variable after successful alloc_disk(). Return error directly when devm_platform_ioremap_resource() or alloc_disk() fail. Remove fail_queue label and a call to the blk_cleanup_queue(). Direct return from these two functions allows us to remove the local variable err and allocating queue after alloc_disk() allows us to remove the local variable queue so we use disk->queue directly. Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> Reviewed-by: Lauri Kasanen <cand@gmx.com> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
This commit is contained in:
parent
37772f9136
commit
0d42478085
|
@ -116,9 +116,7 @@ static const struct block_device_operations n64cart_fops = {
|
||||||
*/
|
*/
|
||||||
static int __init n64cart_probe(struct platform_device *pdev)
|
static int __init n64cart_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
int err;
|
|
||||||
struct gendisk *disk;
|
struct gendisk *disk;
|
||||||
struct request_queue *queue;
|
|
||||||
|
|
||||||
if (!start || !size) {
|
if (!start || !size) {
|
||||||
pr_err("start or size not specified\n");
|
pr_err("start or size not specified\n");
|
||||||
|
@ -130,26 +128,21 @@ static int __init n64cart_probe(struct platform_device *pdev)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
queue = blk_alloc_queue(NUMA_NO_NODE);
|
|
||||||
if (!queue)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
reg_base = devm_platform_ioremap_resource(pdev, 0);
|
reg_base = devm_platform_ioremap_resource(pdev, 0);
|
||||||
if (!reg_base) {
|
if (!reg_base)
|
||||||
err = -EINVAL;
|
return -EINVAL;
|
||||||
goto fail_queue;
|
|
||||||
}
|
|
||||||
|
|
||||||
disk = alloc_disk(0);
|
disk = alloc_disk(0);
|
||||||
if (!disk) {
|
if (!disk)
|
||||||
err = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto fail_queue;
|
|
||||||
}
|
disk->queue = blk_alloc_queue(NUMA_NO_NODE);
|
||||||
|
if (!disk->queue)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
dev = &pdev->dev;
|
dev = &pdev->dev;
|
||||||
|
|
||||||
disk->first_minor = 0;
|
disk->first_minor = 0;
|
||||||
disk->queue = queue;
|
|
||||||
disk->flags = GENHD_FL_NO_PART_SCAN | GENHD_FL_EXT_DEVT;
|
disk->flags = GENHD_FL_NO_PART_SCAN | GENHD_FL_EXT_DEVT;
|
||||||
disk->fops = &n64cart_fops;
|
disk->fops = &n64cart_fops;
|
||||||
strcpy(disk->disk_name, "n64cart");
|
strcpy(disk->disk_name, "n64cart");
|
||||||
|
@ -157,19 +150,15 @@ static int __init n64cart_probe(struct platform_device *pdev)
|
||||||
set_capacity(disk, size >> SECTOR_SHIFT);
|
set_capacity(disk, size >> SECTOR_SHIFT);
|
||||||
set_disk_ro(disk, 1);
|
set_disk_ro(disk, 1);
|
||||||
|
|
||||||
blk_queue_flag_set(QUEUE_FLAG_NONROT, queue);
|
blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
|
||||||
blk_queue_physical_block_size(queue, 4096);
|
blk_queue_physical_block_size(disk->queue, 4096);
|
||||||
blk_queue_logical_block_size(queue, 4096);
|
blk_queue_logical_block_size(disk->queue, 4096);
|
||||||
|
|
||||||
add_disk(disk);
|
add_disk(disk);
|
||||||
|
|
||||||
pr_info("n64cart: %u kb disk\n", size / 1024);
|
pr_info("n64cart: %u kb disk\n", size / 1024);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
fail_queue:
|
|
||||||
blk_cleanup_queue(queue);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct platform_driver n64cart_driver = {
|
static struct platform_driver n64cart_driver = {
|
||||||
|
|
Loading…
Reference in New Issue