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

block: cleanup __alloc_disk_node

Use early returns and goto-based unwinding to simplify the flow a bit.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent e5c7fb40
...@@ -1729,19 +1729,20 @@ struct gendisk *__alloc_disk_node(int minors, int node_id) ...@@ -1729,19 +1729,20 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)
} }
disk = kzalloc_node(sizeof(struct gendisk), GFP_KERNEL, node_id); disk = kzalloc_node(sizeof(struct gendisk), GFP_KERNEL, node_id);
if (disk) { if (!disk)
disk->part0.dkstats = alloc_percpu(struct disk_stats);
if (!disk->part0.dkstats) {
kfree(disk);
return NULL; return NULL;
}
disk->part0.dkstats = alloc_percpu(struct disk_stats);
if (!disk->part0.dkstats)
goto out_free_disk;
init_rwsem(&disk->lookup_sem); init_rwsem(&disk->lookup_sem);
disk->node_id = node_id; disk->node_id = node_id;
if (disk_expand_part_tbl(disk, 0)) { if (disk_expand_part_tbl(disk, 0)) {
free_percpu(disk->part0.dkstats); free_percpu(disk->part0.dkstats);
kfree(disk); goto out_free_disk;
return NULL;
} }
ptbl = rcu_dereference_protected(disk->part_tbl, 1); ptbl = rcu_dereference_protected(disk->part_tbl, 1);
rcu_assign_pointer(ptbl->part[0], &disk->part0); rcu_assign_pointer(ptbl->part[0], &disk->part0);
...@@ -1755,19 +1756,21 @@ struct gendisk *__alloc_disk_node(int minors, int node_id) ...@@ -1755,19 +1756,21 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)
* converted to make use of bd_mutex and sequence counters. * converted to make use of bd_mutex and sequence counters.
*/ */
hd_sects_seq_init(&disk->part0); hd_sects_seq_init(&disk->part0);
if (hd_ref_init(&disk->part0)) { if (hd_ref_init(&disk->part0))
hd_free_part(&disk->part0); goto out_free_part0;
kfree(disk);
return NULL;
}
disk->minors = minors; disk->minors = minors;
rand_initialize_disk(disk); rand_initialize_disk(disk);
disk_to_dev(disk)->class = &block_class; disk_to_dev(disk)->class = &block_class;
disk_to_dev(disk)->type = &disk_type; disk_to_dev(disk)->type = &disk_type;
device_initialize(disk_to_dev(disk)); device_initialize(disk_to_dev(disk));
}
return disk; return disk;
out_free_part0:
hd_free_part(&disk->part0);
out_free_disk:
kfree(disk);
return NULL;
} }
EXPORT_SYMBOL(__alloc_disk_node); EXPORT_SYMBOL(__alloc_disk_node);
......
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