[v3,1/2] blk-mq: improve error handling in blk_mq_alloc_rq_map()

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

Commit Message

Jinlong Chen Nov. 2, 2022, 3:06 a.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 | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
  

Comments

Chaitanya Kulkarni Nov. 2, 2022, 5:45 a.m. UTC | #1
On 11/1/22 20:06, Jinlong Chen wrote:
> Use goto-style error handling like we do elsewhere in the kernel.
> 
> Signed-off-by: Jinlong Chen <nickyc975@zju.edu.cn>
> ---

since all to blk_mq_free_tags is duplicated in the code this seems
to be the right thing to do.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck
  
Christoph Hellwig Nov. 2, 2022, 6:59 a.m. UTC | #2
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
  

Patch

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 623e8a506539..453ad445a6bd 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -3274,21 +3274,22 @@  static struct blk_mq_tags *blk_mq_alloc_rq_map(struct blk_mq_tag_set *set,
 	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);
+	return NULL;
 }
 
 static int blk_mq_init_request(struct blk_mq_tag_set *set, struct request *rq,