mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 04:18:39 +08:00
blk-mq: Free tags in blk_mq_init_tags() upon error
Since the tags are allocated in blk_mq_init_tags(), it's better practice to free in that same function upon error, rather than a callee which is to init the bitmap tags (blk_mq_init_tags()). [jpg: Split from an earlier patch with a new commit message] Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: John Garry <john.garry@huawei.com> Tested-by: Douglas Gilbert <dgilbert@interlog.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
655ac30094
commit
4d063237b9
@ -429,24 +429,22 @@ static int bt_alloc(struct sbitmap_queue *bt, unsigned int depth,
|
|||||||
node);
|
node);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct blk_mq_tags *blk_mq_init_bitmap_tags(struct blk_mq_tags *tags,
|
static int blk_mq_init_bitmap_tags(struct blk_mq_tags *tags,
|
||||||
int node, int alloc_policy)
|
int node, int alloc_policy)
|
||||||
{
|
{
|
||||||
unsigned int depth = tags->nr_tags - tags->nr_reserved_tags;
|
unsigned int depth = tags->nr_tags - tags->nr_reserved_tags;
|
||||||
bool round_robin = alloc_policy == BLK_TAG_ALLOC_RR;
|
bool round_robin = alloc_policy == BLK_TAG_ALLOC_RR;
|
||||||
|
|
||||||
if (bt_alloc(&tags->bitmap_tags, depth, round_robin, node))
|
if (bt_alloc(&tags->bitmap_tags, depth, round_robin, node))
|
||||||
goto free_tags;
|
return -ENOMEM;
|
||||||
if (bt_alloc(&tags->breserved_tags, tags->nr_reserved_tags, round_robin,
|
if (bt_alloc(&tags->breserved_tags, tags->nr_reserved_tags, round_robin,
|
||||||
node))
|
node))
|
||||||
goto free_bitmap_tags;
|
goto free_bitmap_tags;
|
||||||
|
|
||||||
return tags;
|
return 0;
|
||||||
free_bitmap_tags:
|
free_bitmap_tags:
|
||||||
sbitmap_queue_free(&tags->bitmap_tags);
|
sbitmap_queue_free(&tags->bitmap_tags);
|
||||||
free_tags:
|
return -ENOMEM;
|
||||||
kfree(tags);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
|
struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
|
||||||
@ -467,7 +465,11 @@ struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
|
|||||||
tags->nr_tags = total_tags;
|
tags->nr_tags = total_tags;
|
||||||
tags->nr_reserved_tags = reserved_tags;
|
tags->nr_reserved_tags = reserved_tags;
|
||||||
|
|
||||||
return blk_mq_init_bitmap_tags(tags, node, alloc_policy);
|
if (blk_mq_init_bitmap_tags(tags, node, alloc_policy) < 0) {
|
||||||
|
kfree(tags);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void blk_mq_free_tags(struct blk_mq_tags *tags)
|
void blk_mq_free_tags(struct blk_mq_tags *tags)
|
||||||
|
Loading…
Reference in New Issue
Block a user