[PATCH 2/4] blk-mq: improve error handling in blk_mq_alloc_rq_map()

Jinlong Chen posted 4 patches 3 years, 5 months ago
There is a newer version of this series
[PATCH 2/4] blk-mq: improve error handling in blk_mq_alloc_rq_map()
Posted by Jinlong Chen 3 years, 5 months ago
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(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 7ceceea91b3b..408a929be90e 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -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,
-- 
2.31.1
Re: [PATCH 2/4] blk-mq: improve error handling in blk_mq_alloc_rq_map()
Posted by Christoph Hellwig 3 years, 5 months ago
>  	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.
Re: [PATCH 2/4] blk-mq: improve error handling in blk_mq_alloc_rq_map()
Posted by Jens Axboe 3 years, 5 months ago
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.

-- 
Jens Axboe