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

Message ID 992db53bdeaba35d37de3784fe6f80879c9bbb35.1667314759.git.nickyc975@zju.edu.cn
State New
Headers
Series some random cleanups for blk-mq.c |

Commit Message

Jinlong Chen Nov. 1, 2022, 3:11 p.m. UTC
  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

Christoph Hellwig Nov. 1, 2022, 5:34 p.m. UTC | #1
>  	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.
  
Jens Axboe Nov. 1, 2022, 6:18 p.m. UTC | #2
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.
  

Patch

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,