[2/4] blk-mq: improve error handling in blk_mq_alloc_rq_map()
Commit Message
Use goto-style error handling like we do elsewhere in the kernel.
Signed-off-by: Jinlong Chen <nickyc975@zju.edu.cn>
---
block/blk-mq.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
Comments
> if (!tags)
> - return NULL;
> + goto err_out;
Using a label just for the direct error return here is a bit silly.
The rest looks fine.
On 11/1/22 11:34 AM, Christoph Hellwig wrote:
>> if (!tags)
>> - return NULL;
>> + goto err_out;
>
> Using a label just for the direct error return here is a bit silly.
Plus that's not idiomatic code for cleanup, just keep the NULL
return if there's no cleanup to be done.
@@ -3272,26 +3272,28 @@ static struct blk_mq_tags *blk_mq_alloc_rq_map(struct blk_mq_tag_set *set,
tags = blk_mq_init_tags(nr_tags, reserved_tags, node,
BLK_MQ_FLAG_TO_ALLOC_POLICY(set->flags));
if (!tags)
- return NULL;
+ goto err_out;
tags->rqs = kcalloc_node(nr_tags, sizeof(struct request *),
GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY,
node);
- if (!tags->rqs) {
- blk_mq_free_tags(tags);
- return NULL;
- }
+ if (!tags->rqs)
+ goto err_free_tags;
tags->static_rqs = kcalloc_node(nr_tags, sizeof(struct request *),
GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY,
node);
- if (!tags->static_rqs) {
- kfree(tags->rqs);
- blk_mq_free_tags(tags);
- return NULL;
- }
+ if (!tags->static_rqs)
+ goto err_free_rqs;
return tags;
+
+err_free_rqs:
+ kfree(tags->rqs);
+err_free_tags:
+ blk_mq_free_tags(tags);
+err_out:
+ return NULL;
}
static int blk_mq_init_request(struct blk_mq_tag_set *set, struct request *rq,